mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
b2: Repeat deleting until all file versions are removed
When hard deleting the latest file version on B2, this uncovers earlier versions. If an upload required retries, multiple version might exist for a file. Thus to reliably delete a file, we have to remove all versions of it.
This commit is contained in:
parent
0d9ac78437
commit
fc506f8538
@ -274,16 +274,24 @@ func (be *b2Backend) Remove(ctx context.Context, h restic.Handle) error {
|
||||
be.sem.GetToken()
|
||||
defer be.sem.ReleaseToken()
|
||||
|
||||
// the retry backend will also repeat the remove method up to 10 times
|
||||
for i := 0; i < 3; i++ {
|
||||
obj := be.bucket.Object(be.Filename(h))
|
||||
err := obj.Delete(ctx)
|
||||
if err == nil {
|
||||
// keep deleting until we are sure that no leftover file versions exist
|
||||
continue
|
||||
}
|
||||
// consider a file as removed if b2 informs us that it does not exist
|
||||
if b2.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.Wrap(err, "Delete")
|
||||
}
|
||||
|
||||
return errors.New("failed to delete all file versions")
|
||||
}
|
||||
|
||||
type semLocker struct {
|
||||
sema.Semaphore
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user