From 28e2731594e1520239859832c2a722b1d5b54eeb Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Wed, 13 Sep 2023 16:06:17 +0800 Subject: [PATCH] fix: clear cache recursively on deleting the folder (close #5209) --- internal/op/fs.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/op/fs.go b/internal/op/fs.go index 5a22362e738..8ee6993e091 100644 --- a/internal/op/fs.go +++ b/internal/op/fs.go @@ -84,6 +84,14 @@ func addCacheObj(storage driver.Driver, path string, newObj model.Obj) { } func ClearCache(storage driver.Driver, path string) { + objs, ok := listCache.Get(Key(storage, path)) + if ok { + for _, obj := range objs { + if obj.IsDir() { + ClearCache(storage, stdpath.Join(path, obj.GetName())) + } + } + } listCache.Del(Key(storage, path)) } @@ -473,6 +481,10 @@ func Remove(ctx context.Context, storage driver.Driver, path string) error { err = s.Remove(ctx, model.UnwrapObj(rawObj)) if err == nil { delCacheObj(storage, dirPath, rawObj) + // clear folder cache recursively + if rawObj.IsDir() { + ClearCache(storage, path) + } } default: return errs.NotImplement