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
This commit is contained in:
shreyas-goenka 2022-09-19 16:47:55 +02:00 committed by GitHub
parent 7cad8bda81
commit 731679cb4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 11 deletions

View File

@ -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")
}

View File

@ -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
}
}
}
}