From 0d09f98bf5d47fa2c5d6e73255438d6641ade30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 20 Apr 2024 23:21:42 +1200 Subject: [PATCH] Read WATCHEXEC_TMPDIR env --- crates/cli/src/state.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/state.rs b/crates/cli/src/state.rs index 5a56c1b..b23634a 100644 --- a/crates/cli/src/state.rs +++ b/crates/cli/src/state.rs @@ -1,4 +1,5 @@ use std::{ + env::var_os, io::Write, path::PathBuf, sync::{Arc, Mutex}, @@ -18,7 +19,14 @@ pub struct RotatingTempFile(Arc>>); 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(()) }