Skip to content

Commit

Permalink
Auto merge of #3118 - cbiffle:master, r=alexcrichton
Browse files Browse the repository at this point in the history
Fall back to fs::copy when hard_link fails.

Some filesystems don't allow hard links.  Since Cargo's use of hard
links is an optimization, and not necessary for correctness, it can fall
back to a file copy when hard linking is not available.

This is one possible solution to #3098.

Caveat: this will try to copy if the hard link fails *for any reason*.
It's not clear that there's a more surgical way of handling this; Unix
tends to indicate the condition as "permission denied," not with a
granular "links not supported by filesystem" error.
  • Loading branch information
bors authored Sep 26, 2016
2 parents 2755b3a + cf5640a commit 231dce6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,11 @@ fn rustc(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
human(format!("failed to remove: {}", dst.display()))
}));
}
try!(fs::hard_link(&src, &dst).chain_error(|| {
human(format!("failed to link `{}` to `{}`",
src.display(), dst.display()))
try!(fs::hard_link(&src, &dst)
.or_else(|_| fs::copy(&src, &dst).map(|_| ()))
.chain_error(|| {
human(format!("failed to link or copy `{}` to `{}`",
src.display(), dst.display()))
}));
}
}
Expand Down

0 comments on commit 231dce6

Please sign in to comment.