From 59608b3ee2473cc2d2b35b286168c932f0c78f2d Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 18 Jul 2025 18:08:22 +0200 Subject: fix(crates/yt/config): Ensure that the download_dir is created Previously, we only ensured that for its parent directory. --- crates/yt/src/config/mod.rs | 3 ++- crates/yt/src/config/paths.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 { get_config_path("config.toml") -- cgit 1.4.1