andreafrancia / trash-cli

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

Add a flag to trash-restore to allow a force overwrite of existing files #259

Closed Matt-London closed 1 year ago

Matt-London commented 1 year ago

When attempting to restore the entire trash it quickly fails with the following error:

$ touch test.txt
$ trash test.txt
$ touch test.txt
$ trash-restore
> 0-1
Refusing to overwrite existing file "test.txt".

This can be frustrating if the trash has thousands of files, which is the situation I was in (I do not clear it often enough!). I love the trash system otherwise, but this restore functionality would greatly improve my specific use case.

Instead allowing the user to pass a flag like --force could overwrite the files whenever this is encountered.

There is the potential that I am one of the few who would benefit from this flag, but I wanted to reach out and share my perspective. Keep up the great work!

andreafrancia commented 1 year ago

Pull request: https://github.com/andreafrancia/trash-cli/pull/260

andreafrancia commented 1 year ago

Hi @Matt-London, thank for your contribution!! I've a doubt about what would happen if the session is going to restore multiple version of the same file.

$ trash-restore --overwrite
   0 2022-11-03 14:27:15 /Users/andrea/kata/scalable-merchant-app/web/frontend/pippo
   1 2022-11-03 14:27:16 /Users/andrea/kata/scalable-merchant-app/web/frontend/pippo
   2 2022-11-03 14:27:16 /Users/andrea/kata/scalable-merchant-app/web/frontend/pippo
   3 2022-11-03 14:27:17 /Users/andrea/kata/scalable-merchant-app/web/frontend/pippo
What file to restore [0..3]: 0-3

Which version would remain? The latest? Is right to lose all the other versions?

Matt-London commented 1 year ago

In my experiment the latest version would remain. In this case latest in the list and latest chronologically as I believe it will loop from 0 to 2 and restore the files in that order. So the last file to be restored would be file 2 and so the most recently trashed file. For the use case I originally implemented this for, this is my intended solution. Do you have something else in mind?

andreafrancia commented 1 year ago

I'm thinking that it would be great if we can restore only the most recent trashed file and keep the others in the in the bin.

Matt-London commented 1 year ago

I agree that would be a useful feature. At the moment I have not dived deep enough into the code to have an idea of how that could be implemented, but I will try and think about it. Since the original feature was merged would you like me to close this issue? Thanks for implementing my code!