summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reloadMtime.go94
1 files changed, 94 insertions, 0 deletions
diff --git a/reloadMtime.go b/reloadMtime.go
index d5425a1..fa4708f 100644
--- a/reloadMtime.go
+++ b/reloadMtime.go
@@ -3,6 +3,7 @@ package gitpb
// An app to submit patches for the 30 GO GUI repos
import (
+ "errors"
"fmt"
"os"
"path/filepath"
@@ -264,3 +265,96 @@ func (repo *Repo) DidRepoChange() error {
// log.Info("DidRepoChange() is false", repo.FullPath)
return nil
}
+
+func (all *Repos) ScanAllMtimesVerbose() (string, error) {
+ var count int
+ var anyerr error
+ for r := range all.IterAll() {
+ var err error
+ var ok bool
+ if count < 10 {
+ // only show output for the first 10 repos
+ ok, err = r.didRepoChangeVerbose()
+ } else {
+ err = r.DidRepoChange()
+ }
+ if err != nil {
+ log.Info(r.Namespace, err)
+ }
+ if (err != nil) || ok {
+ // means there was output
+ anyerr = err
+ count += 1
+ }
+ }
+ if anyerr != nil {
+ all.Save()
+ }
+ return "looked into mtime changes", anyerr
+}
+
+func (r *Repo) didRepoChangeVerbose() (bool, error) {
+ var output bool
+ if r.Times == nil {
+ r.Times = new(GitTimes)
+ log.Info("repo.Reload() was never run")
+ output = true
+ // means this is going to populate the mtimes for the first time
+ // todo: make sure the whole thing gets saved
+ } else {
+ if r.Times.LastUpdate != nil {
+ lastupdate := r.Times.LastUpdate.AsTime()
+ dur := time.Since(lastupdate)
+ if dur < 5*time.Minute {
+ log.Info("repo.ReloadMtime() was was last run", config.FormatDuration(dur), r.Namespace)
+ output = true
+ }
+ } else {
+ log.Info("repo.ReloadMtime() LastUpdate == nil", r.Namespace)
+ output = true
+ }
+ }
+ if r.didFileChange(".git/HEAD", r.Times.MtimeHead) {
+ r.RunVerbose([]string{"ls", "-l", ".git/HEAD"})
+ output = true
+ return output, errors.New(".git/HEAD changed")
+ }
+ if r.didFileChange(".git/index", r.Times.MtimeIndex) {
+ r.StateChange += "jwc2"
+ r.RunVerbose([]string{"ls", "-l", ".git/index"})
+ output = true
+ return output, errors.New(".git/index changed")
+ }
+ if r.didFileChange(".git/config", r.Times.MtimeConfig) {
+ r.RunVerbose([]string{"ls", "-l", ".git/config"})
+ output = true
+ return output, errors.New(".git/config changed")
+ }
+ if r.didFileChange(".git", r.Times.MtimeDir) {
+ if r.Times.MtimeDir != nil {
+ lastupdate := r.Times.LastUpdate.AsTime()
+ dur := time.Since(lastupdate)
+ if dur < 5*time.Minute {
+ log.Info("repo.ReloadMtime() MtimeDir last run", config.FormatDuration(dur), r.Namespace)
+ r.RunVerbose([]string{"ls", "-l", ".git", "-d"})
+ output = true
+ }
+ } else {
+ }
+ // todo: do something with CheckDirty()
+ // return true
+ }
+ if r.Times.LastUpdate == nil {
+ log.Info("r.Reload() was never run")
+ output = true
+ return output, errors.New("Reload() ran for the first time")
+ } else {
+ if r.Times.LastUpdate.Seconds < r.Times.MtimeHead.Seconds {
+ log.Info("SHOULD RUN Reload() here", r.Times.MtimeHead.Seconds-r.Times.LastUpdate.Seconds, "secs diff")
+ output = true
+ return output, errors.New("Reload() time skew on .git/HEAD")
+ }
+ }
+ // nothing changed. All mtimes being monitored are old
+ return output, nil
+}