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-put --home-fallback (was: trash-put cannot trash regular empty file) #247

Open andreafrancia opened 2 years ago

andreafrancia commented 2 years ago

Hey @andreafrancia , I am facing the similar issue.

When I use trash-put in my home directory, it works perfectly as you can see

image

However, we have another disk \data and trash-put command does not work there.

image

I have created a .Trash-$UID dir and provided the permissions as mentioned in the documentation chmod a+rw .Trash-$UID` chmod +t .Trash-$UID

I am not sure what to do. Could you please help me out?

Thanks, Naman

Originally posted by @bnaman50 in https://github.com/andreafrancia/trash-cli/issues/9#issuecomment-1243072011

andreafrancia commented 2 years ago

Please try these commands and send me the output:

$ trash-put --version
$ trash-list --debug-volumes
$ trash-put --verbose aa.txt
bnaman50 commented 2 years ago

Thanks for your response, @andreafrancia.

Here are the output of the commands you asked me to run -

Looking at the output of the last command, it seems it is trying to write to /data/.Trash-1006. However, this directory does not exist. Rather, I have /data/naman/.Trash-1006. I don't have sudo access on this machine. So would it be possible to trash/put the deleted contents in my user directory on the same volume, say /data/naman/.Trash-1006 or /data/naman/.local/share/Trash.

Once again, thanks for all the help!

Naman

andreafrancia commented 2 years ago

I cannot understand why it does not use directly the home trash dir (/home/naman/.local/share/Trash). The --verbose option does not emit sufficient data to understand the current situation.

Please, try to use this command:

trash-put --verbose --trash-dir=/home/naman/.local/share/Trash aa.txt
bnaman50 commented 2 years ago

Hey @andreafrancia,

Here is the output

image

I think this is happening because the file aa.txt is on different disk (\data)

andreafrancia commented 2 years ago

Please try this, please:

ls ~/.local/share/Trash/files/aa.txt

Try also to trash a file named bb.txt, please

bnaman50 commented 2 years ago

Hey @andreafrancia,

I did not have any file named bb.txt so I created one in the \data disk but the issue remains.

image

If I create the file bb.txt in my home dir, trash-put as expected.

image

Thanks, Naman

andreafrancia commented 2 years ago

I think we're almost there, try this:

$ ls -lad /data/aa.txt
$ ls -lad /data
bnaman50 commented 2 years ago

Hey @andreafrancia ,

Here are the results -

image

Just to clarify again, I only access to a directory in /data disk which /data/naman.

image

Thanks, Naman

andreafrancia commented 2 years ago

ok, I was wrong about the path of aa.txt. I think the issue can be related to the ACLs of the file. Try this please:

$ getfacl /data/naman/aa.txt
$ getfacl /data/naman
$ getfacl /data
bnaman50 commented 2 years ago

@andreafrancia

andreafrancia commented 2 years ago

Can you also try the folllowings?

$ cd /data/naman
$ touch cc.txt
$ ls -lad cc.txt
$ getfacl /data/naman/cc.txt`
$ mkdir -p /data/naman/tmp-trash
$ mv -v aa.txt /data/naman/tmp-trash 
$ mv -v cc.txt /data/naman/tmp-trash 
bnaman50 commented 2 years ago

Hey @andreafrancia ,

This is working as expected but I don't think it solves the trash-put issue though.

image

Thanks, Naman

andreafrancia commented 2 years ago

Hi @bnaman50, it's not a permission issue.

Please try this:

$ ls /home/naman/.local/share/Trash/files/aa*
$ ls /home/naman/.local/share/Trash/info/aa*

Please redact any output line with sensible information.

Thank you Andrea

bnaman50 commented 2 years ago

Hey @andreafrancia,

It shows that there is no file named aa* in the location you specified.

image

And this is expected since when we moved the file over here /data/naman/tmp-trash following there commands.

Thanks, Naman

andreafrancia commented 2 years ago

Hi @bnaman50. Sorry for the delay. I know we moved the source file to the /data/naman/tmp-trash. Sometimes the trash-put fails because there is already a similar named file in ~/.local/share/Trash/files but a similar named file is not present in the ~/.local/share/Trash/info directory. This is why asked you to check the directories in ~/.local/share/Trash.

