diff --git a/cmd/sync/sync.go b/cmd/sync/sync.go index 1b2f7fff..d5d76b26 100644 --- a/cmd/sync/sync.go +++ b/cmd/sync/sync.go @@ -59,8 +59,11 @@ var interval *time.Duration var remotePath *string +var persistSnapshot *bool + func init() { root.RootCmd.AddCommand(syncCmd) interval = syncCmd.Flags().Duration("interval", 1*time.Second, "project files polling interval") remotePath = syncCmd.Flags().String("remote-path", "", "remote path to store repo in. eg: /Repos/me@example.com/test-repo") + persistSnapshot = syncCmd.Flags().Bool("persist-snapshot", true, "whether to store local snapshots of sync state") } diff --git a/cmd/sync/watchdog.go b/cmd/sync/watchdog.go index a4cd9361..defe5c2c 100644 --- a/cmd/sync/watchdog.go +++ b/cmd/sync/watchdog.go @@ -94,13 +94,14 @@ func (w *watchdog) main(ctx context.Context, applyDiff func(diff) error) { // load from json or sync it every time there's an action state := snapshot{} root := w.files.Root() - err := state.loadSnapshot(root) - if err != nil { - log.Printf("[ERROR] cannot load snapshot: %s", err) - w.failure = err - return + if *persistSnapshot { + err := state.loadSnapshot(root) + if err != nil { + log.Printf("[ERROR] cannot load snapshot: %s", err) + w.failure = err + return + } } - for { select { case <-ctx.Done(): @@ -122,11 +123,13 @@ func (w *watchdog) main(ctx context.Context, applyDiff func(diff) error) { w.failure = err return } - err = state.storeSnapshot(root) - if err != nil { - log.Printf("[ERROR] cannot store snapshot: %s", err) - w.failure = err - return + if *persistSnapshot { + err = state.storeSnapshot(root) + if err != nil { + log.Printf("[ERROR] cannot store snapshot: %s", err) + w.failure = err + return + } } } }