Skip to content

Commit

Permalink
Use same-file to avoid unnecessary hard links
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Aug 10, 2017
1 parent 88d15f9 commit 599db09
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ libc = "0.2"
libgit2-sys = "0.6"
log = "0.3"
num_cpus = "1.0"
same-file = "0.1"
scoped-tls = "0.1"
semver = { version = "0.7.0", features = ["serde"] }
serde = "1.0"
Expand Down
1 change: 1 addition & 0 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern crate jobserver;
extern crate libc;
extern crate libgit2_sys;
extern crate num_cpus;
extern crate same_file;
extern crate semver;
extern crate serde;
extern crate serde_ignored;
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::io::{self, Write};
use std::path::{self, PathBuf};
use std::sync::Arc;

use same_file::is_same_file;
use serde_json;

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

debug!("linking {} to {}", src.display(), dst.display());
if is_same_file(src, dst).unwrap_or(false) {
continue
}
if dst.exists() {
fs::remove_file(&dst).chain_err(|| {
format!("failed to remove: {}", dst.display())
Expand Down

0 comments on commit 599db09

Please sign in to comment.