@@ -8,6 +8,7 @@ use percent_encoding::{percent_decode_str, utf8_percent_encode, NON_ALPHANUMERIC
8
8
use rustwide:: Crate as RustwideCrate ;
9
9
use std:: convert:: TryFrom ;
10
10
use std:: fmt;
11
+ use std:: path:: Path ;
11
12
use std:: str:: FromStr ;
12
13
13
14
pub ( crate ) use crate :: crates:: sources:: github:: GitHubRepo ;
@@ -24,6 +25,7 @@ pub enum Crate {
24
25
Registry ( RegistryCrate ) ,
25
26
GitHub ( GitHubRepo ) ,
26
27
Local ( String ) ,
28
+ Path ( String ) ,
27
29
Git ( GitRepo ) ,
28
30
}
29
31
@@ -39,6 +41,9 @@ impl Crate {
39
41
}
40
42
}
41
43
Crate :: Local ( ref name) => format ! ( "local/{}" , name) ,
44
+ Crate :: Path ( ref path) => {
45
+ format ! ( "path/{}" , utf8_percent_encode( & path, & NON_ALPHANUMERIC ) )
46
+ }
42
47
Crate :: Git ( ref repo) => {
43
48
if let Some ( ref sha) = repo. sha {
44
49
format ! (
@@ -60,6 +65,7 @@ impl Crate {
60
65
RustwideCrate :: git ( & format ! ( "https://github.com/{}/{}" , repo. org, repo. name) )
61
66
}
62
67
Self :: Local ( name) => RustwideCrate :: local ( & LOCAL_CRATES_DIR . join ( name) ) ,
68
+ Self :: Path ( path) => RustwideCrate :: local ( Path :: new ( & path) ) ,
63
69
Self :: Git ( repo) => RustwideCrate :: git ( & repo. url ) ,
64
70
}
65
71
}
@@ -85,7 +91,7 @@ impl TryFrom<&'_ PackageId> for Crate {
85
91
name : name. to_string ( ) ,
86
92
version : version. to_string ( ) ,
87
93
} ) ) ,
88
- [ name , _, "path" , _ ] => Ok ( Crate :: Local ( name . to_string ( ) ) ) ,
94
+ [ _ , _, "path" , path ] => Ok ( Crate :: Path ( path . to_string ( ) ) ) ,
89
95
[ _, _, "git" , repo] => {
90
96
if repo. starts_with ( "https://github.com" ) {
91
97
Ok ( Crate :: GitHub ( repo. replace ( "#" , "/" ) . parse ( ) ?) )
@@ -131,6 +137,8 @@ impl fmt::Display for Crate {
131
137
format!( "{}/{}" , repo. org, repo. name)
132
138
} ,
133
139
Crate :: Local ( ref name) => format!( "{} (local)" , name) ,
140
+ Crate :: Path ( ref path) =>
141
+ format!( "{}" , utf8_percent_encode( path, & NON_ALPHANUMERIC ) ) ,
134
142
Crate :: Git ( ref repo) =>
135
143
if let Some ( ref sha) = repo. sha {
136
144
format!(
@@ -175,6 +183,9 @@ impl FromStr for Crate {
175
183
sha : None ,
176
184
} ) ) ,
177
185
[ "local" , name] => Ok ( Crate :: Local ( name. to_string ( ) ) ) ,
186
+ [ "path" , path] => Ok ( Crate :: Path (
187
+ percent_decode_str ( path) . decode_utf8 ( ) ?. to_string ( ) ,
188
+ ) ) ,
178
189
_ => bail ! ( "unexpected crate value" ) ,
179
190
}
180
191
}
@@ -203,7 +214,7 @@ mod tests {
203
214
#[ test]
204
215
fn test_parse_from_pkgid ( ) {
205
216
test_from_pkgid ! {
206
- "dummy 0.1.0 (path+file:///opt/rustwide/workdir)" => Crate :: Local ( "dummy ". to_string( ) ) ,
217
+ "dummy 0.1.0 (path+file:///opt/rustwide/workdir)" => Crate :: Path ( "file:///opt/rustwide/workdir ". to_string( ) ) ,
207
218
"dummy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" => Crate :: Registry ( RegistryCrate {
208
219
name: "dummy" . to_string( ) ,
209
220
version: "0.1.0" . to_string( )
@@ -270,6 +281,8 @@ mod tests {
270
281
271
282
test_from_str ! {
272
283
"local/build-fail" => Crate :: Local ( "build-fail" . to_string( ) ) ,
284
+ "path/pathtofile" => Crate :: Path ( "pathtofile" . to_string( ) ) ,
285
+ & format!( "path/{}" , utf8_percent_encode( "path/with:stange?characters" , & NON_ALPHANUMERIC ) ) => Crate :: Path ( "path/with:stange?characters" . to_string( ) ) ,
273
286
"gh/org/user" => Crate :: GitHub ( GitHubRepo { org: "org" . to_string( ) , name: "user" . to_string( ) , sha: None } ) ,
274
287
"gh/org/user/sha" => Crate :: GitHub ( GitHubRepo { org: "org" . to_string( ) , name: "user" . to_string( ) , sha: Some ( "sha" . to_string( ) ) } ) ,
275
288
"git/url" => Crate :: Git ( GitRepo { url: "url" . to_string( ) , sha: None } ) ,
0 commit comments