diff --git a/dev/devcam/devcam.go b/dev/devcam/devcam.go index 894344ba9..ad4c993a7 100644 --- a/dev/devcam/devcam.go +++ b/dev/devcam/devcam.go @@ -191,12 +191,12 @@ func checkModtime() error { devcamDir := filepath.Join(camliSrcRoot, "dev", "devcam") d, err := os.Open(devcamDir) if err != nil { - log.Fatal(err) + return fmt.Errorf("could not read devcam source dir %v: %v", devcamDir, err) } defer d.Close() fis, err := d.Readdir(-1) if err != nil { - log.Fatal(err) + return fmt.Errorf("could not read devcam source dir %v: %v", devcamDir, err) } for _, fi := range fis { if fi.ModTime().After(binModtime) { @@ -247,10 +247,13 @@ func build(path string) error { func main() { cmdmain.CheckCwd = checkCamliSrcRoot - - if err := checkModtime(); err != nil { - log.Printf("Skipping freshness check: %v", err) + cmdmain.CheckModtime = func() error { + if err := checkModtime(); err != nil { + log.Printf("Skipping freshness check: %v", err) + } + return nil } + // TODO(mpl): usage error is not really correct for devcam. // See if I can reimplement it while still using cmdmain.Main(). cmdmain.Main() diff --git a/pkg/cmdmain/cmdmain.go b/pkg/cmdmain/cmdmain.go index bc1eff592..776022672 100644 --- a/pkg/cmdmain/cmdmain.go +++ b/pkg/cmdmain/cmdmain.go @@ -51,6 +51,9 @@ var ( // CheckCwd checks the current working directory, and possibly // changes it, or aborts the run if needed. CheckCwd = func() {} + // CheckModtime provides a way to check if the currently running binary + // is out of date. If it returns an error, the run is aborted. + CheckModtime = func() error { return nil } ) var ErrUsage = UsageError("invalid command") @@ -238,6 +241,10 @@ func Main() { } flag.Parse() CheckCwd() + if err := CheckModtime(); err != nil { + log.Print(err) + Exit(1) + } args := flag.Args() if *FlagVersion {