Skip to content

Commit

Permalink
Merge pull request #104 from thomastaylor312/fix/ensure_path
Browse files Browse the repository at this point in the history
fix(wkg): Ensures that the directory containing the config file exists
  • Loading branch information
calvinrp authored Oct 2, 2024
2 parents 00f974e + c566f5f commit f9e34dd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"

[workspace.package]
edition = "2021"
version = "0.7.0"
version = "0.7.1"
authors = ["The Wasmtime Project Developers"]
license = "Apache-2.0 WITH LLVM-exception"

Expand Down Expand Up @@ -36,9 +36,9 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features =
"fmt",
"env-filter",
] }
wasm-pkg-common = { version = "0.7.0", path = "crates/wasm-pkg-common" }
wasm-pkg-client = { version = "0.7.0", path = "crates/wasm-pkg-client" }
wasm-pkg-common = { version = "0.7.1", path = "crates/wasm-pkg-common" }
wasm-pkg-client = { version = "0.7.1", path = "crates/wasm-pkg-client" }
wasm-metadata = "0.217"
wit-component = "0.217"
wit-parser = "0.217"
wasm-pkg-core = { version = "0.7.0", path = "crates/wasm-pkg-core" }
wasm-pkg-core = { version = "0.7.1", path = "crates/wasm-pkg-core" }
18 changes: 18 additions & 0 deletions crates/wkg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ impl ConfigArgs {
.ok_or(anyhow::anyhow!("global config path not available"))?
};

// Check if the parent directory exists, if not create it
if let Some(parent) = path.parent() {
match tokio::fs::metadata(parent).await {
Ok(metadata) => {
if !metadata.is_dir() {
anyhow::bail!("parent directory is not a directory");
}
}
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
tokio::fs::create_dir_all(parent).await?;
} else {
anyhow::bail!("failed to check for config file directory: {}", e);
}
}
}
}

if self.edit {
let editor = std::env::var("EDITOR").or(Err(anyhow::anyhow!(
"failed to read `$EDITOR` environment variable"
Expand Down

0 comments on commit f9e34dd

Please sign in to comment.