Skip to content

feat: add restore support to macOS#2

Merged
yara-blue merged 6 commits intozed-industries:masterfrom
dinocosta:5039-macos-restore
Apr 7, 2026
Merged

feat: add restore support to macOS#2
yara-blue merged 6 commits intozed-industries:masterfrom
dinocosta:5039-macos-restore

Conversation

@dinocosta
Copy link
Copy Markdown
Member

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 the os_limited module's functionality on macOS, the restore_all function 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::rename for both delete methods, so as to avoid having to either introduce a new argument in restore_all or a new field in TrashItem so we can keep track of the DeleteMethod on macOS. Files deleted via Finder will not have their .DS_Store "Put Back" metadata cleaned up.

@dinocosta dinocosta force-pushed the 5039-macos-restore branch 6 times, most recently from eb1ce59 to 38705c2 Compare February 27, 2026 14:51
@dinocosta dinocosta changed the title 5039 macos restore feat: add restore support to macOS Feb 28, 2026
@dinocosta dinocosta force-pushed the 5039-macos-restore branch 2 times, most recently from 949b9cb to 0f01438 Compare March 2, 2026 21:32
@dinocosta dinocosta changed the base branch from master to 5039-delete-with-info March 24, 2026 15:01
@dinocosta dinocosta changed the base branch from 5039-delete-with-info to master March 25, 2026 19:18
@dinocosta dinocosta marked this pull request as ready for review March 25, 2026 19:19
@dinocosta dinocosta self-assigned this Mar 25, 2026
@dinocosta dinocosta requested a review from yara-blue March 25, 2026 19:19
@dinocosta
Copy link
Copy Markdown
Member Author

Marked as ready for review but will likely need to either rebase or merge main after #1 is merged 🙂

dinocosta and others added 6 commits April 7, 2026 15:17
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.
@dinocosta dinocosta force-pushed the 5039-macos-restore branch from 0f01438 to 8d07846 Compare April 7, 2026 14:18
Comment thread src/macos/mod.rs
});
}

std::fs::create_dir_all(&item.original_parent).map_err(|error| fs_error(&original_path, error))?;
Copy link
Copy Markdown
Member

@yara-blue yara-blue Apr 7, 2026

Choose a reason for hiding this comment

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

could race between fs::exists and this call. Might be better to just try it and then investigate the returned error.

Comment thread src/macos/tests.rs
#[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());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

more tempdir :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

though you'll still need CleanupPaths to yank the trashed but not restored items from the trash...

Comment thread src/lib.rs
{
use std::collections::HashSet;

// Check for twins here cause that's pretty platform independent.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh I just saw that was already in the crate.... no need to change anything then :)

Copy link
Copy Markdown
Member

@yara-blue yara-blue left a comment

Choose a reason for hiding this comment

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

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...

@yara-blue yara-blue merged commit 3bf27ef into zed-industries:master Apr 7, 2026
4 checks passed
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.

2 participants