wgui: parser: normalize paths in <include>s, (fix rust-embed file not found in release build)
This commit is contained in:
@@ -1,3 +1,22 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub trait AssetProvider {
|
||||
fn load_from_path(&mut self, path: &str) -> anyhow::Result<Vec<u8>>;
|
||||
}
|
||||
|
||||
// replace "./foo/bar/../file.txt" with "./foo/file.txt"
|
||||
pub fn normalize_path(path: &Path) -> PathBuf {
|
||||
let mut stack = Vec::new();
|
||||
for component in path.components() {
|
||||
match component {
|
||||
std::path::Component::ParentDir => {
|
||||
stack.pop();
|
||||
}
|
||||
std::path::Component::Normal(name) => {
|
||||
stack.push(name);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
stack.iter().collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user