Skip to content

Commit f9e34dd

Browse files
authored
Merge pull request #104 from thomastaylor312/fix/ensure_path
fix(wkg): Ensures that the directory containing the config file exists
2 parents 00f974e + c566f5f commit f9e34dd

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resolver = "2"
44

55
[workspace.package]
66
edition = "2021"
7-
version = "0.7.0"
7+
version = "0.7.1"
88
authors = ["The Wasmtime Project Developers"]
99
license = "Apache-2.0 WITH LLVM-exception"
1010

@@ -36,9 +36,9 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features =
3636
"fmt",
3737
"env-filter",
3838
] }
39-
wasm-pkg-common = { version = "0.7.0", path = "crates/wasm-pkg-common" }
40-
wasm-pkg-client = { version = "0.7.0", path = "crates/wasm-pkg-client" }
39+
wasm-pkg-common = { version = "0.7.1", path = "crates/wasm-pkg-common" }
40+
wasm-pkg-client = { version = "0.7.1", path = "crates/wasm-pkg-client" }
4141
wasm-metadata = "0.217"
4242
wit-component = "0.217"
4343
wit-parser = "0.217"
44-
wasm-pkg-core = { version = "0.7.0", path = "crates/wasm-pkg-core" }
44+
wasm-pkg-core = { version = "0.7.1", path = "crates/wasm-pkg-core" }

crates/wkg/src/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ impl ConfigArgs {
122122
.ok_or(anyhow::anyhow!("global config path not available"))?
123123
};
124124

125+
// Check if the parent directory exists, if not create it
126+
if let Some(parent) = path.parent() {
127+
match tokio::fs::metadata(parent).await {
128+
Ok(metadata) => {
129+
if !metadata.is_dir() {
130+
anyhow::bail!("parent directory is not a directory");
131+
}
132+
}
133+
Err(e) => {
134+
if e.kind() == std::io::ErrorKind::NotFound {
135+
tokio::fs::create_dir_all(parent).await?;
136+
} else {
137+
anyhow::bail!("failed to check for config file directory: {}", e);
138+
}
139+
}
140+
}
141+
}
142+
125143
if self.edit {
126144
let editor = std::env::var("EDITOR").or(Err(anyhow::anyhow!(
127145
"failed to read `$EDITOR` environment variable"

0 commit comments

Comments
 (0)