Skip to content

Commit 689fe2a

Browse files
committed
Workaround copying file returning EAGAIN on ZFS on mac OS
Falling back to 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. Looks related to openzfsonosx/zfs#809 Closes #13838
1 parent d34d0a1 commit 689fe2a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

crates/cargo-util/src/paths.rs

+17-1
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 == 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)