Log most recently modified file for cache-keys (#16338)

For https://github.com/astral-sh/uv/issues/16336. We previously weren't
telling the user which file is responsible for rebuilding.

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This commit is contained in:
konsti 2025-11-02 19:52:07 +01:00 committed by GitHub
parent 857827da14
commit 944ff6c685
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 7 deletions

1
Cargo.lock generated
View file

@ -5504,6 +5504,7 @@ dependencies = [
"thiserror 2.0.17",
"toml",
"tracing",
"uv-fs",
"walkdir",
]

View file

@ -16,6 +16,8 @@ doctest = false
workspace = true
[dependencies]
uv-fs = { workspace = true }
fs-err = { workspace = true }
globwalk = { workspace = true }
schemars = { workspace = true, optional = true }

View file

@ -1,11 +1,12 @@
use std::borrow::Cow;
use std::cmp::max;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use serde::Deserialize;
use tracing::{debug, warn};
use uv_fs::Simplified;
use crate::git_info::{Commit, Tags};
use crate::glob::cluster_globs;
use crate::timestamp::Timestamp;
@ -63,7 +64,7 @@ impl CacheInfo {
pub fn from_directory(directory: &Path) -> Result<Self, CacheInfoError> {
let mut commit = None;
let mut tags = None;
let mut timestamp = None;
let mut last_changed: Option<(PathBuf, Timestamp)> = None;
let mut directories = BTreeMap::new();
let mut env = BTreeMap::new();
@ -128,7 +129,12 @@ impl CacheInfo {
);
continue;
}
timestamp = max(timestamp, Some(Timestamp::from_metadata(&metadata)));
let timestamp = Timestamp::from_metadata(&metadata);
if last_changed.as_ref().is_none_or(|(_, prev_timestamp)| {
*prev_timestamp < Timestamp::from_metadata(&metadata)
}) {
last_changed = Some((path, timestamp));
}
}
CacheKey::Directory { dir } => {
// Treat the path as a directory.
@ -258,14 +264,25 @@ impl CacheInfo {
}
continue;
}
timestamp = max(timestamp, Some(Timestamp::from_metadata(&metadata)));
let timestamp = Timestamp::from_metadata(&metadata);
if last_changed.as_ref().is_none_or(|(_, prev_timestamp)| {
*prev_timestamp < Timestamp::from_metadata(&metadata)
}) {
last_changed = Some((entry.into_path(), timestamp));
}
}
}
}
let timestamp = if let Some((path, timestamp)) = last_changed {
debug!(
"Computed cache info: {timestamp:?}, {commit:?}, {tags:?}, {env:?}, {directories:?}"
"Computed cache info: {timestamp:?}, {commit:?}, {tags:?}, {env:?}, {directories:?}. Most recently modified: {}",
path.user_display()
);
Some(timestamp)
} else {
None
};
Ok(Self {
timestamp,