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

trash-empty not working for partitions #65

Closed
mxmlnkn opened this issue Jun 7, 2016 · 9 comments
Closed

trash-empty not working for partitions #65

mxmlnkn opened this issue Jun 7, 2016 · 9 comments

Comments

@mxmlnkn
Copy link

mxmlnkn commented Jun 7, 2016

I have several mounted partitions in /media/. They each have their own .Trash folder

du -shc /media/*/.Trash*
    5.5M    /media/d/.Trash
trash-empty
du -shc /media/*/.Trash*
    5.5M    /media/d/.Trash

As can be seen above trash-empty will in any case (couldn't find options and current working dir also didn't seem to matter) only empty ~/.local/share/Trash and not .Trash on my mounted partitons. I found this very unexpected, I would have thought trash-empty clears all trashs like nemo and Thunar would do.

@andreafrancia
Copy link
Owner

trash-empty should empty all your trashed files, it means that it will delete trashed files from these directories:

  • the ~/.local/share/Trash directory
  • all the $topdir/.Trash/$uid directories
  • all the $topdir/.Trash-$uid directories

For example if you had uid=1000, in your case it should remove at least all your trashed files from:

  • ~/.local/share/Trash directory
  • /media/d/.Trash/1000
  • /media/d/.Trash-1000

For example it does not remove files from other user directories (for example if your uid is 1000 it will not touch any file in /media/d/.Trash-1001 nor any file in /media/d/.Trash/1001).

