summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/standalone/virtual_fs.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/cli/standalone/virtual_fs.rs b/cli/standalone/virtual_fs.rs
index 31f630db8..e94758bd9 100644
--- a/cli/standalone/virtual_fs.rs
+++ b/cli/standalone/virtual_fs.rs
@@ -84,7 +84,7 @@ impl VfsBuilder {
}
pub fn add_dir(&mut self, path: &Path) -> &mut VirtualDirectory {
- let path = path.strip_prefix(&self.root_path).unwrap();
+ let path = self.path_relative_root(path);
let mut current_dir = &mut self.root_dir;
for component in path.components() {
@@ -151,7 +151,7 @@ impl VfsBuilder {
}
pub fn add_symlink(&mut self, path: &Path, target: &Path) {
- let dest = target.strip_prefix(&self.root_path).unwrap().to_path_buf();
+ let dest = self.path_relative_root(target);
let dir = self.add_dir(path.parent().unwrap());
let name = path.file_name().unwrap().to_string_lossy();
match dir.entries.binary_search_by(|e| e.name().cmp(&name)) {
@@ -174,6 +174,20 @@ impl VfsBuilder {
pub fn into_dir_and_files(self) -> (VirtualDirectory, Vec<Vec<u8>>) {
(self.root_dir, self.files)
}
+
+ fn path_relative_root(&self, path: &Path) -> PathBuf {
+ match path.strip_prefix(&self.root_path) {
+ Ok(p) => p.to_path_buf(),
+ Err(err) => {
+ panic!(
+ "Failed to strip prefix '{}' from '{}': {:#}",
+ self.root_path.display(),
+ path.display(),
+ err
+ )
+ }
+ }
+ }
}
#[derive(Debug)]