From 8aa2fbf734555bb9bd5e0e606a9229b855d9dae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bardon?= Date: Sat, 25 May 2024 15:29:16 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Do=20not=20use=20system=20tmp=20?= =?UTF-8?q?dir=20for=20website=20trash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/src/config.rs | 1 + src/helpers/src/generate.rs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/helpers/src/config.rs b/src/helpers/src/config.rs index 0d23983..782f3a2 100644 --- a/src/helpers/src/config.rs +++ b/src/helpers/src/config.rs @@ -17,6 +17,7 @@ lazy_static! { pub static ref WEBSITE_REPOSITORY: String = env::var("WEBSITE_REPOSITORY") .expect("Environment variable `WEBSITE_REPOSITORY` is required."); pub static ref BASE_DIR: PathBuf = WORK_DIR.join(".orangutan"); + pub static ref TMP_DIR: PathBuf = BASE_DIR.join("tmp"); pub static ref KEYS_DIR: PathBuf = BASE_DIR.join("keys"); pub static ref MODE: Result = env::var("MODE"); pub static ref KEYS_MODE: Result = env::var("KEYS_MODE"); diff --git a/src/helpers/src/generate.rs b/src/helpers/src/generate.rs index c663590..8408b14 100644 --- a/src/helpers/src/generate.rs +++ b/src/helpers/src/generate.rs @@ -21,7 +21,7 @@ static DATA_FILES_GENERATED: AtomicBool = AtomicBool::new(false); lazy_static! { // NOTE: `Arc` prevents race conditions static ref GENERATED_WEBSITES: Arc>> = Arc::new(Mutex::new(HashSet::new())); - static ref TMP_DIR: PathBuf = std::env::temp_dir().join("orangutan-save"); + static ref TRASH_DIR: PathBuf = TMP_DIR.join("trash"); } pub fn generate_default_website() -> Result<(), Error> { @@ -350,7 +350,7 @@ pub fn trash_outdated_websites() -> Result { trace!("Trashing outdated websites…"); // Remove outdated websites - fs::rename(DEST_DIR.as_path(), TMP_DIR.as_path()).map_err(Error::IOError)?; + fs::rename(DEST_DIR.as_path(), TRASH_DIR.as_path()).map_err(Error::IOError)?; // Save caches (in case we need to recover) let state = State { @@ -373,7 +373,7 @@ pub fn recover_trash(state: State) -> Result<(), Error> { trace!("Recovering trash…"); // Reload files - fs::rename(TMP_DIR.as_path(), DEST_DIR.as_path()).map_err(Error::IOError)?; + fs::rename(TRASH_DIR.as_path(), DEST_DIR.as_path()).map_err(Error::IOError)?; // Relaod caches HUGO_CONFIG_GENERATED.store(state.hugo_config_generated, Ordering::Relaxed); @@ -388,7 +388,7 @@ pub fn recover_trash(state: State) -> Result<(), Error> { pub fn empty_trash(_state: State) -> Result<(), Error> { trace!("Emptying trash…"); - fs::remove_dir_all(TMP_DIR.as_path()).map_err(Error::IOError)?; + fs::remove_dir_all(TRASH_DIR.as_path()).map_err(Error::IOError)?; Ok(()) }