Skip to content

Commit

Permalink
Conditionally build fileInfo type based on target OS
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseyhightower committed Oct 10, 2013
1 parent 25fb504 commit 9f64b02
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
9 changes: 9 additions & 0 deletions fileinfo_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

// A fileInfo describes a configuration file and is returned by fileStat.
type fileInfo struct {
Uid uint32
Gid uint32
Mode uint16
Md5 string
}
9 changes: 9 additions & 0 deletions fileinfo_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

// A fileInfo describes a configuration file and is returned by fileStat.
type fileInfo struct {
Uid uint32
Gid uint32
Mode uint32
Md5 string
}
12 changes: 0 additions & 12 deletions template_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ type TemplateResourceConfig struct {
TemplateResource TemplateResource `toml:"template"`
}

// A fileInfo describes a configuration file and is returned by fileStat.
type fileInfo struct {
Uid uint32
Gid uint32
Mode uint32
Md5 string
}

// TemplateResource is the representation of a parsed template resource.
type TemplateResource struct {
Dest string
Expand Down Expand Up @@ -199,10 +191,6 @@ func fileStat(name string) (fi fileInfo, err error) {
return fi, err
}
stats, _ := f.Stat()
// Gathering the uid, gid, and mode this way is not portable.
// This will build on Linux but not OS X. The Mode on OS X returns a
// uint16 but uint32 on Linux. We could change our FileInfo Mode field
// type to os.FileMode and cast Mode here.
fi.Uid = stats.Sys().(*syscall.Stat_t).Uid
fi.Gid = stats.Sys().(*syscall.Stat_t).Gid
fi.Mode = stats.Sys().(*syscall.Stat_t).Mode
Expand Down

0 comments on commit 9f64b02

Please sign in to comment.