2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +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:
Michael Eischer 2022-08-21 11:11:00 +02:00
parent 0d9ac78437
commit fc506f8538

View File

@ -274,14 +274,22 @@ func (be *b2Backend) Remove(ctx context.Context, h restic.Handle) error {
be.sem.GetToken() be.sem.GetToken()
defer be.sem.ReleaseToken() 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)) obj := be.bucket.Object(be.Filename(h))
err := obj.Delete(ctx) 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 // consider a file as removed if b2 informs us that it does not exist
if b2.IsNotExist(err) { if b2.IsNotExist(err) {
return nil return nil
} }
return errors.Wrap(err, "Delete") return errors.Wrap(err, "Delete")
}
return errors.New("failed to delete all file versions")
} }
type semLocker struct { type semLocker struct {