forked from TrueCloudLab/restic
backend/retry: Overwrite failed uploads instead of deleting them
For backends which are able to atomically replace files, we just can overwrite the old copy, if it is necessary to retry an upload. This has the benefit of issuing one operation less and might be beneficial if a backend storage, due to bugs or similar, could mix up the order of the upload and delete calls.
This commit is contained in:
parent
fc506f8538
commit
de0162ea76
1 changed files with 10 additions and 4 deletions
|
@ -68,10 +68,16 @@ func (be *RetryBackend) Save(ctx context.Context, h restic.Handle, rd restic.Rew
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
debug.Log("Save(%v) failed with error, removing file: %v", h, err)
|
if be.Backend.HasAtomicReplace() {
|
||||||
rerr := be.Backend.Remove(ctx, h)
|
debug.Log("Save(%v) failed with error: %v", h, err)
|
||||||
if rerr != nil {
|
// there is no need to remove files from backends which can atomically replace files
|
||||||
debug.Log("Remove(%v) returned error: %v", h, err)
|
// in fact if something goes wrong at the backend side the delete operation might delete the wrong instance of the file
|
||||||
|
} else {
|
||||||
|
debug.Log("Save(%v) failed with error, removing file: %v", h, err)
|
||||||
|
rerr := be.Backend.Remove(ctx, h)
|
||||||
|
if rerr != nil {
|
||||||
|
debug.Log("Remove(%v) returned error: %v", h, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return original error
|
// return original error
|
||||||
|
|
Loading…
Reference in a new issue