box: when doing cleanup delete as much as possible - fixes #5545

Before this change the cleanup routine exited on the first deletion
error.

This change counts any errors on deletion and exits when the iteration
is complete with an error showing the number of deletion failures.
Deletion failures will be logged.
This commit is contained in:
Nick Craig-Wood 2021-08-20 10:22:35 +01:00
parent 308323e9c4
commit bfecf5301b
1 changed files with 7 additions and 2 deletions

View File

@ -1095,6 +1095,7 @@ func (f *Fs) deletePermanently(ctx context.Context, itemType, id string) error {
// CleanUp empties the trash
func (f *Fs) CleanUp(ctx context.Context) (err error) {
var deleteErrors = 0
opts := rest.Opts{
Method: "GET",
Path: "/folders/trash/items",
@ -1124,7 +1125,8 @@ func (f *Fs) CleanUp(ctx context.Context) (err error) {
if item.Type == api.ItemTypeFolder || item.Type == api.ItemTypeFile {
err := f.deletePermanently(ctx, item.Type, item.ID)
if err != nil {
return errors.Wrap(err, "failed to delete file")
fs.Errorf(f, "failed to delete trash item %q: %v", item.ID, err)
deleteErrors++
}
} else {
fs.Debugf(f, "Ignoring %q - unknown type %q", item.Name, item.Type)
@ -1136,7 +1138,10 @@ func (f *Fs) CleanUp(ctx context.Context) (err error) {
break
}
}
return
if deleteErrors != 0 {
return errors.Errorf("failed to delete %d trash items", deleteErrors)
}
return nil
}
// DirCacheFlush resets the directory cache - used in testing as an