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 open_ambient_dir instead of fs::File::open to load folders #136

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions crates/runtimes/src/modules/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
fs,
path::{Path, PathBuf},
};
use wasmtime_wasi::{Dir, WasiCtxBuilder};
use wasmtime_wasi::{ambient_authority, Dir, WasiCtxBuilder};
use wws_runtimes_manager::metadata::Runtime as RuntimeMetadata;
use wws_store::Store;

Expand Down Expand Up @@ -90,10 +90,10 @@ impl Runtime for ExternalRuntime {
/// Mount the source code in the WASI context so it can be
/// processed by the engine
fn prepare_wasi_ctx(&self, builder: WasiCtxBuilder) -> Result<WasiCtxBuilder> {
let source = fs::File::open(&self.store.folder)?;
let dir = Dir::open_ambient_dir(&self.store.folder, ambient_authority())?;

Ok(builder
.preopened_dir(Dir::from_std_file(source), "/src")?
.preopened_dir(dir, "/src")?
.args(&self.metadata.args)?)
}

Expand Down
10 changes: 4 additions & 6 deletions crates/runtimes/src/modules/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

use crate::runtime::Runtime;
use anyhow::Result;
use std::path::Path;
use std::{fs, path::PathBuf};
use wasmtime_wasi::Dir;
use wasmtime_wasi::WasiCtxBuilder;
use std::path::{Path, PathBuf};
use wasmtime_wasi::{ambient_authority, Dir, WasiCtxBuilder};
use wws_store::Store;

static JS_ENGINE_WASM: &[u8] =
Expand Down Expand Up @@ -48,8 +46,8 @@ impl Runtime for JavaScriptRuntime {
/// Mount the source code in the WASI context so it can be
/// processed by the engine
fn prepare_wasi_ctx(&self, builder: WasiCtxBuilder) -> Result<WasiCtxBuilder> {
let source = fs::File::open(&self.store.folder)?;
Ok(builder.preopened_dir(Dir::from_std_file(source), "/src")?)
let dir = Dir::open_ambient_dir(&self.store.folder, ambient_authority())?;
Ok(builder.preopened_dir(dir, "/src")?)
}

/// Returns a reference to the Wasm module that should
Expand Down
7 changes: 3 additions & 4 deletions crates/worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::path::PathBuf;
use std::{collections::HashMap, path::Path};
use stdio::Stdio;
use wasmtime::{Engine, Linker, Module, Store};
use wasmtime_wasi::{Dir, WasiCtxBuilder};
use wasmtime_wasi::{ambient_authority, Dir, WasiCtxBuilder};
use wws_config::Config as ProjectConfig;
use wws_runtimes::{init_runtime, Runtime};

Expand Down Expand Up @@ -106,9 +106,8 @@ impl Worker {
if let Some(folders) = self.config.folders.as_ref() {
for folder in folders {
if let Some(base) = &self.path.parent() {
let source = fs::File::open(base.join(&folder.from))?;
wasi_builder =
wasi_builder.preopened_dir(Dir::from_std_file(source), &folder.to)?;
let dir = Dir::open_ambient_dir(base.join(&folder.from), ambient_authority())?;
wasi_builder = wasi_builder.preopened_dir(dir, &folder.to)?;
} else {
// TODO: Revisit error management on #73
return Err(anyhow!("The worker couldn't be initialized"));
Expand Down