From bfecf5301b61f41c69bdb776a16d8f5f5652d8d5 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 20 Aug 2021 10:22:35 +0100 Subject: [PATCH] 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. --- backend/box/box.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/box/box.go b/backend/box/box.go index 7f41def85..ad4968496 100644 --- a/backend/box/box.go +++ b/backend/box/box.go @@ -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