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 f3a274f
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions lib/package/src/convert/webc_to_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,36 @@ 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() {
for (atom_name, data) in atoms {
let atom_path = module_dir.join(&atom_name);

std::fs::create_dir_all(&module_dir).map_err(|err| {
ConversionError::with_cause(
format!("Could not create directory '{}'", module_dir.display(),),
err,
)
})?;
std::fs::create_dir_all(&module_dir).map_err(|err| {
ConversionError::with_cause(
format!("Could not create directory '{}'", module_dir.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,
)
})?;
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 f3a274f

Please sign in to comment.