about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--crates/yt/src/config/mod.rs3
-rw-r--r--crates/yt/src/config/paths.rs8
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")