mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Fix output to special file (pipes etc.)
This commit is contained in:
parent
c37e2495e1
commit
14f42833cb
3 changed files with 38 additions and 11 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use log::debug;
|
||||
use std::io::ErrorKind;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::{env, io};
|
||||
use tempfile::{Builder, NamedTempFile};
|
||||
|
|
@ -37,9 +37,8 @@ pub fn tempfile<S: AsRef<str>>(suffix: S) -> io::Result<NamedTempFile> {
|
|||
|
||||
/// Check if the given path exists and rename it until the new (renamed) file does not exist.
|
||||
pub fn free_file(mut path: PathBuf) -> PathBuf {
|
||||
// if path is not a file and not a dir it's probably a pipe on linux which reguarly is intended
|
||||
// and thus does not need to be renamed. what it is on windows ¯\_(ツ)_/¯
|
||||
if !path.is_file() && !path.is_dir() {
|
||||
// if it's a special file does not rename it
|
||||
if is_special_file(&path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
|
|
@ -58,3 +57,9 @@ pub fn free_file(mut path: PathBuf) -> PathBuf {
|
|||
}
|
||||
path
|
||||
}
|
||||
|
||||
/// Check if the given path is a special file. On Linux this is probably a pipe and on Windows
|
||||
/// ¯\_(ツ)_/¯
|
||||
pub fn is_special_file<P: AsRef<Path>>(path: P) -> bool {
|
||||
path.as_ref().exists() && !path.as_ref().is_file() && !path.as_ref().is_dir()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue