4

So, I am busy writing myself a program to move and restore items from my trash (recycle bin), currently I can move it to the trash, but if I try to restore it from the trash using a file manager, it fails.

The trash directory is located at ~/.local/share/Trash and it has 2 folders inside it, files/ to store the files you want to delete and info/, to store the data about the files. I got the file naming correct in the application, so that is not the problem, and I got the details that gets stored in the info/ folder correct as well. Yet, if I delete something with my file manager and then recover it from the trash, there is no problem, but when I move it to the trash with my code, it can only be recovered by manually moving it...

Here are some examples of my application:

$ nrash todelete.txt
> Moved to trash

The above creates this: (inside Trash/files)

todelete.txt

(inside Trash/info)

todelete.txt.trashinfo

Inside the .trashinfo file, the following resides:

[Trash Info]
Path=/home/netsu/Documents/todelete.txt
DeletionDate=2021-10-08T18:24:04

In a .trashinfo for a file deleted from the filemanager instead, you would find this:

[Trash Info]
Path=/home/netsu/Documents/pp.txt
DeletionDate=2021-10-08T18:25:02

The two are exactly the same, yet don't work the same... Is there something I'm missing about moving things to the trash? Why can the file that was placed there by the file manager be restored, but the one I placed there can not? Is this the universal way the trash works on Linux distros, or does it change depending on distro/desktop environment?

Note: My file does appear inside Trash when I open it in the file manager, but I can't restore it.

  • Distro: Solus
  • DE: MATE
  • File Manager: Caja
2

1 Answer 1

4

So, the reason I couldn't restore it was simple, in this link https://specifications.freedesktop.org/trash-spec/trashspec-latest.html (thanks Abdullah!), it specifies under Contents of a trash directory that

When trashing a file or directory, the implementation MUST create the corresponding file in $trash/info first.

I moved the file/folder before I created the info file, which in return caused the above problem to occur. Also, for anyone interested in finding out how your Trash/Recycle bin works, I really recommend reading that link posted.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .