diff options
| author | bors <bors@rust-lang.org> | 2016-12-19 15:36:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-12-19 15:36:15 +0000 |
| commit | 3f9823d5f53230e83b707b4876b5bb271a4c22ef (patch) | |
| tree | 44f308b9a4585e49c3bcb504851a04158157499d /src/bootstrap | |
| parent | 10271ea24fbd7b28a42df8eb02a8dcf6d6132d71 (diff) | |
| parent | a5193057b9a70ab3ed9786294b67cfeca327a7ad (diff) | |
Auto merge of #38405 - alexcrichton:rustbuild-fixes, r=japaric
rustbuild: Fix `copy` helper with existing files This erroneously truncated files when the destination already existed and was an existing hard link to the source. This in turn caused weird bugs! Closes #37745
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/util.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs index cb5b456a0f2..c9e756b6f99 100644 --- a/src/bootstrap/util.rs +++ b/src/bootstrap/util.rs @@ -41,6 +41,12 @@ pub fn mtime(path: &Path) -> FileTime { /// Copies a file from `src` to `dst`, attempting to use hard links and then /// falling back to an actually filesystem copy if necessary. pub fn copy(src: &Path, dst: &Path) { + // A call to `hard_link` will fail if `dst` exists, so remove it if it + // already exists so we can try to help `hard_link` succeed. + let _ = fs::remove_file(&dst); + + // Attempt to "easy copy" by creating a hard link (symlinks don't work on + // windows), but if that fails just fall back to a slow `copy` operation. let res = fs::hard_link(src, dst); let res = res.or_else(|_| fs::copy(src, dst).map(|_| ())); if let Err(e) = res { |
