Skip to content

Handle folder deletion to go through TrashService - #193

Open
vanxa wants to merge 2 commits into
Vault-Web:mainfrom
vanxa:155/folder-delete-fix
Open

vanxa wants to merge 2 commits into
Vault-Web:mainfrom
vanxa:155/folder-delete-fix

Conversation

@vanxa

@vanxa vanxa commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Handle folder deletion to go through TrashService.
Currently, folder deletion is a simple recursive deletion of the provided directory, and does not go through the TrashService functionality. A brief explanation to what needs to be achieved is provided in ResourceShareService:

   * <p><b>Folders are still hard-deleted here</b>, matching {@code FolderController}'s own delete
   * endpoint for the owner's own folders: this codebase has no folder-level trash mechanism at all
   * today ({@link TrashService#moveToTrash} only accepts a single regular file). Routing folder
   * deletes through trash is real follow-up work — it needs a trash design that can hold a whole
   * subtree, restore it, and account for its size against retention/quota — not a one-line change
   * here, so it is intentionally out of scope for this fix rather than silently expanding it.
   */

This PR attempts to implement this functionality.

AC:

  • TrashEntries can be nested within each other (i.e. parent-child relationship)
  • TrashService handles deletion of an entire folder
  • Size calculation is expanded to account for an entire folder that is moved to trash
  • When restoring a folder, quota and size calculations are adapted accordingly
  • Listing trash items can handle trashed folders as well
  • New code is covered with tests

Linked issue

Closes #155

How to test

Notes / Risk

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent review

The only change is an empty if (Files.isDirectory(source)) stub in moveToTrash. It has no effect, directories still throw ResourceNotFoundException, and there are no tests. See the inline comment.

Generated by Pull Request Review for #193 · copilot · auto · 10.1 AIC · ⌖ 0.509 AIC · ⊞ 7.1K

Path source = Paths.get(rootPath, relativeFilePath).normalize();
FileUtils.validatePath(rootPath, source);
if (Files.isDirectory(source)) {
// handle directory deletion.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is empty, so it does nothing. A directory path (e.g. moveToTrash(root, uid, "docs")) skips the block and then fails the !Files.isRegularFile(source) check just below with ResourceNotFoundException. Behaviour is unchanged. If directory trashing is meant to be implemented here, it needs real logic (move the tree, record trash metadata, restore support) plus tests. Otherwise drop this dead stub. Please don't merge a placeholder that appears to handle directories but doesn't.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vanxa please check this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[audit] Folder delete bypasses Trash, and a blank/"." folderPath wipes the whole root including .trash

2 participants