Skip to content

Commit 8733d5a

Browse files
committed
Auto merge of #13845 - thiblahute:zfs_macos_hard_link, r=weihanglo
Workaround copying file returning EAGAIN on ZFS on mac OS ### What does this PR try to resolve? Fixes #13838 Trying to build simple hello world fail when on zfs file system on macOS fails while trying to copy files around. This PR makes cargo fallback to using hard_link when that happens, retrying can lead to very long wait before copying works (up to 4secs in my tests) while hard_linking works straight away.
2 parents 27d3e3d + 4634aa6 commit 8733d5a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cargo-util/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-util"
3-
version = "0.2.12"
3+
version = "0.2.13"
44
rust-version = "1.77" # MSRV:1
55
edition.workspace = true
66
license.workspace = true

crates/cargo-util/src/paths.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,23 @@ fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
585585
// Note that: fs::copy on macos is using CopyOnWrite (syscall fclonefileat) which should be
586586
// as fast as hardlinking.
587587
// See https://github.com/rust-lang/cargo/issues/10060 for the details
588-
fs::copy(src, dst).map(|_| ())
588+
fs::copy(src, dst).map_or_else(
589+
|e| {
590+
if e.raw_os_error()
591+
.map_or(false, |os_err| os_err == 35 /* libc::EAGAIN */)
592+
{
593+
tracing::info!("copy failed {e:?}. falling back to fs::hard_link");
594+
595+
// Working around an issue copying too fast with zfs (probably related to
596+
// https://github.com/openzfsonosx/zfs/issues/809)
597+
// See https://github.com/rust-lang/cargo/issues/13838
598+
fs::hard_link(src, dst)
599+
} else {
600+
Err(e)
601+
}
602+
},
603+
|_| Ok(()),
604+
)
589605
} else {
590606
fs::hard_link(src, dst)
591607
}

0 commit comments

Comments
 (0)