refactor: avoid hard coding tmp dir

This commit is contained in:
Pig Fang 2023-08-07 22:28:35 +08:00
parent 2ac51faa93
commit 8927b4b162
No known key found for this signature in database
GPG key ID: A8198F548DADA9E2
2 changed files with 5 additions and 4 deletions

View file

@ -1,4 +1,4 @@
use std::{path::{Path, PathBuf}, sync::Arc};
use std::{env, path::{Path, PathBuf}, sync::Arc};
use anyhow::Result;
use config::PREVIEW;
@ -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()
env::temp_dir()
.join("yazi")
.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();
}