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
This commit is contained in:
mpl 2015-05-07 16:34:17 +02:00
parent 1a483159c3
commit 3db00e5e98
2 changed files with 15 additions and 5 deletions

View File

@ -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()

View File

@ -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 {