Skip to content

Commit

Permalink
fix: clear cache recursively on deleting the folder (close #5209)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 13, 2023
1 parent b1a279c commit 28e2731
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/op/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 28e2731

Please sign in to comment.