From 3db00e5e988eb6fb2f748b6afdf7eddb61f70b77 Mon Sep 17 00:00:00 2001 From: mpl Date: Thu, 7 May 2015 16:34:17 +0200 Subject: [PATCH] devcam: move modtime check after cwd check checkCamliSrcRoot was meant to give a nice error msg if devcam is invoked from outside the Camlistore source tree. However, it was never called because the modtime check (checkModtime), which itself needs to be run from that same location, was called first. So we were always getting the terse "open dev/devcam: no such file or directory" error message instead. Fixes #589 Change-Id: I13a1bb3819217ffbaf727fa6154f077dd8babd49 --- dev/devcam/devcam.go | 13 ++++++++----- pkg/cmdmain/cmdmain.go | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) 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 {