@@ -34,7 +34,6 @@ use std::collections::{BTreeMap, HashMap, HashSet};
34
34
use std:: fmt:: Debug ;
35
35
use std:: hash:: Hash ;
36
36
use std:: os:: unix:: ffi:: OsStrExt ;
37
- use std:: path;
38
37
use std:: path:: Path ;
39
38
use std:: rc:: Rc ;
40
39
@@ -259,22 +258,20 @@ impl OptionParser {
259
258
} ;
260
259
261
260
fn path_join ( prefix : & str , suffix : & str ) -> String {
262
- if prefix. ends_with ( path:: MAIN_SEPARATOR ) {
263
- format ! ( "{}{}" , prefix, suffix)
264
- } else {
265
- format ! ( "{}{}{}" , prefix, path:: MAIN_SEPARATOR , suffix)
266
- }
261
+ // TODO: The calling code should traffic in Path, or OsString, not String.
262
+ // For now we assume the paths are valid UTF8 strings, via unwrap().
263
+ Path :: new ( prefix) . join ( suffix) . to_str ( ) . unwrap ( ) . to_string ( )
267
264
}
268
265
269
266
fn path_strip ( prefix : & str , path : & str ) -> String {
270
- match path . strip_prefix ( prefix ) {
271
- Some ( suffix ) => match suffix . strip_prefix ( path :: MAIN_SEPARATOR ) {
272
- Some ( suffix_suffix ) => suffix_suffix ,
273
- _ => suffix ,
274
- } ,
275
- _ => path ,
276
- }
277
- . to_string ( )
267
+ // TODO: The calling code should traffic in Path, or OsString, not String.
268
+ // For now we assume the paths are valid UTF8 strings, via unwrap().
269
+ Path :: new ( path )
270
+ . strip_prefix ( prefix )
271
+ . unwrap ( )
272
+ . to_str ( )
273
+ . unwrap ( )
274
+ . to_string ( )
278
275
}
279
276
280
277
let repo_config_files = match config_paths {
@@ -316,7 +313,7 @@ impl OptionParser {
316
313
ordinal,
317
314
path : path_strip ( & buildroot_string, path) ,
318
315
} ,
319
- Rc :: new ( config. clone ( ) ) ,
316
+ Rc :: new ( config) ,
320
317
) ;
321
318
ordinal += 1 ;
322
319
}
0 commit comments