Skip to content

Commit

Permalink
🩹 Do not use system tmp dir for website trash
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiBardon committed May 25, 2024
1 parent 089665a commit 8aa2fbf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/helpers/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, env::VarError> = env::var("MODE");
pub static ref KEYS_MODE: Result<String, env::VarError> = env::var("KEYS_MODE");
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static DATA_FILES_GENERATED: AtomicBool = AtomicBool::new(false);
lazy_static! {
// NOTE: `Arc` prevents race conditions
static ref GENERATED_WEBSITES: Arc<Mutex<HashSet<PathBuf>>> = 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> {
Expand Down Expand Up @@ -350,7 +350,7 @@ pub fn trash_outdated_websites() -> Result<State, Error> {
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 {
Expand All @@ -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);
Expand All @@ -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(())
}
Expand Down

0 comments on commit 8aa2fbf

Please sign in to comment.