Skip to content

Commit

Permalink
Auto merge of #13845 - thiblahute:zfs_macos_hard_link, r=weihanglo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed May 2, 2024
2 parents 27d3e3d + 4634aa6 commit 8733d5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/cargo-util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 17 additions & 1 deletion crates/cargo-util/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 8733d5a

Please sign in to comment.