xdg-rs / dirs

a low-level library that provides config/cache/data paths, following the respective conventions on Linux, macOS and Windows
187 stars 23 forks source link

Include "trash folder" in API #25

Open Torrencem opened 4 years ago

Torrencem commented 4 years ago

This is a migration of an issue in the old repository.

It would be useful to include a function which gets the path of a user "trash" folder. The problem on the old repository, to summarize, was how Windows didn't have a normal path to the recycle bin.

This is, as far as I can tell, not exactly right: It looks like Windows 7's recycle bin is stored in a hidden folder at "C:\$Recycle.Bin". This appears to be true in Windows 10 as well

Also potentially relevant, Windows appears to have subdirectories of "C:\$Recycle.Bin" for each user's SID, depending on who deleted a file.

So, just to summarize what could work, trash could return: "$XDG_DATA_DIR/Trash" for Linux (on only some distros? more research is needed) "$HOME/.Trash" for MacOS and probably "C:\$Recycle.Bin" for Windows (or "C:\$Recycle.Bin\%SID%" where %SID% is the current user's SID)

tesuji commented 4 years ago

Could you tell me what use-cases that locating trash folder are needed? I guess temporarily removing files to trash bins to recover later is one.

tesuji commented 4 years ago

Researching a bit. I think trash bin usages should be in another crate. The purpose of trash bin/can is to give users one last change to recover files one deleted by mistakes.

Simply moving files to trash bin location is not enough. You will lost information such as the original location of files, original filenames if you rename files when moving, last date modified.

One should consult OS APIs on how to delete files temporarily.

Anyway, I don't think providing trash bin location is a good API decision. I would write a bit about that in documentation of dirs and directories.


References:

Torrencem commented 4 years ago

Yeah, I guess since they're such special case folders, it's probably not a good addition, makes sense