andreafrancia / trash-cli

Command line interface to the freedesktop.org trashcan.
GNU General Public License v2.0
3.53k stars 177 forks source link

I have a number of bind mounts, and `trash-list` shows trashed items without any duplication. #341

Open andreafrancia opened 3 months ago

andreafrancia commented 3 months ago

I have a number of bind mounts, and trash-list shows trashed items without any duplication. However, the problem in my case is that trash-put moves items to ".Trash-1000" in that mount (creating one if it doesn't exist), and not to "~/.local/share/Trash". In that case, I don't see them in my trash can (e.g. in the file manager or desktop); I have to enter trash-list in terminal to check those trashcans in bind mounts.

Originally posted by @Sadi58 in https://github.com/andreafrancia/trash-cli/issues/301#issuecomment-2032611391

Sadi58 commented 3 months ago

@andreafrancia Thank you very much. The reason why I simply added a comment to issue #301 was because I wasn't sure if my problem was entirely different or simply another aspect of the same problem concerning how trash-cli handles bind mounts. I even don't know much about how bind mounts are managed in the system, especially concerning the Trash. In my Debian KDE Plasma system, Dolphin file manager simply moves items from all different bind mounts to a single Trash located at ~/.local/share/Trash but it seems not all tools and apps behave like this, because sometimes I see that folder named .Trash-1000 in the root of those bind mounts containing items, which are not detected and shown by my file manager. This happened before trash-cli came to my attention, and I immediately started using it the other day, which apparently does not behave like Dolphin file manager. Actually, it even refused to accept the symlinks named .Trash in those bind mounts pointing to ~/.local/share/Trash so that I can see them all in my Trashcan.

andreafrancia commented 3 months ago

Hi @Sadi58, I think (but I'm not sure) that maybe KDE/Dolphin is implementing just the Trash to the home trash dir (~/.local/share/Trash) the Trash Specifications is OK. According the afore mentioned Trash Specification an trash implementation can also use directories like these: /disk/.Trash-1000 or /disk/.Trash/1000. This should have the benefit of not moving file through the partitions. trash-cli uses this second option. I don't know whether other trash implementation out there which option of the Trash Specification are using. Maybe on your computer there is another that support trashing in /disk/.Trash-1000. The problem with this option is that trash-cli sees binds as a volumes. It is strange though that KDE does not sees trashed files in /path-to-bind/.Trash-1000.

Unfortunately at this moment trash-cli does not have an option to tell him to trash always in ~/.local/share/Trash.

Sadi58 commented 3 months ago

Hi @andreafrancia, I understand; I'll try to find a way to make Dolphin file manager watch other trash locations as well - it seems this makes more sense. Meanwhile, I did some tests with some trash-put options:

  1. The option --trash-dir looked promising, but didn't work as I hoped as another possible workaround; when I executed the command find . -maxdepth 1 ! -name 'Empty*' -exec trash-put -f -r --trash-dir=~/.local/share/Trash {} + in a bind mount location, the result looked disastrous: a new directory named "~" was created in the current location, which looked empty, and trash-list didn't show anything. I would later discover that this odd directory included the hidden ".local" directory in the new trash path! :-D
  2. There's also inconsistency between help and man about the use of "=" sign there. Apparently, ~ is interpreted as the user home directory only if you use space instead of = in this option, and an absolute path must be used after the = sign. , I also learned that correctly pointing to a location in another volume in this way is not accepted either (but the trash-dir must be in the same volume). I think users should better be warned about all this. Thanks again for this very useful tool which I use in several scripts instead of rm where I can't use kioclient5 move "$filename" trash:/
andreafrancia commented 3 months ago

The expansion of the tilde "~" character is handled by the shell you are currently using (maybe Bash or Zsh). It is possible that ~ is recognized only when use the space instead of a equal sign "=".

If any documentation of trash-cli man page is suggesting to use "=" in conjunction with tilde "~" please tell me where so I can fix it. You can also send a pull request for the manual.

I'm not able to unwrap what's the meaning of your find command.

Thank to you for using it, I hope to find the time to implement an option to force the home trash directory in the future.