Skip to content

Commit

Permalink
chore: Prevent create_dir_all in a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
theduke committed Sep 16, 2024
1 parent 5cae10d commit 1336783
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lib/package/src/convert/webc_to_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,35 @@ pub fn webc_to_package_dir(
let module_dir_name = "modules";
let module_dir = target_dir.join(module_dir_name);

for (atom_name, data) in webc.atoms() {
let atom_path = module_dir.join(&atom_name);

let atoms = webc.atoms();
if !atoms.is_empty() {
std::fs::create_dir_all(&module_dir).map_err(|err| {
ConversionError::with_cause(
format!("Could not create directory '{}'", module_dir.display(),),
err,
)
})?;
for (atom_name, data) in atoms {
let atom_path = module_dir.join(&atom_name);

std::fs::write(&atom_path, &data).map_err(|err| {
ConversionError::with_cause(
format!("Could not write atom to path '{}'", atom_path.display()),
err,
)
})?;
std::fs::write(&atom_path, &data).map_err(|err| {
ConversionError::with_cause(
format!("Could not write atom to path '{}'", atom_path.display()),
err,
)
})?;

let relative_path = format!("./{module_dir_name}/{atom_name}");
let relative_path = format!("./{module_dir_name}/{atom_name}");

pkg_manifest.modules.push(wasmer_config::package::Module {
name: atom_name,
source: relative_path.into(),
abi: wasmer_config::package::Abi::None,
kind: None,
interfaces: None,
bindings: None,
});
pkg_manifest.modules.push(wasmer_config::package::Module {
name: atom_name,
source: relative_path.into(),
abi: wasmer_config::package::Abi::None,
kind: None,
interfaces: None,
bindings: None,
});
}
}

// Convert commands.
Expand Down

0 comments on commit 1336783

Please sign in to comment.