upgrade_repo_v2: Use atomic replace for supported backends
This commit is contained in:
parent
7559d2f105
commit
e36a40db10
13 changed files with 82 additions and 17 deletions
|
@ -53,17 +53,19 @@ func (*UpgradeRepoV2) Check(ctx context.Context, repo restic.Repository) (bool,
|
|||
func (*UpgradeRepoV2) upgrade(ctx context.Context, repo restic.Repository) error {
|
||||
h := restic.Handle{Type: restic.ConfigFile}
|
||||
|
||||
// now remove the original file
|
||||
err := repo.Backend().Remove(ctx, h)
|
||||
if err != nil {
|
||||
return fmt.Errorf("remove config failed: %w", err)
|
||||
if !repo.Backend().HasAtomicReplace() {
|
||||
// remove the original file for backends which do not support atomic overwriting
|
||||
err := repo.Backend().Remove(ctx, h)
|
||||
if err != nil {
|
||||
return fmt.Errorf("remove config failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// upgrade config
|
||||
cfg := repo.Config()
|
||||
cfg.Version = 2
|
||||
|
||||
_, err = repo.SaveJSONUnpacked(ctx, restic.ConfigFile, cfg)
|
||||
_, err := repo.SaveJSONUnpacked(ctx, restic.ConfigFile, cfg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("save new config file failed: %w", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue