feat: add restore support to macOS#2
Conversation
eb1ce59 to
38705c2
Compare
949b9cb to
0f01438
Compare
|
Marked as ready for review but will likely need to either rebase or merge |
Co-authored-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
* Move `trash::restore_all` from the `os_limited` module to its parent module, as we want this to be available also to macOS, but not want to be bothered, at least for now, with implementing all of the `os_limited` module's functionality * Update macOS' `restore_all` implementation to correctly handle restore collisions in case a file in the trashed item's location already exists * Add new tests to ensure that restore collisions are handled correctly Co-authored-by: Agus Zubiaga <agus@zed.dev>
The `restore_all` implementation on macOS only checked if there was a file collision when attempting to restore a file. This commit updates the implementation so as to also confirm that the provided trash item's file does exist before attempting to create the original parent folder as well as moving the file.
0f01438 to
8d07846
Compare
| }); | ||
| } | ||
|
|
||
| std::fs::create_dir_all(&item.original_parent).map_err(|error| fs_error(&original_path, error))?; |
There was a problem hiding this comment.
could race between fs::exists and this call. Might be better to just try it and then investigate the returned error.
| #[serial] | ||
| fn test_trash_and_restore_roundtrip_finder() { | ||
| let mut cleanup_paths = CleanupPaths::new(); | ||
| let path = std::env::current_dir().expect("Should be able to get current directory").join(get_unique_name()); |
There was a problem hiding this comment.
though you'll still need CleanupPaths to yank the trashed but not restored items from the trash...
| { | ||
| use std::collections::HashSet; | ||
|
|
||
| // Check for twins here cause that's pretty platform independent. |
There was a problem hiding this comment.
could race here again, as in: this check can pass then something else uses trash and now the actual restore fails with a (maybe?) confusing error.
There was a problem hiding this comment.
oh I just saw that was already in the crate.... no need to change anything then :)
yara-blue
left a comment
There was a problem hiding this comment.
nits regarding correctness (logical races). But its not:
- not something that will realistically happen (undo does not happen concurrently much)
- the crate already contains such race conditions, bringing it up to a level of correctness where those are impossible is a separate concern to this PR.
So lets not do anything about them, for now...
These changes are a followup to #1 and should only be merged after, and if, those changes are shipped.
This PR adds
restore_all()functionality for macOS. Since we don't want to have to implement all of theos_limitedmodule's functionality on macOS, therestore_allfunction has been moved and is now a top-level public function.It's worth noting that the restore implementation currently uses a simple
std::fs::renamefor both delete methods, so as to avoid having to either introduce a new argument inrestore_allor a new field inTrashItemso we can keep track of theDeleteMethodon macOS. Files deleted via Finder will not have their.DS_Store"Put Back" metadata cleaned up.