Skip to content

Commit

Permalink
docs(utils): Clarify expected state of name for make_dep_path
Browse files Browse the repository at this point in the history
For index entries, the caller must lowercase the name.
  • Loading branch information
epage committed Feb 21, 2025
1 parent 274253a commit eff4cae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions crates/cargo-util/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
/// - [index from of Cargo's index on filesystem][1], and
/// - [index from Crates.io][2].
///
/// <div class="warning">
///
/// Note: For index files, `dep_name` must have had `to_lowercase` called on it.
///
/// </div>
///
/// [1]: https://docs.rs/cargo/latest/cargo/sources/registry/index.html#the-format-of-the-index
/// [2]: https://github.com/rust-lang/crates.io-index
pub fn make_dep_path(dep_name: &str, prefix_only: bool) -> String {
Expand Down
12 changes: 6 additions & 6 deletions src/cargo/sources/registry/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,19 +584,19 @@ impl Summaries {
) -> Poll<CargoResult<Option<Summaries>>> {
// This is the file we're loading from cache or the index data.
// See module comment in `registry/mod.rs` for why this is structured the way it is.
let name = &name.to_lowercase();
let relative = make_dep_path(&name, false);
let lowered_name = &name.to_lowercase();
let relative = make_dep_path(&lowered_name, false);

let mut cached_summaries = None;
let mut index_version = None;
if let Some(contents) = cache_manager.get(name) {
if let Some(contents) = cache_manager.get(lowered_name) {
match Summaries::parse_cache(contents) {
Ok((s, v)) => {
cached_summaries = Some(s);
index_version = Some(v);
}
Err(e) => {
tracing::debug!("failed to parse {name:?} cache: {e}");
tracing::debug!("failed to parse {lowered_name:?} cache: {e}");
}
}
}
Expand All @@ -609,7 +609,7 @@ impl Summaries {
return Poll::Ready(Ok(cached_summaries));
}
LoadResponse::NotFound => {
cache_manager.invalidate(name);
cache_manager.invalidate(lowered_name);
return Poll::Ready(Ok(None));
}
LoadResponse::Data {
Expand Down Expand Up @@ -658,7 +658,7 @@ impl Summaries {
// Once we have our `cache_bytes` which represents the `Summaries` we're
// about to return, write that back out to disk so future Cargo
// invocations can use it.
cache_manager.put(name, &cache_bytes);
cache_manager.put(lowered_name, &cache_bytes);

// If we've got debug assertions enabled read back in the cached values
// and assert they match the expected result.
Expand Down

0 comments on commit eff4cae

Please # to comment.