From 6ce6ecc26ddbc1ce39721f16d72fee3f24f054b3 Mon Sep 17 00:00:00 2001 From: Berke Enercan Date: Wed, 14 Dec 2022 11:18:19 +0300 Subject: [PATCH] fix: don't auto create config directory unless generating instances file --- CHANGELOG.md | 1 + src/config/options.rs | 2 +- src/utils.rs | 10 +++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d4b2b4..00f4581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - No longer crashes if no tag is selected when trying to modify channels of a tag. - Reload channels when a tag is deleted. +- Don't automatically create config directory unless generating instances file. ## [0.3.1] - 2022-10-16 ### Fixed diff --git a/src/config/options.rs b/src/config/options.rs index 2f2558f..46c5a34 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -37,7 +37,7 @@ impl Options { self.tick_rate = *tick_rate; } - if let Some(request_timeout) = CLAP_ARGS.get_one::("instances") { + if let Some(request_timeout) = CLAP_ARGS.get_one::("request_timeout") { self.request_timeout = *request_timeout; } diff --git a/src/utils.rs b/src/utils.rs index 407feaf..1033a1b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -16,9 +16,7 @@ pub fn get_config_dir() -> Result { Some(path) => path.join(PACKAGE_NAME), None => bail!("Couldn't find config directory"), }; - if !path.exists() { - std::fs::create_dir_all(&path)?; - } + Ok(path) } @@ -59,6 +57,12 @@ pub fn get_default_instances_file() -> Result { pub fn generate_instances_file() -> Result<()> { let instances = fetch_invidious_instances()?; let instances_file_path = &CONFIG.options.instances; + let instances_dir = instances_file_path.parent().unwrap(); + + if !instances_dir.exists() { + std::fs::create_dir_all(instances_dir)?; + } + let mut file = File::create(instances_file_path.as_path())?; println!( "Generated \"{}\" with the following instances:",