summary history branches tags files
commit:33f0544953164fe80ec915e8c96bf9ecb7ac87b7
author:Trevor Bentley
committer:Trevor Bentley
date:Mon Jan 13 21:33:41 2025 +0100
parents:ba87c77822cb3344e9861ec8a7fed822ffec3f62
support overriding temp dir on command line
diff --git a/src/main.rs b/src/main.rs
line changes: +13/-2
index 6497443..8d3081f
--- a/src/main.rs
+++ b/src/main.rs
@@ -49,6 +49,10 @@ struct PwwArgs {
     #[arg(short = 'b', long)]
     identifier_bin: Option<PathBuf>,
 
+    /// Directory to store temporary files
+    #[arg(long)]
+    temp_dir: Option<PathBuf>,
+
     /// Do not actually write metadata to file, but print which files
     /// would have changed.
     #[arg(short = 'n', long)]
@@ -257,6 +261,13 @@ impl PwwConfig {
         }
     }
 
+    fn temp_dir(&self) -> Option<PathBuf> {
+        match &self.cli {
+            Some(c) => c.temp_dir.clone(),
+            _ => Default::default(),
+        }
+    }
+
     fn max_dimension(&self) -> u32 {
         match self.max_dimension {
             0 => std::u32::MAX,
@@ -352,7 +363,7 @@ fn exec_identifier<P: AsRef<Path>>(config: &PwwConfig, file_path: P) -> Result<S
     let res = p.wait()
         .map_err(|e| PwwError::Unknown(format!("Failed to wait for identifier binary: {}", e)))?;
     if !res.success() {
-        return Err(PwwError::Unknown("identifier binary failed to execute.".into()));
+        return Err(PwwError::Unknown("identifier binary exited with failure.".into()));
     }
     let mut s: String = String::new();
     let mut stdout = p.stdout.ok_or_else(|| PwwError::Unknown(format!("Failed to get output from identifier binary")))?;
@@ -616,7 +627,7 @@ fn process_image(config: &PwwConfig, input_path: &Path) -> Result<(), PwwError> 
             }
             let i = Image::<u8, image2::Rgb>::open(&input_path)
                 .map_err(|_e| PwwError::InvalidImage)?;
-            let temp_dir = config.temp_dir.clone()
+            let temp_dir = config.temp_dir().clone()
                 .unwrap_or(PathBuf::from(std::env::temp_dir()));
             tmpfile = Some(tempfile::Builder::new()
                            .prefix("pww-")