Skip to content

Commit

Permalink
refactor: remove unnecessary branch for link binary on macOS
Browse files Browse the repository at this point in the history
The other workaround branch should have covered that.
  • Loading branch information
weihanglo committed May 2, 2024
1 parent 8733d5a commit f8aead9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
4 changes: 0 additions & 4 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,10 +1286,6 @@ pub trait TestEnv: Sized {
.env_remove("USER") // not set on some rust-lang docker images
.env_remove("XDG_CONFIG_HOME") // see #2345
.env_remove("OUT_DIR"); // see #13204
if cfg!(target_os = "macos") {
// Work-around a bug in macOS 10.15, see `link_or_copy` for details.
self = self.env("__CARGO_COPY_DONT_LINK_DO_NOT_USE_THIS", "1");
}
if cfg!(windows) {
self = self.env("USERPROFILE", paths::home());
}
Expand Down
28 changes: 10 additions & 18 deletions crates/cargo-util/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,26 +565,18 @@ fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
src
};
symlink(src, dst)
} else if env::var_os("__CARGO_COPY_DONT_LINK_DO_NOT_USE_THIS").is_some() {
// This is a work-around for a bug in macOS 10.15. When running on
// APFS, there seems to be a strange race condition with
// Gatekeeper where it will forcefully kill a process launched via
// `cargo run` with SIGKILL. Copying seems to avoid the problem.
// This shouldn't affect anyone except Cargo's test suite because
// it is very rare, and only seems to happen under heavy load and
// rapidly creating lots of executables and running them.
// See https://github.com/rust-lang/cargo/issues/7821 for the
// gory details.
fs::copy(src, dst).map(|_| ())
} else {
if cfg!(target_os = "macos") {
// This is a work-around for a bug on macos. There seems to be a race condition
// with APFS when hard-linking binaries. Gatekeeper does not have signing or
// hash information stored in kernel when running the process. Therefore killing it.
// This problem does not appear when copying files as kernel has time to process it.
// 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
// There seems to be a race condition with APFS when hard-linking
// binaries. Gatekeeper does not have signing or hash information
// stored in kernel when running the process. Therefore killing it.
// This problem does not appear when copying files as kernel has
// time to process it. Note that: fs::copy on macos is using
// CopyOnWrite (syscall fclonefileat) which should be as fast as
// hardlinking. See these issues for the details:
//
// * https://github.com/rust-lang/cargo/issues/7821
// * https://github.com/rust-lang/cargo/issues/10060
fs::copy(src, dst).map_or_else(
|e| {
if e.raw_os_error()
Expand Down

0 comments on commit f8aead9

Please sign in to comment.