Skip to content

Commit

Permalink
Do not destroy metadata when moving items into the trashbin
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Aug 22, 2024
1 parent 32a9971 commit b4dc71c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
14 changes: 13 additions & 1 deletion pkg/storage/fs/posix/trashbin/trashbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func trashRootForNode(n *node.Node) string {
return filepath.Join(n.SpaceRoot.InternalPath(), ".Trash")
}

func (tb *Trashbin) MoveToTrash(n *node.Node, path string) error {
func (tb *Trashbin) MoveToTrash(ctx context.Context, n *node.Node, path string) error {
key := uuid.New().String()
trashPath := trashRootForNode(n)

Expand All @@ -120,6 +120,18 @@ func (tb *Trashbin) MoveToTrash(n *node.Node, path string) error {
return err
}

// purge metadata
if err = tb.lu.IDCache.DeleteByPath(ctx, path); err != nil {
return err
}
if err != nil {
return err
}
err = tb.lu.MetadataBackend().Rename(path, trashPath)
if err != nil {
return err
}

return os.Rename(path, filepath.Join(trashPath, "files", key+".trashitem"))
}

Expand Down
20 changes: 1 addition & 19 deletions pkg/storage/fs/posix/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,25 +488,7 @@ func (t *Tree) Delete(ctx context.Context, n *node.Node) error {
// Remove lock file if it exists
_ = os.Remove(n.LockFilePath())

// purge metadata
err := filepath.WalkDir(path, func(path string, _ fs.DirEntry, err error) error {
if err != nil {
return err
}

if err = t.lookup.(*lookup.Lookup).IDCache.DeleteByPath(ctx, path); err != nil {
return err
}
if err = t.lookup.MetadataBackend().Purge(ctx, path); err != nil {
return err
}
return nil
})
if err != nil {
return err
}

err = t.trashbin.MoveToTrash(n, path)
err := t.trashbin.MoveToTrash(ctx, n, path)
if err != nil {
return err
}
Expand Down

0 comments on commit b4dc71c

Please sign in to comment.