refactor: move mtime_on_use check up to caller

This commit is contained in:
Weihang Lo 2024-01-29 13:20:09 -05:00
parent 21f4de7bcf
commit bf0b156885
No known key found for this signature in database
GPG key ID: D7DBF189825E82E7

View file

@ -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),
@ -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() {