diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-18 18:08:22 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-18 18:09:22 +0200 |
commit | 59608b3ee2473cc2d2b35b286168c932f0c78f2d (patch) | |
tree | 948f92078d9c7cbc95cce78c220b7b67c90302aa | |
parent | test(crates/yt/tests/_testenv::init): Use appropriate atomic u64 type (diff) | |
download | yt-59608b3ee2473cc2d2b35b286168c932f0c78f2d.zip |
fix(crates/yt/config): Ensure that the download_dir is created
Previously, we only ensured that for its parent directory.
-rw-r--r-- | crates/yt/src/config/mod.rs | 3 | ||||
-rw-r--r-- | crates/yt/src/config/paths.rs | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/crates/yt/src/config/mod.rs b/crates/yt/src/config/mod.rs index 52962ab..e02d5f5 100644 --- a/crates/yt/src/config/mod.rs +++ b/crates/yt/src/config/mod.rs @@ -28,6 +28,7 @@ mk_config! { use super::paths::get_runtime_path; use super::paths::get_data_path; use super::paths::ensure_parent_dir; + use super::paths::ensure_dir; use super::paths::PREFIX; struct Config { @@ -65,7 +66,7 @@ mk_config! { let temp_dir = std::env::temp_dir(); temp_dir.join(PREFIX) - } => ensure_parent_dir, + } => ensure_dir, /// Path to the mpv configuration file. mpv_config_path: PathBuf =? get_config_path("mpv.conf") => ensure_parent_dir, diff --git a/crates/yt/src/config/paths.rs b/crates/yt/src/config/paths.rs index 224891b..66975dd 100644 --- a/crates/yt/src/config/paths.rs +++ b/crates/yt/src/config/paths.rs @@ -42,6 +42,14 @@ pub(super) fn ensure_parent_dir(path: &Path) -> Result<()> { Ok(()) } +pub(super) fn ensure_dir(path: &Path) -> Result<()> { + if !path.exists() { + std::fs::create_dir_all(path) + .with_context(|| format!("Failed to create the '{}' directory", path.display()))?; + } + + Ok(()) +} pub(super) fn config_path() -> Result<PathBuf> { get_config_path("config.toml") |