It will remove only files that represent 'garbage' it will remove only these files:

  • .trashinfo files (for example /media/d/.Trash/1000/info/*.trashinfo`)
  • backup copy files (for example /media/d/.Trash/1000/files/*`)
    it will leave untouched any file that does not match one of these two categories.

Please provide more information about the non deleted contents of your trash directories including full file names, permissions and mount type of your partition if you want reopen this issue. Also check if you have the latest version of trash-cli.

@mxmlnkn
Copy link
Author

mxmlnkn commented Jan 1, 2017

Current versions:

sudo apt-get install -t sid trash-cli
    trash-cli is already the newest version (0.12.9.14-2.1)
trash --version
    trash 0.12.9.14
trash-empty --version
    /usr/bin/trash-empty 0.12.9.14

You might be right, so trash-empty only deletes .Trash-1000, not .Trash in my case. Starting out with nothing:

du -shc /mnt/d/.Trash*
du: cannot access '/mnt/d/.Trash*': No such file or directory
0	total

I create and delete this file and try to empty the trash:

touch /mnt/d/cmakecache.txt
trash /mnt/d/cmakecache.txt
la /mnt/d/.Trash/1000/files/    
    -rwxrwxrwx 1 mxmlnkn mxmlnkn   0 Jan  1 11:00 cmakecache.txt
trash-empty
la /mnt/d/.Trash/1000/files/
    -rwxrwxrwx 1 mxmlnkn mxmlnkn   0 Jan  1 11:00 cmakecache.txt

And now trash-empty does not work. I can force it to work with:

mv /mnt/d/.Trash{/1000,-1000}
la .Trash-1000/files/
    -rwxrwxrwx 1 mxmlnkn mxmlnkn   0 Jan  1 11:00 cmakecache.txt
trash-empty
la .Trash-1000/files/
    # nothing

Some minimal information about that partition

mount | grep /mnt/d
    /dev/sda4 on /mnt/d type fuseblk (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)

It seems like, unlike you told, it only deletes $topdir/.Trash-$UID, not $topdir/.Trash/$UID At least in my system.

@mxmlnkn
Copy link
Author

mxmlnkn commented Jan 1, 2017

So I added some debug output to /usr/lib/python2.7/dist-packages/trashcli/ and got this:

[TrashDirs] Try /mnt/c/.Trash/1000
analyze /mnt/c/.Trash-1000 on volume /mnt/c
[TrashDirs] Try /mnt/d/.Trash/1000
[TrashDirs] /mnt/d/.Trash/1000 not valid because parent is not sticky
Traceback (most recent call last):
  File "/usr/bin/trash-empty", line 5, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/dist-packages/trashcli/cmds.py", line 31, in empty
    ).run(*sys.argv)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 942, in run
    parse(argv)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 806, in __call__
    self.default_action()
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 969, in _empty_all_trashdirs
    self.trashdirs.list_trashdirs()
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 880, in list_trashdirs
    self._for_each_volume_trashcan()
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 887, in _for_each_volume_trashcan
    self.emit_trashcans_for(volume)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 889, in emit_trashcans_for
    self.emit_trashcan_1_for(volume)
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 905, in emit_trashcan_1_for
    self.top_trashdir_rules.valid_to_be_read(top_trashdir_path, IsValidOutput())
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 1042, in valid_to_be_read
    output.not_valid_parent_should_be_sticky()
  File "/usr/lib/python2.7/dist-packages/trashcli/trash.py", line 899, in not_valid_parent_should_be_sticky
    assert( False )
AssertionError

Line numbers may differ because of the debug outputs.
I guess this might be similar to this bug.

Trying if setting .Trash to sticky would work:

la /mnt/d/.Trash/1000/files/
    -rwxrwxrwx 1 mxmlnkn mxmlnkn   0 Jan  1 11:32 test.txt
ls -ld /mnt/d/.Trash/
chmod +t /mnt/d/.Trash/
    ls -ld /mnt/d/.Trash/
    drwxrwxrwx 1 mxmlnkn mxmlnkn 144 Jan  1 11:32 .Trash/
trash-empty
la /mnt/d/.Trash/1000/files/
    -rwxrwxrwx 1 mxmlnkn mxmlnkn   0 Jan  1 11:32 test.txt

So yeah, I can't set sticky (or change permissions on that volume in general), because it is a NTFS mounted volume.
I don't see in the first place why sticky on the parent is a required condition for a trash folder to be deleted. It's my own folder, so even if it was sticky I should have permissions to delete it. Plus it's counterintuitive that /mnt/d/.Trash-1000 works anyway, I guess because it only checks if /mnt/d is sticky, maybe it doesn't even, because it is the topdir.

@andreafrancia andreafrancia reopened this Jan 1, 2017
@andreafrancia
Copy link
Owner

andreafrancia commented Jan 1, 2017

trash-cli does not support filesystem that does not allow to set the sticky bit.

In commit (2a83ed5) I've add a secret --trash-dir option to trash-empty. With this option you can get trash-empty to empty a specified directory bypassing the sticky bit check.

For example you may want use like that:

trash-empty --trash-dir /mnt/d/.Trash/

@mxmlnkn
Copy link
Author

mxmlnkn commented Jan 1, 2017

Ok, Thank you.

@oblitum
Copy link

oblitum commented Jan 6, 2018

trash-empty/trash-list never works inside other partitions for me, it doesn't matter which filesystem, I've tried both ext4 and ntfs. I had rm as an alias to trash-put but in truth it's quite annoying, because anytime I do a rm (trash-put in fact) on a file in whatever partition I have, the files get moved to a /.Trash-1000 directory at the partition that file resides, but trash-empty/trash-list just recognizes the trash of my system's partition, not the others, so I can't forget to delete those /.Trash-1000 directories with /bin/rm.

@mxmlnkn
Copy link
Author

mxmlnkn commented Jan 6, 2018

trash-list output for me:

TrashDir skipped because parent not sticky: /media/d/.Trash/1000

@oblitum
Copy link

oblitum commented Jan 6, 2018

@mxmlnkn for me it shows nothing, just tried on an NTFS partition, touched a file and removed. The partition didn't have a ./Trash-1000 directory at first, then it gets created after the first trash-put there, and the file is moved there, then trash-list shows nothing. I think the referred #56 issue is more particular to this.

@mxmlnkn
Copy link
Author

mxmlnkn commented Jan 6, 2018

Ah sry, I might still have my personally touched version of trash-cli and just forgot about it.

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

No branches or pull requests

3 participants