Skip to content

Commit

Permalink
fix: use fs::canonicalize to cover symlink edge cases
Browse files Browse the repository at this point in the history
fixes #263
  • Loading branch information
Boshen committed Oct 22, 2024
1 parent ee87dbc commit 5455a98
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl FileSystem for FileSystemOs {
}
} else if #[cfg(windows)] {
dunce::canonicalize(path)
} else {
} else if #[cfg(target_family = "wasm")] {
use std::path::Component;
let mut path_buf = path.to_path_buf();
loop {
Expand All @@ -184,15 +184,8 @@ impl FileSystem for FileSystemOs {
path_buf.pop();
}
Component::Normal(seg) => {
#[cfg(target_family = "wasm")]
// Need to trim the extra \0 introduces by https://github.com/nodejs/uvwasi/issues/262
{
path_buf.push(seg.to_string_lossy().trim_end_matches('\0'));
}
#[cfg(not(target_family = "wasm"))]
{
path_buf.push(seg);
}
path_buf.push(seg.to_string_lossy().trim_end_matches('\0'));
}
Component::RootDir => {
path_buf = PathBuf::from("/");
Expand All @@ -205,6 +198,8 @@ impl FileSystem for FileSystemOs {
}
}
Ok(path_buf)
} else {
fs::canonicalize(path)
}
}
}
Expand Down

0 comments on commit 5455a98

Please # to comment.