Skip to content

Commit f5ec77b

Browse files
committed
docs(utils): Clarify expected state of name for make_dep_path
For index entries, the caller must lowercase the name.
1 parent 258db04 commit f5ec77b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

crates/cargo-util/src/registry.rs

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
/// - [index from of Cargo's index on filesystem][1], and
44
/// - [index from Crates.io][2].
55
///
6+
/// <div class="warning">
7+
///
8+
/// Note: For index files, `dep_name` must have had `to_lowercase` called on it.
9+
///
10+
/// </div>
11+
///
612
/// [1]: https://docs.rs/cargo/latest/cargo/sources/registry/index.html#the-format-of-the-index
713
/// [2]: https://github.com/rust-lang/crates.io-index
814
pub fn make_dep_path(dep_name: &str, prefix_only: bool) -> String {

src/cargo/sources/registry/index/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -584,19 +584,19 @@ impl Summaries {
584584
) -> Poll<CargoResult<Option<Summaries>>> {
585585
// This is the file we're loading from cache or the index data.
586586
// See module comment in `registry/mod.rs` for why this is structured the way it is.
587-
let name = &name.to_lowercase();
588-
let relative = make_dep_path(&name, false);
587+
let lowered_name = &name.to_lowercase();
588+
let relative = make_dep_path(&lowered_name, false);
589589

590590
let mut cached_summaries = None;
591591
let mut index_version = None;
592-
if let Some(contents) = cache_manager.get(name) {
592+
if let Some(contents) = cache_manager.get(lowered_name) {
593593
match Summaries::parse_cache(contents) {
594594
Ok((s, v)) => {
595595
cached_summaries = Some(s);
596596
index_version = Some(v);
597597
}
598598
Err(e) => {
599-
tracing::debug!("failed to parse {name:?} cache: {e}");
599+
tracing::debug!("failed to parse {lowered_name:?} cache: {e}");
600600
}
601601
}
602602
}
@@ -609,7 +609,7 @@ impl Summaries {
609609
return Poll::Ready(Ok(cached_summaries));
610610
}
611611
LoadResponse::NotFound => {
612-
cache_manager.invalidate(name);
612+
cache_manager.invalidate(lowered_name);
613613
return Poll::Ready(Ok(None));
614614
}
615615
LoadResponse::Data {
@@ -658,7 +658,7 @@ impl Summaries {
658658
// Once we have our `cache_bytes` which represents the `Summaries` we're
659659
// about to return, write that back out to disk so future Cargo
660660
// invocations can use it.
661-
cache_manager.put(name, &cache_bytes);
661+
cache_manager.put(lowered_name, &cache_bytes);
662662

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

0 commit comments

Comments
 (0)