Read WATCHEXEC_TMPDIR env

This commit is contained in:
Félix Saparelli 2024-04-20 23:21:42 +12:00
parent 51b18edb1c
commit 0d09f98bf5
No known key found for this signature in database
1 changed files with 9 additions and 1 deletions

View File

@ -1,4 +1,5 @@
use std::{
env::var_os,
io::Write,
path::PathBuf,
sync::{Arc, Mutex},
@ -18,7 +19,14 @@ pub struct RotatingTempFile(Arc<Mutex<Option<NamedTempFile>>>);
impl RotatingTempFile {
pub fn rotate(&self) -> Result<()> {
// implicitly drops the old file
*self.0.lock().unwrap() = Some(NamedTempFile::new().into_diagnostic()?);
*self.0.lock().unwrap() = Some(
if let Some(dir) = var_os("WATCHEXEC_TMPDIR") {
NamedTempFile::new_in(dir)
} else {
NamedTempFile::new()
}
.into_diagnostic()?,
);
Ok(())
}