@@ -12,10 +12,11 @@ pub fn format_fingerprint(fingerprint: &str) -> String {
12
12
format ! ( "SHA256:{}" , fingerprint)
13
13
}
14
14
15
- /// Crates with a total of 1, 2 or 3 characters in the same are written out to directories named
16
- /// 1, 2 or 3 respectively as per the cargo spec. Anything else we'll build out a normal tree for
17
- /// using the first four characters of the crate name, 2 for the first directory and the other 2
18
- /// for the second.
15
+ /// Crates with a total of 1, 2 characters in the same are written out to directories named
16
+ /// 1, 2 respectively as per the cargo spec. With a total of 3 characters they're stored in a
17
+ /// directory named 3 and then a subdirectory named after the first letter of the crate's name.
18
+ /// Anything else we'll build out a normal tree for using the first four characters of the crate
19
+ /// name, 2 for the first directory and the other 2 for the second.
19
20
#[ must_use]
20
21
pub fn get_crate_folder ( crate_name : & str ) -> ArrayVec < & ' static str , 2 > {
21
22
let mut folders = ArrayVec :: new ( ) ;
@@ -24,7 +25,10 @@ pub fn get_crate_folder(crate_name: &str) -> ArrayVec<&'static str, 2> {
24
25
0 => { }
25
26
1 => folders. push ( "1" ) ,
26
27
2 => folders. push ( "2" ) ,
27
- 3 => folders. push ( "3" ) ,
28
+ 3 => {
29
+ folders. push ( "3" ) ;
30
+ folders. push ( ustr ( & crate_name[ ..1 ] ) . as_str ( ) ) ;
31
+ }
28
32
_ => {
29
33
folders. push ( ustr ( & crate_name[ ..2 ] ) . as_str ( ) ) ;
30
34
folders. push ( ustr ( & crate_name[ 2 ..4 ] ) . as_str ( ) ) ;
@@ -86,3 +90,28 @@ impl Display for ArcOrCowStr {
86
90
std:: fmt:: Display :: fmt ( & * * self , f)
87
91
}
88
92
}
93
+
94
+ #[ cfg( test) ]
95
+ mod tests {
96
+ use super :: * ;
97
+
98
+ #[ test]
99
+ fn test_crate_paths ( ) {
100
+ let result = get_crate_folder ( "dfu" ) ;
101
+ let expected = ArrayVec :: from ( [ "3" , "d" ] ) ;
102
+ assert_eq ! ( result, expected) ;
103
+ let result = get_crate_folder ( "df" ) ;
104
+ let mut expected = ArrayVec :: new ( ) ;
105
+ expected. push ( "2" ) ;
106
+ assert_eq ! ( result, expected) ;
107
+
108
+ let result = get_crate_folder ( "d" ) ;
109
+ let mut expected = ArrayVec :: new ( ) ;
110
+ expected. push ( "1" ) ;
111
+ assert_eq ! ( result, expected) ;
112
+
113
+ let result = get_crate_folder ( "longname" ) ;
114
+ let expected = ArrayVec :: from ( [ "lo" , "ng" ] ) ;
115
+ assert_eq ! ( result, expected) ;
116
+ }
117
+ }
0 commit comments