manuel-woelker / rust-vfs

A virtual filesystem for Rust
Apache License 2.0
384 stars 44 forks source link

EmbeddedFS File Not Found #61

Closed agieocean closed 10 months ago

agieocean commented 10 months ago

My code compiles properly but it seems like there is some sort of issue with rust-embed as the fs says file not found when compiled with wasm-pack

I am on the latest version of this repo and using rust-embed 8.0.0 to match this repos requirements.

Here's the relevant code:

#[derive(RustEmbed)]
#[derive(Debug)]
#[folder = "./templates"]
struct EmbedFFS;
let EFS: VfsPath = EmbeddedFS::<EmbedFFS>::new().into();
let im: VfsPath = EFS.join("templates").unwrap();

When I call: im.is_dir().unwrap() I get false

Could this be a build issue? Im running this to build: wasm-pack build --target web --release

manuel-woelker commented 10 months ago

Hi, I haven't looked into it too deeply, but here's what I think might be happening:

The folder ./templates is "mounted" as the root of the embedded EFS. When joining "templates" to that path, the path im actually resolves to what is ./templates/templates (on the host OS). Can you verify if that is the case? (i.e. EFS should already point to the directory ./templates) If that is not the issue, you could maybe try to reproduce the issue by extending the testcases in src/impl/embedded.rs.

The following line is where this is tested, and seems to work: https://github.com/manuel-woelker/rust-vfs/blob/master/src/impls/embedded.rs#L357

agieocean commented 10 months ago

Ah yeah that was is it does seem to be starting in templates, thank you again!