-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs | ||
index 56a8528d..b8e862da 100644 | ||
--- a/src/bootstrap/src/core/download.rs | ||
+++ b/src/bootstrap/src/core/download.rs | ||
@@ -706,9 +706,7 @@ pub(crate) fn maybe_download_ci_llvm(&self) { | ||
let file_times = fs::FileTimes::new().set_accessed(now).set_modified(now); | ||
|
||
let llvm_config = llvm_root.join("bin").join(exe("llvm-config", self.build)); | ||
- let llvm_config_file = t!(File::options().write(true).open(llvm_config)); | ||
- | ||
- t!(llvm_config_file.set_times(file_times)); | ||
+ t!(crate::utils::helpers::set_file_times(llvm_config, file_times)); | ||
|
||
if self.should_fix_bins_and_dylibs() { | ||
let llvm_lib = llvm_root.join("lib"); | ||
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs | ||
index a8555b2c..7b55463a 100644 | ||
--- a/src/bootstrap/src/lib.rs | ||
+++ b/src/bootstrap/src/lib.rs | ||
@@ -41,7 +41,9 @@ | ||
use crate::core::config::{DryRun, Target}; | ||
use crate::core::config::{LlvmLibunwind, TargetSelection}; | ||
use crate::utils::exec::{command, BehaviorOnFailure, BootstrapCommand, CommandOutput}; | ||
-use crate::utils::helpers::{self, dir_is_empty, exe, libdir, mtime, output, symlink_dir}; | ||
+use crate::utils::helpers::{ | ||
+ self, dir_is_empty, exe, libdir, mtime, output, set_file_times, symlink_dir, | ||
+}; | ||
|
||
mod core; | ||
mod utils; | ||
@@ -1725,21 +1727,20 @@ fn copy_link_internal(&self, src: &Path, dst: &Path, dereference_symlinks: bool) | ||
} | ||
} | ||
if let Ok(()) = fs::hard_link(&src, 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. | ||
+ // Attempt to "easy copy" by creating a hard link (symlinks are priviledged on windows), | ||
+ // but if that fails just fall back to a slow `copy` operation. | ||
} else { | ||
if let Err(e) = fs::copy(&src, dst) { | ||
panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e) | ||
} | ||
t!(fs::set_permissions(dst, metadata.permissions())); | ||
|
||
+ // Restore file times because changing permissions on e.g. Linux using `chmod` can cause | ||
+ // file access time to change. | ||
let file_times = fs::FileTimes::new() | ||
.set_accessed(t!(metadata.accessed())) | ||
.set_modified(t!(metadata.modified())); | ||
- | ||
- let dst_file = t!(fs::File::open(dst)); | ||
- t!(dst_file.set_times(file_times)); | ||
+ t!(set_file_times(dst, file_times)); | ||
} | ||
} | ||
|
||
diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs | ||
index 773a873e..72ec05e6 100644 | ||
--- a/src/bootstrap/src/utils/helpers.rs | ||
+++ b/src/bootstrap/src/utils/helpers.rs | ||
@@ -545,3 +545,15 @@ pub fn get_closest_merge_base_commit( | ||
|
||
Ok(output_result(git.as_command_mut())?.trim().to_owned()) | ||
} | ||
+ | ||
+/// Sets the file times for a given file at `path`. | ||
+pub fn set_file_times<P: AsRef<Path>>(path: P, times: fs::FileTimes) -> io::Result<()> { | ||
+ // Windows requires file to be writable to modify file times. But on Linux CI the file does not | ||
+ // need to be writable to modify file times and might be read-only. | ||
+ let f = if cfg!(windows) { | ||
+ fs::File::options().write(true).open(path)? | ||
+ } else { | ||
+ fs::File::open(path)? | ||
+ }; | ||
+ f.set_times(times) | ||
+} |