Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use fs::canonicalize to cover symlink edge cases #284

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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