andreafrancia / trash-cli

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

trash-empty: option to only empty files trashed prior to application start #318

Open chapmanjacobd opened 9 months ago

chapmanjacobd commented 9 months ago

Is your feature request related to a problem? Please describe.

When trash-empty runs for a long time it's possible that files are deleted sooner than expected (trash-empty running concurrently to a process which uses trash-put).

This might seem like a rare edge-case but in my workflows it is an hourly occurrence. It defeats the purpose of a recycle bin if the files are deleted prior to me running trash-empty for the next batch of files.

Describe the solution you'd like

I imagine that you could modify the DeleteAccordingDate class to check against a module const. For example:

APPLICATION_START = datetime.now(tz=timezone.utc).timestamp()

If something is trashed after APPLICATION_START, then Emptier would ignore that file.

Describe alternatives you've considered

Of course, I could run trash-empty less often, but the context here is an automated workflow and trash-cli fits in very well with the exception of this issue and this seems like it would be an easy fix.

Additional context

trash --version
0.22.10.20
andreafrancia commented 8 months ago

You can put a check at the beginning of DeleteAccordingDate.ok_to_delete(). Something like:

if parse_deletion_date(contents) >= application_start:
    return False

But you should also consider the case when parse_deletion_date() returns None. The application start can be detected in EmptyAction.run_action() at can be passed as a parameter to the emptier.do_empty() function.