From fcbcd175e16f5fd97677909a866441b58fd8aa1e Mon Sep 17 00:00:00 2001 From: ByteDream Date: Sun, 9 Apr 2023 14:22:43 +0200 Subject: [PATCH] Add env variable to make temp directory configurable (#153) --- crunchy-cli-core/src/utils/os.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crunchy-cli-core/src/utils/os.rs b/crunchy-cli-core/src/utils/os.rs index 43a37d4..f33fee2 100644 --- a/crunchy-cli-core/src/utils/os.rs +++ b/crunchy-cli-core/src/utils/os.rs @@ -24,10 +24,12 @@ pub fn has_ffmpeg() -> bool { /// e.g. remove them in a case of ctrl-c. Having one function also good to prevent mistakes like /// setting the wrong prefix if done manually. pub fn tempfile>(suffix: S) -> io::Result { + let tmp_dir = env::var("CRUNCHY_CLI_TEMP_DIR").map_or(env::temp_dir(), |d| PathBuf::from(d)); + let tempfile = Builder::default() .prefix(".crunchy-cli_") .suffix(suffix.as_ref()) - .tempfile_in(&env::temp_dir())?; + .tempfile_in(tmp_dir)?; debug!( "Created temporary file: {}", tempfile.path().to_string_lossy()