devcam: warn when outdated

http://camlistore.org/issue/482

Change-Id: Ifafec9c9ff337aefa98e630242cb28f19495d4b5
This commit is contained in:
mpl 2014-08-19 17:45:49 +02:00
parent 6f05133c88
commit ae097a3960
1 changed files with 45 additions and 0 deletions

View File

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