diff --git a/Cargo.lock b/Cargo.lock index 0d598052247..458bbe110ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -445,7 +445,7 @@ dependencies = [ [[package]] name = "cargo-util" -version = "0.2.12" +version = "0.2.13" dependencies = [ "anyhow", "core-foundation", diff --git a/crates/cargo-util/Cargo.toml b/crates/cargo-util/Cargo.toml index 28877eedaf7..060f2f5613d 100644 --- a/crates/cargo-util/Cargo.toml +++ b/crates/cargo-util/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-util" -version = "0.2.12" +version = "0.2.13" rust-version = "1.77" # MSRV:1 edition.workspace = true license.workspace = true diff --git a/crates/cargo-util/src/paths.rs b/crates/cargo-util/src/paths.rs index 1172b002885..f890390b0e0 100644 --- a/crates/cargo-util/src/paths.rs +++ b/crates/cargo-util/src/paths.rs @@ -585,7 +585,23 @@ fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> { // Note that: fs::copy on macos is using CopyOnWrite (syscall fclonefileat) which should be // as fast as hardlinking. // See /~https://github.com/rust-lang/cargo/issues/10060 for the details - fs::copy(src, dst).map(|_| ()) + fs::copy(src, dst).map_or_else( + |e| { + if e.raw_os_error() + .map_or(false, |os_err| os_err == 35 /* libc::EAGAIN */) + { + tracing::info!("copy failed {e:?}. falling back to fs::hard_link"); + + // Working around an issue copying too fast with zfs (probably related to + // /~https://github.com/openzfsonosx/zfs/issues/809) + // See /~https://github.com/rust-lang/cargo/issues/13838 + fs::hard_link(src, dst) + } else { + Err(e) + } + }, + |_| Ok(()), + ) } else { fs::hard_link(src, dst) }