[F] Fix cache path might be missing

This commit is contained in:
Azalea Gui 2025-08-21 10:05:02 -04:00
parent cf6b77a1b7
commit afa3c1dfb9
3 changed files with 6 additions and 7 deletions

View file

@ -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:?}"))?;
}

View file

@ -34,11 +34,6 @@ pub fn get_font_logo(backend: Backend) -> Result<String> {
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")?;

View file

@ -16,6 +16,12 @@ pub fn get_cache_path() -> Result<PathBuf> {
.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)
}