fixed moduleConfig.xml being case insesitive
This commit is contained in:
37
src/utils.rs
37
src/utils.rs
@@ -1,5 +1,6 @@
|
||||
use std::{
|
||||
fs::{self, DirEntry},
|
||||
io,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
@@ -29,3 +30,39 @@ pub fn walk_files_recursive(
|
||||
pub fn path_to_lowercase(path: impl AsRef<Path>) -> PathBuf {
|
||||
PathBuf::from(path.as_ref().to_string_lossy().to_lowercase())
|
||||
}
|
||||
|
||||
pub fn resolve_case_insensitive(
|
||||
base: impl AsRef<Path>,
|
||||
rel: impl AsRef<Path>,
|
||||
) -> io::Result<PathBuf> {
|
||||
let mut current = base.as_ref().to_path_buf();
|
||||
|
||||
for part in rel.as_ref().iter() {
|
||||
let target = part.to_string_lossy();
|
||||
|
||||
let mut found = None;
|
||||
|
||||
for entry in fs::read_dir(¤t)? {
|
||||
let entry = entry?;
|
||||
let name = entry.file_name();
|
||||
let name = name.to_string_lossy();
|
||||
|
||||
if name.eq_ignore_ascii_case(&target) {
|
||||
found = Some(entry.path());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
match found {
|
||||
Some(path) => current = path,
|
||||
None => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
format!("Path component not found: {}", target),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(current)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user