Skip to content

Properly handle home trash behind complex symlinks/mounts#143

Merged
Byron merged 4 commits intoByron:masterfrom
null-dev:nd/canonicalize-trash-path
Apr 6, 2026
Merged

Properly handle home trash behind complex symlinks/mounts#143
Byron merged 4 commits intoByron:masterfrom
null-dev:nd/canonicalize-trash-path

Conversation

@null-dev
Copy link
Copy Markdown
Contributor

@null-dev null-dev commented Apr 1, 2026

Consider the following system configuration:

  • XDG_DATA_HOME=/home/john/.local/share so the home trash folder is located at: /home/john/.local/share/Trash
  • /home is a mount
  • /home/john/.local is another mount
  • The home trash folder /home/john/.local/share/Trash is a symlink to /home/trash
  • The user now attempts to delete this file: /home/john/foo.

This was not handled properly by the previous logic because the previous logic:

  • Does not determine the true location of the home trash folder by following symlinks
  • Attempts to determine the topdir/mount of the trash folder by looking at $XDG_DATA_HOME or $HOME, and not $XDG_DATA_HOME/Trash or $HOME/.local/share/Trash.

This PR fixes these issues.

only recurse in canonicalize_path when error is NotFound
Comment thread src/freedesktop.rs
} else if topdir.to_str() == Some("/var/home") && home_topdir.to_str() == Some("/") {
debug!("The topdir is '/var/home' but the home_topdir is '/', moving to the home trash anyway.");
move_to_trash(path, &home_trash, topdir).map_err(|(p, e)| fs_error(p, e))?;
} else {
Copy link
Copy Markdown
Contributor Author

@null-dev null-dev Apr 1, 2026

Choose a reason for hiding this comment

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

The changes in this PR allow removing of this hardcoded logic to support Fedora Atomic desktops. This logic was originally needed because on Fedora Atomic desktops:

  • HOME is set to /home/<user>
  • So the home trash is calculated as: $HOME/.local/share/Trash -> /home/<user>/.local/share/Trash
  • /home is a symlink to /var/home
  • /var/home is a mount
  • / is a mount

The previous logic would incorrectly determine the topdir of the home trash /home/<user>/.local/share/Trash to be / because it didn't follow the symlink at /home.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the freedesktop trash implementation to correctly resolve the actual home trash location in the presence of symlinks and nested mount points, so files are routed to the appropriate trash folder/topdir per the freedesktop spec behavior.

Changes:

  • Canonicalize the computed home trash path (following symlinks), even when the final path component doesn’t exist yet.
  • Determine the “home” topdir based on the resolved home trash folder itself (instead of $XDG_DATA_HOME/$HOME).
  • Remove the old home_topdir helper and add canonicalize_path_or_parents to support the above behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/freedesktop.rs
Comment thread src/freedesktop.rs
Comment thread src/freedesktop.rs Outdated
Comment thread src/freedesktop.rs Outdated
@Byron
Copy link
Copy Markdown
Owner

Byron commented Apr 2, 2026

@null-dev Thanks a lot! It think this can be merged once the auto-review comments were resolved.

@vp-oryn vp-oryn force-pushed the nd/canonicalize-trash-path branch from 4859b39 to 8997e9a Compare April 4, 2026 20:29
@null-dev
Copy link
Copy Markdown
Contributor Author

null-dev commented Apr 4, 2026

@null-dev Thanks a lot! It think this can be merged once the auto-review comments were resolved.

Sweet, I've addressed all the comments.

Copy link
Copy Markdown
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

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

Alright, thanks, let's just merge this.

Admittedly, I didn't see to what extend the canonicalisation test makes sense, but at least could see that it uses the respective function under test.
Overall, I'd think this is an improvement, or so I hope as errors around trashing can be fatal.

@Byron Byron merged commit 5a7c7f7 into Byron:master Apr 6, 2026
4 checks passed
@null-dev null-dev deleted the nd/canonicalize-trash-path branch April 11, 2026 22:02
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.

3 participants