From 6b7d73d7570c136c74c628b95b0db7a48de6aae5 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 1 Jan 2013 21:05:02 -0800 Subject: [PATCH] camput: ignore atimes Change-Id: Ia55d6fef6a8e3aa95b6265c958853da7b170e3c4 --- cmd/camput/flatcache.go | 8 ++++++++ cmd/camput/stat_darwin.go | 18 ++++++++++++++++++ cmd/camput/stat_linux.go | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 cmd/camput/stat_darwin.go create mode 100644 cmd/camput/stat_linux.go diff --git a/cmd/camput/flatcache.go b/cmd/camput/flatcache.go index aab9211d2..ee9eaa4d5 100644 --- a/cmd/camput/flatcache.go +++ b/cmd/camput/flatcache.go @@ -38,12 +38,20 @@ import ( type statFingerprint string +var cleanSysStat func(v interface{}) interface{} + func fileInfoToFingerprint(fi os.FileInfo) statFingerprint { // We calculate the CRC32 of the underlying system stat structure to get // ctime, owner, group, etc. This is overkill (e.g. we don't care about // the inode or device number probably), but works. sysHash := uint32(0) if sys := fi.Sys(); sys != nil { + if clean := cleanSysStat; clean != nil { + // TODO: don't clean bad fields, but provide a + // portable way to extract all good fields. + // This is a Linux+Mac-specific hack for now. + sys = clean(sys) + } var buf bytes.Buffer fmt.Fprintf(&buf, "%#v", sys) sysHash = crc32.ChecksumIEEE(buf.Bytes()) diff --git a/cmd/camput/stat_darwin.go b/cmd/camput/stat_darwin.go new file mode 100644 index 000000000..688b8f64b --- /dev/null +++ b/cmd/camput/stat_darwin.go @@ -0,0 +1,18 @@ +//+build darwin + +package main + +import ( + "syscall" +) + +func init() { + cleanSysStat = func(si interface{}) interface{} { + st, ok := si.(*syscall.Stat_t) + if !ok { + return si + } + st.Atimespec = syscall.Timespec{} + return st + } +} diff --git a/cmd/camput/stat_linux.go b/cmd/camput/stat_linux.go new file mode 100644 index 000000000..318a1eba3 --- /dev/null +++ b/cmd/camput/stat_linux.go @@ -0,0 +1,22 @@ +//+build linux + +// TODO: move this to somewhere generic in osutil; use it for all +// posix-y operation systems? Or rather, don't clean bad fields, but +// provide a portable way to extract all good fields. + +package main + +import ( + "syscall" +) + +func init() { + cleanSysStat = func(si interface{}) interface{} { + st, ok := si.(*syscall.Stat_t) + if !ok { + return si + } + st.Atim = syscall.Timespec{} + return st + } +}