andreafrancia / trash-cli

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

Trash-{list,restore,empty} not working on bindfs mounted directories #250

Closed omernaveedxyz closed 2 years ago

omernaveedxyz commented 2 years ago

Describe the bug I am running NixOS on a Btrfs volume alongside the impermanence module (linked here). Currently this module is only applied to a single directory in my home folder. What this module does is that it bindfs mounts the directory from a separate Btrfs subvolume (i.e. /persistent) to the user's home directory (i.e. ~/Desktop in subvolume /). What this allows is for me to wipe unnecessary cache files and only persist necessary files between boot (I wipe the home partition between boots).

The issue I have with Trash-cli is that it does not seem to detect files that are trashed within these directories. Running trash-put ~/Desktop/<file> will create a ~/Desktop/.Trash-1000 folder with the correct file information, but trash-restore, trash-list, and trash-empty will not detect this folder regardless if I run the commands from within the ~/Desktop directory or /persistent/home/<user>/Desktop where the original file contents are.

trash-cli version trash-put 0.22.8.27

Operating system:

To Reproduce: $ cd ~/Desktop $ touch foo $ trash-put foo $ tree -a

.
└── .Trash-1000
    ├── files
    │   └── foo
    └── info
        └── foo.trashinfo

3 directories, 2 files

$ trash-list


$ trash-list --trash-dir=.Trash-1000

2022-09-21 00:39:26 /home/omer/Desktop/foo

$ trash-restore

No files trashed from current dir ('/home/omer/Desktop')

$ trash-empty

Would empty the following trash directories:
    - /home/omer/.local/share/Trash
Proceed? (y/n) n

Expected behavior These commands should recognize the ~/Desktop/Trash-1000 folder and give me the ability to restore/empty if I desire.

As an aside, I would prefer if the files where trashed to ~/.local/share/Trash but I believe that is a limitation of each directory being a separate bindfs mount, separate from the subvolume mounting the home directory.

Output of trash-list --debug-volumes

Filesystem                    1024-blocks     Used Available Capacity Mounted on
devtmpfs                          1625108        0   1625108       0% /dev
tmpfs                            16251048    45324  16205724       1% /dev/shm
tmpfs                             8125524     7968   8117556       1% /run
tmpfs                            16251048      408  16250640       1% /run/wrappers
/dev/mapper/root                499565892 78797304 419893064      16% /
/dev/mapper/root                499565892 78797304 419893064      16% /nix
/dev/mapper/root                499565892 78797304 419893064      16% /persistent
/dev/mapper/root                499565892 78797304 419893064      16% /snapshots
/dev/mapper/root                499565892 78797304 419893064      16% /swap
/dev/nvme0n1p1                     523248    55724    467524      11% /boot
tmpfs                             3250208       20   3250188       1% /run/user/1000
/persistent/home/omer/Desktop   499565892 78797304 419893064      16% /home/omer/Desktop
physical ->
[sdiskpart(device='/dev/mapper/root', mountpoint='/', fstype='btrfs', opts='rw,noatime,compress=zstd:3,ssd,space_cache=v2,subvolid=256,subvol=/@', maxfile=255, maxpath=4096),
 sdiskpart(device='/dev/mapper/root', mountpoint='/nix', fstype='btrfs', opts='rw,noatime,compress=zstd:3,ssd,space_cache=v2,subvolid=257,subvol=/@nix', maxfile=255, maxpath=4096),
 sdiskpart(device='/dev/mapper/root', mountpoint='/nix/store', fstype='btrfs', opts='ro,noatime,compress=zstd:3,ssd,space_cache=v2,subvolid=257,subvol=/@nix', maxfile=255, maxpath=4096),
 sdiskpart(device='/dev/mapper/root', mountpoint='/persistent', fstype='btrfs', opts='rw,noatime,compress=zstd:3,ssd,space_cache=v2,subvolid=258,subvol=/@persistent', maxfile=255, maxpath=4096),
 sdiskpart(device='/dev/mapper/root', mountpoint='/snapshots', fstype='btrfs', opts='rw,noatime,compress=zstd:3,ssd,space_cache=v2,subvolid=260,subvol=/@snapshots', maxfile=255, maxpath=4096),
 sdiskpart(device='/dev/mapper/root', mountpoint='/swap', fstype='btrfs', opts='rw,noatime,compress=zstd:3,ssd,space_cache=v2,subvolid=259,subvol=/@swap', maxfile=255, maxpath=4096),
 sdiskpart(device='/dev/nvme0n1p1', mountpoint='/boot', fstype='vfat', opts='rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro', maxfile=1530, maxpath=4096)]
