Repository: dathere/qsv (language: rust)

Issue:
BUG: qsv cat no longer reads STDIN
given a trivial ids.csv file of

```
id
1
2
```

`qsv cat columns ids.csv ids.csv` works as expected, but `cat ids.csv | qsv cat columns - ids.csv` no longer works, giving the error "Input file '-' does not exist"

This worked in 0.129


Discussion / hints:

Fix patch:
diff --git a/src/util.rs b/src/util.rs
index 8bfa283e0..9b1e9f95a 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1560,27 +1560,12 @@ pub fn isutf8_file(path: &Path) -> Result<bool, CliError> {
 /// If the input is a file, add the file to the input.
 /// If the input are snappy compressed files, uncompress them before adding them to the input.
 pub fn process_input(
-    mut arg_input: Vec<PathBuf>,
+    arg_input: Vec<PathBuf>,
     tmpdir: &tempfile::TempDir,
     custom_empty_stdin_errmsg: &str,
 ) -> Result<Vec<PathBuf>, CliError> {
     let mut processed_input = Vec::with_capacity(arg_input.len());
 
-    // if the input is empty or "-", its stdin. try to copy stdin to a file named
-    // "stdin" in the passed temp directory
-    if arg_input.len() == 1 && arg_input[0] == PathBuf::from("-") {
-        // its "-", remove the "-" from the input so its empty
-        arg_input.remove(0);
-    }
-    if arg_input.is_empty() {
-        // copy stdin to a file named stdin in a temp directory
-        let tmp_filename = tmpdir.path().join("stdin");
-        let mut tmp_file = std::fs::File::create(&tmp_filename)?;
-        std::io::copy(&mut std::io::stdin(), &mut tmp_file)?;
-        tmp_file.flush()?;
-        processed_input.push(tmp_filename);
-    }
-
     let work_input = if arg_input.len() == 1 {
         let input_path = &arg_input[0];
         if input_path.is_dir() {
@@ -1643,10 +1628,25 @@ pub fn process_input(
         arg_input
     };
 
+    let mut stdin_path = PathBuf::new();
+    let mut stdin_file_created = false;
+
     // check the input files
     for path in work_input {
-        // does the input file exist?
-        if !path.exists() {
+        // check if the path is "-" (stdin)
+        if path == PathBuf::from("-") {
+            if !stdin_file_created {
+                // if stdin was not copied to a file, copy stdin to a file named "stdin"
+                let tmp_filename = tmpdir.path().join("stdin");
+                let mut tmp_file = std::fs::File::create(&tmp_filename)?;
+                std::io::copy(&mut std::io::stdin(), &mut tmp_file)?;
+                tmp_file.flush()?;
+                stdin_file_created = true;
+                stdin_path = tmp_filename;
+            }
+            processed_input.push(stdin_path.clone());
+            continue;
+        } else if !path.exists() {
             return fail_clierror!("Input file '{}' does not exist", path.display());
         }
 


Test patch: