Skip to content

Commit

Permalink
clean idcache properly
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed May 19, 2023
1 parent 5fe5a77 commit 3378dec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/clean-decomposedfs-idcache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Clean IDCache properly

decomposedfs' subpackage `tree` uses an idCache to avoid reading too often from disc. In case of a `move` or `delete` this cache was
properly cleaned, but when renaming a file (= move with same parent) the cache wasn't cleaned. This lead to strange behaviour when
uploading files with the same name and renaming them

https://github.com/cs3org/reva/pull/3903
13 changes: 8 additions & 5 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func (t *Tree) Move(ctx context.Context, oldNode *node.Node, newNode *node.Node)
}
}

// remove cache entry in any case to avoid inconsistencies
t.idCache.Remove(filepath.Join(oldNode.ParentPath(), oldNode.Name))

// Always target the old node ID for xattr updates.
// The new node id is empty if the target does not exist
// and we need to overwrite the new one when overwriting an existing path.
Expand Down Expand Up @@ -271,7 +274,6 @@ func (t *Tree) Move(ctx context.Context, oldNode *node.Node, newNode *node.Node)
if err != nil {
return errors.Wrap(err, "Decomposedfs: could not move child")
}
t.idCache.Remove(filepath.Join(oldNode.ParentPath(), oldNode.Name))

// update target parentid and name
attribs := node.Attributes{}
Expand Down Expand Up @@ -416,6 +418,10 @@ func (t *Tree) ListFolder(ctx context.Context, n *node.Node) ([]*node.Node, erro

// Delete deletes a node in the tree by moving it to the trash
func (t *Tree) Delete(ctx context.Context, n *node.Node) (err error) {
path := filepath.Join(n.ParentPath(), n.Name)
// remove entry from cache immediately to avoid inconsistencies
t.idCache.Remove(path)

deletingSharedResource := ctx.Value(appctx.DeletingSharedResource)

if deletingSharedResource != nil && deletingSharedResource.(bool) {
Expand Down Expand Up @@ -492,10 +498,7 @@ func (t *Tree) Delete(ctx context.Context, n *node.Node) (err error) {
_ = os.Remove(n.LockFilePath())

// finally remove the entry from the parent dir
path := filepath.Join(n.ParentPath(), n.Name)
err = os.Remove(path)
t.idCache.Remove(path)
if err != nil {
if err = os.Remove(path); err != nil {
// To roll back changes
// TODO revert the rename
// TODO remove symlink
Expand Down

0 comments on commit 3378dec

Please sign in to comment.