Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chapmanjacobd opened this issue Oct 24, 2023 · 1 comment

Comments

@chapmanjacobd
Copy link

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
@chapmanjacobd chapmanjacobd changed the title trash-empty: option to only empty files deleted prior to application start trash-empty: option to only empty files trashed prior to application start Oct 24, 2023
@andreafrancia
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants