diff --git a/crates/hyfetch/src/bin/hyfetch.rs b/crates/hyfetch/src/bin/hyfetch.rs index 3dbf17f9..eee6490f 100644 --- a/crates/hyfetch/src/bin/hyfetch.rs +++ b/crates/hyfetch/src/bin/hyfetch.rs @@ -118,8 +118,6 @@ fn main() -> Result<()> { .context("failed to write message to stdout")?; if !june_path.is_file() { - fs::create_dir_all(&cache_path) - .with_context(|| format!("failed to create cache dir {cache_path:?}"))?; File::create(&june_path) .with_context(|| format!("failed to create file {june_path:?}"))?; } diff --git a/crates/hyfetch/src/font_logo.rs b/crates/hyfetch/src/font_logo.rs index 5e293d2a..7fff409e 100644 --- a/crates/hyfetch/src/font_logo.rs +++ b/crates/hyfetch/src/font_logo.rs @@ -34,11 +34,6 @@ pub fn get_font_logo(backend: Backend) -> Result { let logo = font_logos.get(matched_distro).unwrap(); - // Create parent directories for the cache if they don't exist - if let Some(parent) = cache_path.parent() { - fs::create_dir_all(parent).context("Failed to create cache directory")?; - } - // Write the logo to the cache file let mut cache_file = File::create(cache_path).context("Failed to create cache file")?; cache_file.write_all(logo.as_bytes()).context("Failed to write logo to cache file")?; diff --git a/crates/hyfetch/src/utils.rs b/crates/hyfetch/src/utils.rs index f9b61f80..5c83b502 100644 --- a/crates/hyfetch/src/utils.rs +++ b/crates/hyfetch/src/utils.rs @@ -16,6 +16,12 @@ pub fn get_cache_path() -> Result { .context("failed to get base dirs")? .cache_dir() .to_owned(); + + // Make sure the cache directory exists + if !path.exists() { + fs::create_dir_all(&path).with_context(|| format!("failed to create cache dir {path:?}"))?; + } + Ok(path) }