Skip to content

Commit 9b4e37b

Browse files
committed
Make sure to only search for whole path components
1 parent f424021 commit 9b4e37b

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

crates/brush-dataset/src/formats/colmap.rs

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ use std::collections::HashMap;
2222
fn find_mask_and_img(vfs: &BrushVfs, name: &str) -> Option<(PathBuf, Option<PathBuf>)> {
2323
// Colmap only specifies an image name, not a full path. We brute force
2424
// 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+
2530
let paths: Vec<_> = vfs.files_ending_in(name).collect();
2631

2732
let mut path_masks = HashMap::new();

crates/brush-vfs/src/lib.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,18 @@ struct PathKey(String);
5454

5555
impl PathKey {
5656
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)
6369
}
6470
}
6571

@@ -250,11 +256,12 @@ impl BrushVfs {
250256
}
251257

252258
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())
258265
}
259266

260267
pub fn files_with_stem<'a>(&'a self, filestem: &'a str) -> impl Iterator<Item = PathBuf> + 'a {

0 commit comments

Comments
 (0)