virtual ->
[sdiskpart(device='', mountpoint='/run/keys', fstype='ramfs', opts='rw,nosuid,nodev,relatime,mode=750', maxfile=255, maxpath=4096),
 sdiskpart(device='/persistent/home/omer/Desktop', mountpoint='/home/omer/Desktop', fstype='fuse', opts='rw,nosuid,nodev,relatime,user_id=1000,group_id=100,default_permissions,allow_other', maxfile=255, maxpath=4096),
 sdiskpart(device='bpf', mountpoint='/sys/fs/bpf', fstype='bpf', opts='rw,nosuid,nodev,noexec,relatime,mode=700', maxfile=255, maxpath=4096),
 sdiskpart(device='cgroup2', mountpoint='/sys/fs/cgroup', fstype='cgroup2', opts='rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot', maxfile=255, maxpath=4096),
 sdiskpart(device='configfs', mountpoint='/sys/kernel/config', fstype='configfs', opts='rw,nosuid,nodev,noexec,relatime', maxfile=255, maxpath=4096),
 sdiskpart(device='debugfs', mountpoint='/sys/kernel/debug', fstype='debugfs', opts='rw,nosuid,nodev,noexec,relatime', maxfile=255, maxpath=4096),
 sdiskpart(device='devpts', mountpoint='/dev/pts', fstype='devpts', opts='rw,nosuid,noexec,relatime,gid=3,mode=620,ptmxmode=666', maxfile=255, maxpath=4096),
 sdiskpart(device='devtmpfs', mountpoint='/dev', fstype='devtmpfs', opts='rw,nosuid,size=1625108k,nr_inodes=4059446,mode=755', maxfile=255, maxpath=4096),
 sdiskpart(device='efivarfs', mountpoint='/sys/firmware/efi/efivars', fstype='efivarfs', opts='rw,nosuid,nodev,noexec,relatime', maxfile=255, maxpath=4096),
 sdiskpart(device='fusectl', mountpoint='/sys/fs/fuse/connections', fstype='fusectl', opts='rw,nosuid,nodev,noexec,relatime', maxfile=255, maxpath=4096),
 sdiskpart(device='hugetlbfs', mountpoint='/dev/hugepages', fstype='hugetlbfs', opts='rw,relatime,pagesize=2M', maxfile=255, maxpath=4096),
 sdiskpart(device='mqueue', mountpoint='/dev/mqueue', fstype='mqueue', opts='rw,nosuid,nodev,noexec,relatime', maxfile=255, maxpath=4096),
 sdiskpart(device='proc', mountpoint='/proc', fstype='proc', opts='rw,nosuid,nodev,noexec,relatime', maxfile=255, maxpath=4096),
 sdiskpart(device='pstore', mountpoint='/sys/fs/pstore', fstype='pstore', opts='rw,nosuid,nodev,noexec,relatime', maxfile=255, maxpath=4096),
 sdiskpart(device='securityfs', mountpoint='/sys/kernel/security', fstype='securityfs', opts='rw,nosuid,nodev,noexec,relatime', maxfile=255, maxpath=4096),
 sdiskpart(device='sysfs', mountpoint='/sys', fstype='sysfs', opts='rw,nosuid,nodev,noexec,relatime', maxfile=255, maxpath=4096),
 sdiskpart(device='tmpfs', mountpoint='/dev/shm', fstype='tmpfs', opts='rw,nosuid,nodev,size=16251048k', maxfile=255, maxpath=4096),
 sdiskpart(device='tmpfs', mountpoint='/run', fstype='tmpfs', opts='rw,nosuid,nodev,size=8125524k,mode=755', maxfile=255, maxpath=4096),
 sdiskpart(device='tmpfs', mountpoint='/run/wrappers', fstype='tmpfs', opts='rw,nodev,relatime,size=16251048k,mode=755', maxfile=255, maxpath=4096),
 sdiskpart(device='tmpfs', mountpoint='/run/user/1000', fstype='tmpfs', opts='rw,nosuid,nodev,relatime,size=3250208k,nr_inodes=812552,mode=700,uid=1000,gid=100', maxfile=255, maxpath=4096)]
andreafrancia commented 2 years ago

I've added "fuse" to the list of "physical" file systems types.

Try install the latest version directly from the repository

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

and let me know if it solves the problem.

omernaveedxyz commented 2 years ago

Yes, the directory ~/Desktop/.Trash-1000 is now correctly sourced by the various trash-cli commands. Thank you for resolving this so quickly.

As for my second point, is there no way to store all of these trashed files into ~/.local/share/Trash?

andreafrancia commented 2 years ago

Have you tried the following?

trash-put --trash-dir=~/.local/share/Trash foo
omernaveedxyz commented 2 years ago

trash-put --trash-dir=~/.local/share/Trash -v foo

trash-put: Volume of file: /home/omer/Desktop
trash-put: Trash-dir: ~/.local/share/Trash from volume: /home/omer/Desktop
trash-put: 'foo' trashed in ~/.local/share/Trash

tree -a ~/Desktop

.
├── ~
│   └── .local
│       └── share
│           └── Trash
│               ├── files
│               │   └── foo
│               └── info
│                   └── foo.trashinfo

6 directories, 2 files

That is not the desired file structure. Trying:

trash-put --trash-dir=/home/omer/.local/share/Trash -v foo

trash-put: Volume of file: /home/omer/Desktop
trash-put: Trash-dir: /home/omer/.local/share/Trash from volume: /
trash-put: cannot trash regular empty file 'foo'
andreafrancia commented 2 years ago

You're right! I think we can close this issue.