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

Linker copies files as a fallback when ref-linking fails #1773

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement a fallback for specific InvalidInput failure states on macOS
  • Loading branch information
snowsignal committed Feb 20, 2024
commit 1340a5f2777e558037f81ae05aa5de9d7b20f596
20 changes: 17 additions & 3 deletions crates/install-wheel-rs/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,28 @@ fn clone_recursive(site_packages: &Path, wheel: &Path, entry: &DirEntry) -> Resu
debug!("Cloning {} to {}", from.display(), to.display());

// Attempt to copy the file or directory
let reflink = reflink_copy::reflink_or_copy(&from, &to);
let mut reflink = reflink_copy::reflink_or_copy(&from, &to);
snowsignal marked this conversation as resolved.
Show resolved Hide resolved

let entry_file_type = entry.file_type()?;

// `reflink_or_copy` returns `InvalidInput` on macOS when reflinking a directory that already exists
// at the source destination. We need to properly fallback in this case as well, so we re-run `reflink`
// and check if that gives us an `AlreadyExists` error.
if reflink
.as_ref()
.is_err_and(|err| err.kind() == std::io::ErrorKind::InvalidInput)
&& cfg!(target_os = "macos")
&& !entry_file_type.is_file()
{
reflink = reflink_copy::reflink(&from, &to).map(|()| None);
}

if reflink
.as_ref()
.is_err_and(|err| matches!(err.kind(), std::io::ErrorKind::AlreadyExists))
.is_err_and(|err| err.kind() == std::io::ErrorKind::AlreadyExists)
{
// If copying fails and the directory exists already, it must be merged recursively.
if entry.file_type()?.is_dir() {
if entry_file_type.is_dir() {
for entry in fs::read_dir(from)? {
clone_recursive(site_packages, wheel, &entry?)?;
}
Expand Down