From 731679cb4bb857518b60ce3e8d8e929cf0cde68b Mon Sep 17 00:00:00 2001 From: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com> Date: Mon, 19 Sep 2022 16:47:55 +0200 Subject: [PATCH] Add `persist-snapshot` to bricks sync (#66) Tested manually We are adding this flag because the default bricks sync is not robust against changing the profile and other project config changes. This will be used in the initial version of the vscode extention --- cmd/sync/sync.go | 3 +++ cmd/sync/watchdog.go | 25 ++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) 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 + } } } }