Skip to content

Commit

Permalink
refactor: move mtime_on_use check up to caller
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Jan 29, 2024
1 parent 21f4de7 commit bf0b156
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,14 @@ fn compare_old_fingerprint(
mtime_on_use: bool,
forced: bool,
) -> Option<DirtyReason> {
let compare = _compare_old_fingerprint(old_hash_path, new_fingerprint, mtime_on_use);
if mtime_on_use {
// update the mtime so other cleaners know we used it
let t = FileTime::from_system_time(SystemTime::now());
debug!("mtime-on-use forcing {:?} to {}", old_hash_path, t);
paths::set_file_time_no_err(old_hash_path, t);
}

let compare = _compare_old_fingerprint(old_hash_path, new_fingerprint);
log_compare(unit, &compare);
match compare {
Ok(None) if forced => Some(DirtyReason::Forced),
Expand All @@ -1754,17 +1761,9 @@ fn compare_old_fingerprint(
fn _compare_old_fingerprint(
old_hash_path: &Path,
new_fingerprint: &Fingerprint,
mtime_on_use: bool,
) -> CargoResult<Option<DirtyReason>> {
let old_fingerprint_short = paths::read(old_hash_path)?;

if mtime_on_use {
// update the mtime so other cleaners know we used it
let t = FileTime::from_system_time(SystemTime::now());
debug!("mtime-on-use forcing {:?} to {}", old_hash_path, t);
paths::set_file_time_no_err(old_hash_path, t);
}

let new_hash = new_fingerprint.hash_u64();

if util::to_hex(new_hash) == old_fingerprint_short && new_fingerprint.fs_status.up_to_date() {
Expand Down

0 comments on commit bf0b156

Please sign in to comment.