Fix directory structure for crates with a name that's 3 characters long
Crates that have a name with 3 characters are not stores in `3/foo` like
the comment and code were saying but instead are stored in `3/f/foo` as
seen here: https://github.com/rust-lang/crates.io-index/tree/master/3
Before this commit, crates with a name that was 3 characters couldn't be
used by cargo as it couldn't find them.
Diff
src/util.rs | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
@@ -12,10 +12,11 @@
format!("SHA256:{}", fingerprint)
}
#[must_use]
pub fn get_crate_folder(crate_name: &str) -> ArrayVec<&'static str, 2> {
let mut folders = ArrayVec::new();
@@ -24,7 +25,10 @@
0 => {}
1 => folders.push("1"),
2 => folders.push("2"),
3 => folders.push("3"),
3 => {
folders.push("3");
folders.push(ustr(&crate_name[..1]).as_str());
}
_ => {
folders.push(ustr(&crate_name[..2]).as_str());
folders.push(ustr(&crate_name[2..4]).as_str());
@@ -84,5 +88,30 @@
impl Display for ArcOrCowStr {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&**self, f)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_crate_paths() {
let result = get_crate_folder("dfu");
let expected = ArrayVec::from(["3", "d"]);
assert_eq!(result, expected);
let result = get_crate_folder("df");
let mut expected = ArrayVec::new();
expected.push("2");
assert_eq!(result, expected);
let result = get_crate_folder("d");
let mut expected = ArrayVec::new();
expected.push("1");
assert_eq!(result, expected);
let result = get_crate_folder("longname");
let expected = ArrayVec::from(["lo", "ng"]);
assert_eq!(result, expected);
}
}