diff options
Diffstat (limited to 'reload.go')
| -rw-r--r-- | reload.go | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -4,17 +4,33 @@ import ( "strings" "time" + "go.wit.com/lib/config" "go.wit.com/log" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) +// sets a flag that the repos have changed +// used later by applications on exit to test if +// the protobuf needs to be written to disk +func reposChanged(b bool) { + config.SetChanged("repos", true) +} + +// returns true based on os.Stat() only checks +// seems to kinda work ok. goal is to avoid os.Exec() here for speed +// this might be the 1 place where libgit2 would be a good idea +func (repo *Repo) HasChanged() bool { + return repo.DidRepoChange() +} + // does a fast check with os.Stat() -// if the mtimes changed, does a full repo.Reload() +// if the mtimes changed, does a full repo.ReloadForce() func (repo *Repo) ReloadCheck() error { if !repo.DidRepoChange() { return nil } - err := repo.Reload() + reposChanged(true) + err := repo.ReloadForce() if err != nil { return err } @@ -22,7 +38,8 @@ func (repo *Repo) ReloadCheck() error { } // TODO: clean this up more, but it is working now more or less -func (repo *Repo) Reload() error { +func (repo *Repo) ReloadForce() error { + reposChanged(true) // sometimes, on new repos, if .git/HEAD does not exist // defective git daemons or badly configured repos, 'git clone' can fail // if so, 'git fetch origin' can repair the state |
