Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Trash folders on alternate drives/partitions #2

Closed
rushsteve1 opened this issue Aug 25, 2021 · 5 comments
Closed

Support Trash folders on alternate drives/partitions #2

rushsteve1 opened this issue Aug 25, 2021 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@rushsteve1
Copy link
Owner

rushsteve1 commented Aug 25, 2021

This is a follow-up to #1

Currently trash-d will copy a file into the user's home trash folder when trashing a file on a different drive/partition. This isn't great from a speed and space perspective, nor from a compatibility one (though it is spec-compliant).

A future version of trash-d could enumerate /proc/mounts (or some other facility if D has one) to find out what device it is on, then use that information to find and use a .Trash folder on that device.

However this also poses a number of UX issues. trash --list would have to find and list the trash on every single device, trash --empty now has the potential for considerably more unintended damage. trash --del and trash --restore are now ambiguous if you have 2 files with the same name across different drives.

In addition to all this, it could substantially complicate trash-d's code since there would no longer be a single known trash directory. It could also possibly tie it even more tightly to Linux, and I would like to support the BSDs which would complicate things further.

This issue is for discussing the future of this feature, and in general determining whether or not it is worth doing. So questions, comments, and suggestions are welcome!

@rushsteve1 rushsteve1 added enhancement New feature or request help wanted Extra attention is needed labels Aug 25, 2021
@rushsteve1 rushsteve1 changed the title Support trashing on alternate drives/partitions Support Trash folders on alternate drives/partitions Aug 25, 2021
@ibara
Copy link

ibara commented Aug 25, 2021

In addition to all this, it could substantially complicate trash-d's code since there would no longer be a single known trash directory. It could also possibly tie it even more tightly to Linux, and I would like to support the BSDs which would complicate things further.

Only OpenBSD lacks procfs, if you are concerned about that. We'd probably take a version(OpenBSD): _don't do procfs_ and be fine with it. An interested person can always come around later and make multiple trash dirs work without procfs.

@CyberShadow
Copy link

A future version of trash-d could enumerate /proc/mounts (or some other facility if D has one) to find out what device it is on, then use that information to find and use a .Trash folder on that device.

I have a /proc/mounts parser here:
https://github.com/CyberShadow/ae/blob/d1978633a28b3ea0a0a33ea29b61ff45cc8623c5/sys/file.d#L1614-L1703

If you decide to write one yourself, make sure to unescape the paths.

A more portable alternative may be to walk up the directory hierarchy until st_dev changes.

realpath should be called before doing either.

@rushsteve1
Copy link
Owner Author

Only OpenBSD lacks procfs, if you are concerned about that. We'd probably take a version(OpenBSD): _don't do procfs_ and be fine with it. An interested person can always come around later and make multiple trash dirs work without procfs.

The immediate problem with this approach would be introducing different behaviors on different OSes, and the separate code paths to go with. And I feel like doing this even for one OS opens the can of worms. and suddenly there's justification for platform-specific version flags everywhere. My whole intent in restricting it to POSIX/Freedesktop systems was to avoid the need for platform specific code.


I have a /proc/mounts parser here:
https://github.com/CyberShadow/ae/blob/d1978633a28b3ea0a0a33ea29b61ff45cc8623c5/sys/file.d#L1614-L1703

If you decide to write one yourself, make sure to unescape the paths.

Thanks for sharing this, could be very helpful!

A more portable alternative may be to walk up the directory hierarchy until st_dev changes.

This could be a very good way to work around parsing /proc/mounts in a way that would work on all POSIX systems. Though I can't think of a way to implement --list, --empty, or --restore using this, since they'd need to know the location of all trash folders and can't walk the tree backwards.

@rushsteve1
Copy link
Owner Author

Two possible workaround that I've come up with are:

  • The ability to set the path to the trash directory via CLI option or environment variable.
  • A CLI/envvar toggle that causes trash-d to walk up from the cwd looking for .Trash/ folders or device switches. This one is a bit trickier since it'd need to detect what partition $HOME is on, as well as fall back when necessary. It also isn't really good UX.

One or both of these could be a good stopgap at least.

rushsteve1 added a commit that referenced this issue Sep 3, 2021
Added support for setting the trash directory via the environment
variable TRASH_D_DIR.

Related to #2
@rushsteve1
Copy link
Owner Author

Closing this as being largely fixed in version 15 as part of #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants