gorun fails to compile (Mac OS X)

Bug #1176275 reported by mcandre
40
This bug affects 8 people
Affects Status Importance Assigned to Milestone
gorun
Confirmed
Undecided
Unassigned

Bug Description

Trace:

$ go get launchpad.net/gorun
# launchpad.net/gorun
/usr/local/Cellar/go/1.0.3/src/pkg/launchpad.net/gorun/gorun.go:265: sysStat(info).Atim undefined (type *syscall.Stat_t has no field or method Atim)

System:

$ specs go os
Specs:

specs 0.4
https://github.com/mcandre/specs#readme

go version
go version go1.0.3

system_profiler SPSoftwareDataType | grep 'System Version'
      System Version: OS X 10.8.3 (12D78)

Revision history for this message
Paul Jardetzky (pjardetzky) wrote :

To compile on OS X 10.6.8, this change was required

265c265
< atim := sysStat(info).Atimespec
---
> atim := sysStat(info).Atim

Revision history for this message
Paul Jardetzky (pjardetzky) wrote :
Changed in gorun:
status: New → Confirmed
Revision history for this message
Aaron (atron) wrote :

This is still an issue installing via go get. The patch works still.

Revision history for this message
Brian Reiter (breiter) wrote :

The patch works because the system call in Darwin is the Stat_t structure is not the same on all OSes.

https://golang.org/src/syscall/ztypes_darwin_amd64.go?h=Stat_t

    63 type Stat_t struct {
    64 Dev int32
    65 Mode uint16
    66 Nlink uint16
    67 Ino uint64
    68 Uid uint32
    69 Gid uint32
    70 Rdev int32
    71 Pad_cgo_0 [4]byte
    72 Atimespec Timespec
    73 Mtimespec Timespec
    74 Ctimespec Timespec
    75 Birthtimespec Timespec
    76 Size int64
    77 Blocks int64
    78 Blksize int32
    79 Flags uint32
    80 Gen uint32
    81 Lspare int32
    82 Qspare [2]int64
    83 }

https://golang.org/src/syscall/ztypes_linux_amd64.go?h=Stat_t

  99 type Stat_t struct {
   100 Dev uint64
   101 Ino uint64
   102 Nlink uint64
   103 Mode uint32
   104 Uid uint32
   105 Gid uint32
   106 X__pad0 int32
   107 Rdev uint64
   108 Size int64
   109 Blksize int64
   110 Blocks int64
   111 Atim Timespec
   112 Mtim Timespec
   113 Ctim Timespec
   114 X__unused [3]int64
   115 }

http://golang.org/pkg/syscall/
"Package syscall contains an interface to the low-level operating system primitives. The details vary depending on the underlying system, and by default, godoc will display the syscall documentation for the current system. "

I think the correct solution is to remove the dependency on the syscall pacakge. Go provides the os package to abstract the os details and provide platform-independent interface. Using the os.Stat(name string) function which returns a StatInfo structure that is OS independent would solve the problem.

http://golang.org/pkg/os/#FileInfo

Revision history for this message
Brian Reiter (breiter) wrote :

This patch should allow it to work on both Linux and Darwin/OS X:

265,266c265
< atim := sysStat(info).Atim
< access := time.Unix(int64(atim.Sec), int64(atim.Nsec))
---
> access := info.ModTime()

Revision history for this message
Brian Reiter (breiter) wrote :

Platform independent diff.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.