File tree 2 files changed +23
-11
lines changed
brush-dataset/src/formats
2 files changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ use std::collections::HashMap;
22
22
fn find_mask_and_img ( vfs : & BrushVfs , name : & str ) -> Option < ( PathBuf , Option < PathBuf > ) > {
23
23
// Colmap only specifies an image name, not a full path. We brute force
24
24
// search for the image in the archive.
25
+ //
26
+ // Make sure this path doesn't start with a '/' as the files_ending_in expects
27
+ // things in that format (like a "filename with slashes").
28
+ let name = name. strip_prefix ( '/' ) . unwrap_or ( name) ;
29
+
25
30
let paths: Vec < _ > = vfs. files_ending_in ( name) . collect ( ) ;
26
31
27
32
let mut path_masks = HashMap :: new ( ) ;
Original file line number Diff line number Diff line change @@ -54,12 +54,18 @@ struct PathKey(String);
54
54
55
55
impl PathKey {
56
56
fn from_path ( path : & Path ) -> Self {
57
- Self (
58
- path. clean ( )
59
- . to_str ( )
60
- . expect ( "Path is not valid ascii" )
61
- . to_lowercase ( ) ,
62
- )
57
+ let key = path
58
+ . clean ( )
59
+ . to_str ( )
60
+ . expect ( "Path is not valid ascii" )
61
+ . to_lowercase ( )
62
+ . replace ( '\\' , "/" ) ;
63
+ let key = if key. starts_with ( '/' ) {
64
+ key
65
+ } else {
66
+ '/' . to_string ( ) + & key
67
+ } ;
68
+ Self ( key)
63
69
}
64
70
}
65
71
@@ -250,11 +256,12 @@ impl BrushVfs {
250
256
}
251
257
252
258
pub fn files_ending_in < ' a > ( & ' a self , end_path : & ' a str ) -> impl Iterator < Item = PathBuf > + ' a {
253
- let end_path = end_path. to_lowercase ( ) . replace ( '\\' , "/" ) ;
254
- self . lookup . values ( ) . filter_map ( move |path| {
255
- let full_path = path. to_str ( ) ?. to_lowercase ( ) . replace ( '\\' , "/" ) ;
256
- full_path. ends_with ( & end_path) . then ( || path. clone ( ) )
257
- } )
259
+ let end_keyed = PathKey :: from_path ( Path :: new ( end_path) ) . 0 ;
260
+
261
+ self . lookup
262
+ . iter ( )
263
+ . filter ( move |kv| kv. 0 . 0 . ends_with ( & end_keyed) )
264
+ . map ( |kv| kv. 1 . clone ( ) )
258
265
}
259
266
260
267
pub fn files_with_stem < ' a > ( & ' a self , filestem : & ' a str ) -> impl Iterator < Item = PathBuf > + ' a {
You can’t perform that action at this time.
0 commit comments