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
// If set, sync will not be able to overwrite any existing paths on the
// workspace file system.
DisallowOverwrites bool
// Allow sync to overwrite existing files in the workspace
AllowOverwrites bool
// Persist the snapshot on the local file systems for future sync runs
PersistSnapshot bool
}
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)
}
}
repoFiles := repofiles.Create(opts.RemotePath, opts.LocalPath, opts.WorkspaceClient, &repofiles.RepoFileOptions{
OverwriteIfExists: !opts.DisallowOverwrites,
repoFiles, err := repofiles.Create(opts.RemotePath, opts.LocalPath, opts.WorkspaceClient, &repofiles.RepoFileOptions{
OverwriteIfExists: opts.AllowOverwrites,
})
if err != nil {
return nil, err
}
return &Sync{
SyncOptions: &opts,
@ -163,10 +168,12 @@ func (s *Sync) RunOnce(ctx context.Context) error {
return err
}
err = s.snapshot.Save(ctx)
if err != nil {
log.Errorf(ctx, "cannot store snapshot: %s", err)
return err
if s.PersistSnapshot {
err = s.snapshot.Save(ctx)
if err != nil {
log.Errorf(ctx, "cannot store snapshot: %s", err)
return err
}
}
s.notifyComplete(ctx, change)