refactor: avoid hard coding tmp dir (#32)

This commit is contained in:
Pig Fang 2023-08-07 23:06:41 +08:00 committed by GitHub
parent 2ac51faa93
commit f274848dcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -1,7 +1,7 @@
use std::{path::{Path, PathBuf}, sync::Arc};
use anyhow::Result;
use config::PREVIEW;
use config::{MANAGER, PREVIEW};
use image::{imageops::FilterType, DynamicImage, ImageFormat};
use md5::{Digest, Md5};
use shared::tty_ratio;
@ -57,7 +57,8 @@ impl Image {
#[inline]
pub fn cache(path: &Path) -> PathBuf {
format!("/tmp/yazi/{:x}", Md5::new_with_prefix(path.to_string_lossy().as_bytes()).finalize())
.into()
MANAGER
.cache
.join(format!("{:x}", Md5::new_with_prefix(path.to_string_lossy().as_bytes()).finalize()))
}
}

View file

@ -30,7 +30,7 @@ impl Manager {
let mut manager = toml::from_str::<Outer>(&MERGED_YAZI).unwrap().manager;
manager.cwd = env::current_dir().unwrap_or("/".into());
manager.cache = "/tmp/yazi".into();
manager.cache = env::temp_dir().join("yazi");
if !manager.cache.is_dir() {
fs::create_dir(&manager.cache).unwrap();
}