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

feat: Short circuiting check for empty trash #120

Merged
merged 1 commit into from
Oct 26, 2024

Conversation

joshuamegnauth54
Copy link
Contributor

is_empty() is a short circuiting function that checks if the trash is empty on Freedesktop compatible systems and Windows.

The main purpose of is_empty() is to avoid evaluating the entire trash context when the caller is only interested in whether the trash is empty or not. This is especially useful for full trashes with many items.

I have to write unit tests, so I'll keep this as a draft till tomorrow or so.

`is_empty()` is a short circuiting function that checks if the trash is
empty on Freedesktop compatible systems and Windows.

The main purpose of `is_empty()` is to avoid evaluating the entire trash
context when the caller is only interested in whether the trash is empty
or not. This is especially useful for full trashes with many items.
@joshuamegnauth54 joshuamegnauth54 marked this pull request as ready for review October 9, 2024 05:14
joshuamegnauth54 added a commit to joshuamegnauth54/cosmic-files that referenced this pull request Oct 16, 2024
Closes: pop-os#310

Depends on Byron/trash-rs#120 which implements a function that only
checks if the trash is empty or not instead of parsing each item.
@sofiedotcafe
Copy link

+1

Copy link
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing and sorry for the wait - apparently there are no notifications when the PR changes its draft status, or I somehow managed to miss it.

In any case, I think this is good to go!

}
}
Err(e) => {
warn!("The trash files folder {:?} could not be read. Error was {:?}", bin, e);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting issue - should everything be an error if one folder can't be read?
Right now it assume they are empty even if all of them can't be read.

Unfortunately I don't know if it's common to try to access 'invalid' folders, so I guess we can try to run with this for a while.

@Byron Byron merged commit 0120bbe into Byron:master Oct 26, 2024
4 checks passed
@Byron
Copy link
Owner

Byron commented Oct 26, 2024

And here is the new release: https://github.com/Byron/trash-rs/releases/tag/v5.2.0

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

Successfully merging this pull request may close these issues.

3 participants