Skip to content

Commit 8720d63

Browse files
committed
Auto merge of #4390 - alexcrichton:read-hard-links, r=matklad
Use `same-file` to avoid unnecessary hard links This is targeted at removing the need for a workaround in rust-lang/rust#39518, allowing the main rust build system to move back to hard links which should be much more efficient.
2 parents 8c6b080 + 599db09 commit 8720d63

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ libc = "0.2"
3838
libgit2-sys = "0.6"
3939
log = "0.3"
4040
num_cpus = "1.0"
41+
same-file = "0.1"
4142
scoped-tls = "0.1"
4243
semver = { version = "0.7.0", features = ["serde"] }
4344
serde = "1.0"

src/cargo/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern crate jobserver;
2525
extern crate libc;
2626
extern crate libgit2_sys;
2727
extern crate num_cpus;
28+
extern crate same_file;
2829
extern crate semver;
2930
extern crate serde;
3031
extern crate serde_ignored;

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io::{self, Write};
66
use std::path::{self, PathBuf};
77
use std::sync::Arc;
88

9+
use same_file::is_same_file;
910
use serde_json;
1011

1112
use core::{Package, PackageId, PackageSet, Target, Resolve};
@@ -496,6 +497,9 @@ fn link_targets<'a, 'cfg>(cx: &mut Context<'a, 'cfg>,
496497
destinations.push(dst.display().to_string());
497498

498499
debug!("linking {} to {}", src.display(), dst.display());
500+
if is_same_file(src, dst).unwrap_or(false) {
501+
continue
502+
}
499503
if dst.exists() {
500504
fs::remove_file(&dst).chain_err(|| {
501505
format!("failed to remove: {}", dst.display())

0 commit comments

Comments
 (0)