Skip to content

Commit f21689d

Browse files
Make handling stdin directory unix specific
1 parent 4482bdb commit f21689d

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/params.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::ffi::OsString;
2-
use std::fs;
32
use std::path::PathBuf;
43

5-
use std::fs::File;
4+
#[cfg(unix)]
5+
use std::fs::{self, File};
6+
#[cfg(unix)]
67
use std::io::stdin;
8+
#[cfg(unix)]
79
use std::os::fd::AsFd;
810

911
use regex::Regex;
@@ -185,18 +187,21 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
185187
let mut from_path: PathBuf = PathBuf::from(&params.from);
186188
let mut to_path: PathBuf = PathBuf::from(&params.to);
187189

188-
// check if stdin is a directory
189-
let fd = stdin().as_fd().try_clone_to_owned().unwrap();
190-
let file = File::from(fd);
191-
let meta = file.metadata().unwrap();
192-
if meta.is_dir() {
193-
let mut stdin_path = fs::canonicalize("/dev/stdin").unwrap();
194-
if params.from == "-" {
195-
stdin_path.push(to_path.file_name().unwrap());
196-
} else {
197-
stdin_path.push(from_path.file_name().unwrap());
190+
#[cfg(unix)]
191+
{
192+
// check if stdin is a directory
193+
let fd = stdin().as_fd().try_clone_to_owned().unwrap();
194+
let file = File::from(fd);
195+
let meta = file.metadata().unwrap();
196+
if meta.is_dir() {
197+
let mut stdin_path = fs::canonicalize("/dev/stdin").unwrap();
198+
if params.from == "-" {
199+
stdin_path.push(to_path.file_name().unwrap());
200+
} else {
201+
stdin_path.push(from_path.file_name().unwrap());
202+
}
203+
params.stdin_path = stdin_path.into();
198204
}
199-
params.stdin_path = stdin_path.into();
200205
}
201206

202207
if (from_path.is_dir() || !params.stdin_path.is_empty()) && to_path.is_file() {

0 commit comments

Comments
 (0)