I've added some other debug messages to trash-put. You need to uninstall the current version of trash-cli and install the latest version for using them:

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

The try to trash aa.txt using the debug option: -vv (with two "v"):

trash-put -vv aa.txt

Some other ideas: The aa.txt file is the only one that does not work? What happen if you rename the file?

bnaman50 commented 2 years ago

Hey @andreafrancia ,

Sorry, I got busy and could not try out the solution. Here is the update -

I reinstalled it as you suggested. I also tried the command and here is the log -

image

Seems like it is expecting the trash folder to be in /data/. However, I don't have access to it. I only have access to /data/naman.

Thanks, Naman

andreafrancia commented 2 years ago

There is a problem when it tries to trash it in the first trash-dir (~/.local/share/Trash), it doesn't succeed but it does not show any error message. I'm trying to refactor the make it clearer and find where is the place where it may fail and it does not show the error.

Please the next time use copy and paste of the terminal text instead if pasting an image. For me would be easier copy part of the text.

bnaman50 commented 2 years ago

Thanks a lot for your continuous help @andreafrancia. And yes, I'll write the errors in the text form rather than image from now onwards.

Thanks, Naman

andreafrancia commented 2 years ago

Hi, I've read and refactored the code in order to understand what is happening on your machine.

When you trash a file from /data trash-cli considers three trash-dir candidates:

  1. /home/naman/.local/share/Trash in volume /
  2. /data/.Trash/1006 in volume /data
  3. /data/.Trash-1006 in volume /data

The you want to trash is /data/namam/bb.txt in volume /data

When trash-put starts it first take in consideration the /home/naman/.local/share/Trash dir but it does not use it because the trash dir and the file are in different volumes. Then it tries /data/.Trash/1006 which is in the right volume, but it does not use it because the .Trash directory does not exists, this directory can be created only by the administrator following the instructions described in the README. The it tries to use the /data/.Trash-1006 directory (which is the right volume) but it fails because you user cannot create the directory .Trash-1006 in /data.

I've updated the trash-put los in order to be more clear in cases like your. Your problem would be solved when I implement the --home-fallback option for trash-put

bnaman50 commented 2 years ago

Great. Thanks for the detailed explanation, @andreafrancia.

I'll request the admin to add the top-level trash dir and mentioned in the Readme.

However, best option would be to have trash directory at user level even for other volumes such as \data. Could you please leave it as open and only close it once you implement this feature? That way, I'll get to know that you have updated it and accordingly, I can make changes on my side.

Thanks, Naman

raffaem commented 1 year ago

I am experiencing a similar issue with latest git version of trash-cli:

❯ /home/raffaele/.local/bin/trash-put -vv /mnt/dataint/data/progetti_miei/raffaem.github.io/_posts/2015-03-15-formatting-and-links.md
trash-put: volume of file: /
trash-put: trying trash dir: /home/raffaele/.local/share/Trash from volume: /home
trash-put: won't use trash dir ~/.local/share/Trash because its volume (/home) in a different volume than /mnt/dataint/data/progetti_miei/raffaem.github.io/_posts/2015-03-15-formatting-and-links.md (/)
trash-put: found unusable .Trash dir (should be a dir): /.Trash
trash-put: trash directory is not secure: /.Trash/1000
trash-put: trying trash dir: /.Trash-1000 from volume: /
trash-put: failed to trash /mnt/dataint/data/progetti_miei/raffaem.github.io/_posts/2015-03-15-formatting-and-links.md in /.Trash-1000, because: [Errno 13] Permission denied: '/.Trash-1000'
trash-put: stats for /.Trash-1000: [Errno 2] No such file or directory: '/.Trash-1000'
trash-put: stats for /: 755 root root
trash-put: cannot trash regular file '/mnt/dataint/data/progetti_miei/raffaem.github.io/_posts/2015-03-15-formatting-and-links.md'
franzhuang commented 1 year ago

I've encountered similar issue. Irm(or mv)the ~/.local/share/Trash folder, and let trash-put create a new one by just trash-put some_file . It works so far.

andreafrancia commented 11 months ago

@bnaman50 I'll leave open this issue until we managed to implement properly --home-fallback

andreafrancia commented 11 months ago

@raffaem I created another GitHub issue for your issue, it is here: #320