diff --git a/dev/devcam/devcam.go b/dev/devcam/devcam.go index 737c0b35b..87beef215 100644 --- a/dev/devcam/devcam.go +++ b/dev/devcam/devcam.go @@ -29,8 +29,10 @@ import ( "strconv" "strings" "syscall" + "time" "camlistore.org/pkg/cmdmain" + "camlistore.org/pkg/osutil" ) var ( @@ -166,6 +168,46 @@ func checkCamliSrcRoot() { camliSrcRoot = cwd } +func selfModTime() (time.Time, error) { + var modTime time.Time + devcamBin, err := osutil.SelfPath() + if err != nil { + return modTime, err + } + fi, err := os.Stat(devcamBin) + if err != nil { + return modTime, err + } + return fi.ModTime(), nil +} + +func checkModtime() error { + binModtime, err := selfModTime() + if err != nil { + return fmt.Errorf("could not get ModTime of current devcam executable: %v", err) + } + + devcamDir := filepath.Join(camliSrcRoot, "dev", "devcam") + d, err := os.Open(devcamDir) + if err != nil { + log.Fatal(err) + } + defer d.Close() + fis, err := d.Readdir(-1) + if err != nil { + log.Fatal(err) + } + for _, fi := range fis { + if fi.ModTime().After(binModtime) { + log.Printf("**************************************************************") + log.Printf("WARNING: your devcam binary is outdated, you should rebuild it") + log.Printf("**************************************************************") + return nil + } + } + return nil +} + // Build builds the camlistore command at the given path from the source tree root. func build(path string) error { if v, _ := strconv.ParseBool(os.Getenv("CAMLI_FAST_DEV")); v { @@ -204,6 +246,9 @@ func build(path string) error { func main() { cmdmain.CheckCwd = checkCamliSrcRoot + if err := checkModtime(); err != nil { + log.Printf("Skipping freshness check: %v", err) + } // TODO(mpl): usage error is not really correct for devcam. // See if I can reimplement it while still using cmdmain.Main(). cmdmain.Main()