1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(compile): improve panic message when stripping root path fails (#19258)

I'm not sure what's going on here, so this will help us debug.

For #19251
This commit is contained in:
David Sherret 2023-05-25 15:29:58 -04:00 committed by GitHub
parent 2ebd61ee1b
commit 2ddf85492f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)]