trash-cli icon indicating copy to clipboard operation
trash-cli copied to clipboard

trash-empty lists trash directories in /proc, /sys, /, /dev, /run

Open ayushnix opened this issue 2 years ago • 10 comments

Describe the bug I'm not sure when it started or how it happened but when I execute trash-empty, I get the following output

Would empty the following trash directories:
    - /home/user/.local/share/Trash
    - /proc/.Trash-1000
    - /sys/.Trash-1000
    - /dev/.Trash-1000
    - /run/.Trash-1000
    - /sys/firmware/efi/efivars/.Trash-1000
    - /.Trash-1000
    - /sys/kernel/security/.Trash-1000
    - /dev/shm/.Trash-1000
    - /dev/pts/.Trash-1000
    - /sys/fs/cgroup/.Trash-1000
    - /sys/fs/pstore/.Trash-1000
    - /sys/fs/bpf/.Trash-1000
    - /proc/sys/fs/binfmt_misc/.Trash-1000
    - /dev/mqueue/.Trash-1000
    - /dev/hugepages/.Trash-1000
    - /sys/kernel/debug/.Trash-1000
    - /sys/kernel/tracing/.Trash-1000
    - /tmp/.Trash-1000
    - /sys/fs/fuse/connections/.Trash-1000
    - /sys/kernel/config/.Trash-1000
    - /data/.Trash-1000
    - /boot/.Trash-1000
    - /home/.Trash-1000
    - /data1/.Trash-1000
    - /data2/.Trash-1000
    - /run/user/1000/.Trash-1000
    - /mnt/nas/.Trash-1000
    - /run/netns/.Trash-1000
    - /run/netns/vpn/.Trash-1000
    - /run/netns/vpn/.Trash-1000
    - /proc/sys/fs/binfmt_misc/.Trash-1000
Proceed? (y/n)

These trash directories aren't present in any location mentioned above, except ~/.local/share/Trash, /data/.Trash-1000, and /mnt/nas/.Trash-1000. The /mnt/nas directory is an SSHFS mount. If I enter y, it just gives me

trash-empty: cannot remove /mnt/nas/.Trash-1000/files/backup

and entering trash-empty gives the same menu again.

trash-cli version trash-put 0.21.10.24

Operating system: Arch Linux

Expected behavior trash-empty shouldn't list trash directories where they aren't present, especially in folders like /sys, /dev, and /proc.

ayushnix avatar Oct 30 '21 10:10 ayushnix

As a temporary "fix", you can use yes | trash-empty to bypass the prompt. (Of course, this doesn't solve the underlying issue.)

cheap-glitch avatar Nov 22 '21 12:11 cheap-glitch

I guess this was caused by guard.ask_the_user() being uncommented a few months ago:

https://github.com/andreafrancia/trash-cli/commit/821be0d411c70305017df42c150687624c5fc713#diff-4ec732b70507c7953cb84a23f5a6a43a47b0872a58e219178f95ebc7ab54e068

It looks like this is supposed to be the behaviour only when using the -i switch, but it's always happening.

I assume it's also not meant to show trash directories for every possible mountpoint, but I'm not sure.

crdx avatar Nov 22 '21 17:11 crdx

Have to agree with @crdx here, it does not make sense to walk every single mount point available on the system, especially since the average user account won't even have write access to most of these and thus cannot make any operations there. Also it's highly unlikely that there will be trash folders there during normal operations.

zpuskas avatar Dec 04 '21 17:12 zpuskas

There's not even a --trash-dir option for trash-empty.

I pretty much only use this command under root, where this feels particularly dangerous so I cannot use this at all.

For some strange reason, under root, the /.Trash-0/ directory is created.

For me it only makes sense to empty the trash in ~/.local/share/Trash/, and I believe for most others.

stevenxxiu avatar Dec 06 '21 00:12 stevenxxiu

There's not even a --trash-dir option for trash-empty.

I have that option for trash-empty. It appears in the command's help and I verified that it works.

$ trash-empty --help
usage: trash-empty [-h] [--version] [--trash-dir TRASH_DIR] [--all-users] [-i] [-f] [days]
[...]

TheWall89 avatar Dec 06 '21 06:12 TheWall89

Thank you TheWall89, the use of alias trash-empty='trash-empty -trash-dir=/home/me/.local/share/Trash' doesn't solve the underlying problem of course but works nicely 👍

LudoPinelli avatar Dec 28 '21 02:12 LudoPinelli

I solved this issue by rollbacking the version to 0.21.6.10.1. pip3 install trash-cli==0.21.6.10.1

image

caixxiong avatar Feb 11 '22 07:02 caixxiong

This should be a prioritized issue, IMO. This is bad UX (most likely unintended but still). And it gives the impression that more is being deleted when it isn't. Those directories don't exist for me, even though they are printed.

victorz avatar Feb 28 '22 13:02 victorz

Seems this now misses /mnt/nas and similar.

Euren avatar Apr 30 '22 00:04 Euren

Current remediation does not resolve the problem enough in Ubuntu Desktop. Snap package manager mounts squashfs for each packages. Commit 22e655b stops listing non-physical mountpoints but trash-empty lists snap mountpoints yet.

    - /snap/bare/5/.Trash-1000
    - /snap/chromium/1967/.Trash-1000
    - /snap/core/12834/.Trash-1000
    - /snap/core/12941/.Trash-1000
    - /snap/core18/2284/.Trash-1000
    - /snap/core18/2344/.Trash-1000
    - /snap/core20/1405/.Trash-1000
    - /snap/discord/131/.Trash-1000
    - /snap/discord/132/.Trash-1000
    - /snap/gnome-3-28-1804/161/.Trash-1000
    - /snap/gnome-3-28-1804/145/.Trash-1000
    - /snap/gnome-3-34-1804/72/.Trash-1000
    - /snap/gnome-3-34-1804/77/.Trash-1000
    - /snap/gnome-3-38-2004/87/.Trash-1000
    - /snap/gnome-3-38-2004/99/.Trash-1000
    - /snap/gtk-common-themes/1515/.Trash-1000
    - /snap/gtk-common-themes/1519/.Trash-1000
    - /snap/snap-store/575/.Trash-1000
    - /snap/snapd/15177/.Trash-1000
    - /snap/snapd/15534/.Trash-1000
    - /snap/chromium/1973/.Trash-1000
    - /snap/core20/1434/.Trash-1000
    - /snap/snap-store/582/.Trash-1000
    ...

IMO, cheking all mountpoints and simply listing trash directories which actually exist are good remediation.

ytoku avatar Apr 30 '22 19:04 ytoku

Hi @ayushnix, we have two problems here:

  1. trash-empty shows non existent trash directory
  2. trash-empty can not delete /mnt/nas/.Trash-1000/files/backup

The problem 1) should be solved on master, you can install the latest version from source code using:

pip uninstall trash-cli
pip install pip install git+https://github.com/andreafrancia/trash-cli

The problem 2) probably is related to the permission for of the /mnt/nas/.Trash-1000/files/backup file. Try removing it directly with sudo rm /mnt/nas/.Trash-1000/files/backup, probably is a directory with strange permission.

andreafrancia avatar Aug 19 '22 18:08 andreafrancia

@stevenxxiu please don't add your issue to a pre-existing ticket. If you need the --trash-dir you need to install the latest version of trash-cli. If you still have problems open another ticket, don't write here.

andreafrancia avatar Aug 19 '22 18:08 andreafrancia

@Euren please your own ticket if you still have problems.

andreafrancia avatar Aug 19 '22 18:08 andreafrancia