Skip to content

Commit

Permalink
fix: handle "." in path lookup (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun authored May 1, 2024
1 parent 861233d commit e8786f5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Binary file modified lib/virtual_adapter.debug.wasm
Binary file not shown.
Binary file modified lib/virtual_adapter.wasm
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/cases/fs-preopen-read.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
component = "file-read"

host-fs-path = "/mydir"

[virt-opts.stdio]
stdin = "allow"
stdout = "allow"
stderr = "allow"

[virt-opts.fs.preopens."/mydir".dir]
"file1.txt" = { source = "inner contents1" }
"file2.txt" = { source = "inner contents2" }
"echo.txt" = { source = "inner contents echo" }

[expect]
file-read = "echo.txtfile1.txtfile2.txt"
10 changes: 8 additions & 2 deletions virtual-adapter/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,17 @@ impl StaticIndexEntry {
let static_index = Io::static_index();
Ok(&static_index[self.idx() + child_offset..self.idx() + child_offset + child_list_len])
}
fn dir_lookup(&self, path: &str) -> Result<&'static StaticIndexEntry, ErrorCode> {
fn dir_lookup(&self, path: &str) -> Result<&StaticIndexEntry, ErrorCode> {
assert!(path.len() > 0);
let (first_part, rem) = match path.find('/') {
Some(idx) => (&path[0..idx], &path[idx + 1..]),
None => (path, ""),
None => {
if path == "." {
return Ok(self);
} else {
(path, "")
}
}
};
let child_list = self.child_list()?;
if let Ok(child_idx) = child_list.binary_search_by(|entry| entry.name().cmp(first_part)) {
Expand Down

0 comments on commit e8786f5

Please sign in to comment.