This commit is contained in:
Shreyas Goenka 2023-06-02 00:05:17 +02:00
parent 0382c749c5
commit 289dd0db32
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 16 additions and 9 deletions

View File

@ -25,9 +25,11 @@ type SyncOptions struct {
Host string Host string
// If set, sync will not be able to overwrite any existing paths on the // Allow sync to overwrite existing files in the workspace
// workspace file system. AllowOverwrites bool
DisallowOverwrites bool
// Persist the snapshot on the local file systems for future sync runs
PersistSnapshot bool
} }
type Sync struct { type Sync struct {
@ -80,9 +82,12 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) {
return nil, fmt.Errorf("unable to load sync snapshot: %w", err) return nil, fmt.Errorf("unable to load sync snapshot: %w", err)
} }
} }
repoFiles := repofiles.Create(opts.RemotePath, opts.LocalPath, opts.WorkspaceClient, &repofiles.RepoFileOptions{ repoFiles, err := repofiles.Create(opts.RemotePath, opts.LocalPath, opts.WorkspaceClient, &repofiles.RepoFileOptions{
OverwriteIfExists: !opts.DisallowOverwrites, OverwriteIfExists: opts.AllowOverwrites,
}) })
if err != nil {
return nil, err
}
return &Sync{ return &Sync{
SyncOptions: &opts, SyncOptions: &opts,
@ -163,10 +168,12 @@ func (s *Sync) RunOnce(ctx context.Context) error {
return err return err
} }
err = s.snapshot.Save(ctx) if s.PersistSnapshot {
if err != nil { err = s.snapshot.Save(ctx)
log.Errorf(ctx, "cannot store snapshot: %s", err) if err != nil {
return err log.Errorf(ctx, "cannot store snapshot: %s", err)
return err
}
} }
s.notifyComplete(ctx, change) s.notifyComplete(ctx, change)