andreafrancia / trash-cli

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

Check trash-info target trash folder non-exists before confirming #297

Closed soraxas closed 1 year ago

soraxas commented 1 year ago

Currently, there's a loop to append suffixes (_1, _2, _3, ...) when trashinfo already exists, which is good.

However, given a trashinfo, our target path_of_backup_copy might already exists, which will cause the algorithm to fail.

E.g.:

$ ls ~/.local/share/Trash/info
my_dir_1.trashinfo

$ ls ~/.local/share/Trash/files
my_dir_1/
my_dir_2/
my_dir_3/

The looping will confirm to use my_dir_2.trashinfo as the target trashinfo, and only realises that the my_dir_2 = path_of_backup_copy("my_dir_2.trashinfo") actually already exists when performing the move via OS call:

trash: Failed to trash build/ in ~/.local/share/Trash, because: Destination path '/home/xxx/.local/share/Trash/files/my_dir_2' already exists

The existence of my_dir_2/, my_dir_3/, ... might be due to other similar named files, trashed by the system file manager, etc.

andreafrancia commented 1 year ago

Thank you.