From 8927b4b162e2d3b24f460fba8eea9be6537ed744 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Mon, 7 Aug 2023 22:28:35 +0800 Subject: [PATCH] refactor: avoid hard coding tmp dir --- adaptor/src/image.rs | 7 ++++--- config/src/manager/manager.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/adaptor/src/image.rs b/adaptor/src/image.rs index 862fed2b..d9a66a31 100644 --- a/adaptor/src/image.rs +++ b/adaptor/src/image.rs @@ -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())) } } diff --git a/config/src/manager/manager.rs b/config/src/manager/manager.rs index 64c83603..49440da9 100644 --- a/config/src/manager/manager.rs +++ b/config/src/manager/manager.rs @@ -30,7 +30,7 @@ impl Manager { let mut manager = toml::from_str::(&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(); }