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

added: restore_single TrashItem that can restore to arbitrary destination and force restore #138

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jx-00
Copy link

@jx-00 jx-00 commented Mar 14, 2025

I need the ability to restore to arbitrary destination and force restore, for my one of my project.

This also addresses a todo:

// TODO add option to forcefully replace any target at the restore location if it already exists.

Cheers.

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 a lot for the initiative.

In its current form I don't think the forceful removal will be usable by anyone just yet unless this is wired up on the top-level. There it would also only be available for freedesktop users I presume.

Personally I also find myself avoiding bare booleans in favor of enums that clearly say what they do when in argument position.

@jx-00
Copy link
Author

jx-00 commented Mar 17, 2025

I can try to make it work and a introduce top-level api under os_limited.
One issue is, I'm not familiar with the how things is done on windows, but with enough experimenting, I should get something to work.

@jx-00
Copy link
Author

jx-00 commented Mar 17, 2025

At first, I thought I can just do a small refactor like I did for freedesktop, but to my limited knowledge, its seems each restore operation depends on a IFileOperation object, which means there will be an extra parameter for fn restore_single. This is probably not desirable, and a solution is to create IFileOperation object each loop, but this is probably also not desirable. I suggest, we can hide the extra stuff the operation needs in a struct, like how OpenOptions is for File::open.

The function signature would look something like this:

pub fn restore_single(item: &TrashItem, restore_options: &RestoreOptions) -> Result<(), Error>;

, with the struct looking like this:

pub struct RestoreOptions {
    // generic
    destination: Path,
    force: bool,
    // specific
    pfo: IFileOperation,
    ...
}

Later on RestoreOptions can possibly be generalize for other operation.

@Byron thought?

@Byron
Copy link
Owner

Byron commented Mar 19, 2025

Having OS-limited functions would be a way forward - that way you could just avoid platforms that you don't specifically need.

jx-00 added 2 commits March 22, 2025 15:53

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…rce restore
@jx-00 jx-00 changed the title added: restore_single TrashItem, restore to arbitrary destination, force restore added: restore_single TrashItem that can restore to arbitrary destination and force restore Mar 22, 2025
@Byron Byron marked this pull request as draft March 23, 2025 02:04
@jx-00
Copy link
Author

jx-00 commented Mar 23, 2025

This is done if I am not missing anything?

  • wired up on the top-level
  • enum over boolean

Sorry, something went wrong.

@jx-00 jx-00 marked this pull request as ready for review March 23, 2025 21:04
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.

Apologies, it might be that my browser showed CI as failing even though it was not, due to some cache issue.

I did leave some comments though and it doesn't look like the PR is aligned yet with what I thought it would be.

@@ -343,6 +343,13 @@ pub struct TrashItemMetadata {
pub size: TrashItemSize,
}

#[derive(Debug, Clone, Copy, Default)]
pub enum RestoreMode {
Copy link
Owner

Choose a reason for hiding this comment

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

This isn't documented at all. Could you add #![deny(missing_docs)] to lib.rs? That way this would light up in CI.

@@ -343,6 +343,13 @@ pub struct TrashItemMetadata {
pub size: TrashItemSize,
}

#[derive(Debug, Clone, Copy, Default)]
pub enum RestoreMode {
Force,
Copy link
Owner

Choose a reason for hiding this comment

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

The variants could probably be less abstract by spelling out more closely what they do.

/// }
/// ```
///
/// [`RestoreCollision`]: Error::RestoreCollision
/// [`RestoreTwins`]: Error::RestoreTwins
pub fn restore_all<I>(items: I) -> Result<(), Error>
pub fn restore_all<I>(items: I, mode: RestoreMode) -> Result<(), Error>
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this can be a breaking change, after all this is only implemented on one platform.
Further, I was expecting that restore_single() is exposed on a single platform, right now it doesn't seem available at all.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I totally agree. I went this route because I noticed that the same functions on Windows and Freedesktop are routed to os_limited. Since I’m not super familiar with Windows, I didn’t feel confident implementing restore_single() for it, so I decided to change the argument instead to keep things consistent.

I did consider adding configuration attributes specifically for Freedesktop, but since there wasn’t a precedent for that, I wasn’t quite sure how to approach it.

Some guidance on this would be much appreciated!

Copy link
Owner

Choose a reason for hiding this comment

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

Some guidance on this would be much appreciated!

Undo the public API change and instead expose restore_single() in an os-limited way, just for the platform it's actually implemented in. This is new to this crate and you'd have to add such capability and probably a test as well (for the public API) just to be sure it's actually accessible.

@jx-00
Copy link
Author

jx-00 commented Mar 27, 2025

Sorry, if anything it's probably something I did wrong. I'm still new to working non solo project. I'm trying to learn what I can.
Unfortunately, I don't have much free time recently to work on projects. Hopefully things will be better in few days.

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.

None yet

2 participants