Skip to content

Commit b815cf0

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

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/params.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::PathBuf;
44

55
use std::fs::File;
66
use std::io::stdin;
7+
#[cfg(unix)]
78
use std::os::fd::AsFd;
89

910
use regex::Regex;
@@ -185,18 +186,21 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
185186
let mut from_path: PathBuf = PathBuf::from(&params.from);
186187
let mut to_path: PathBuf = PathBuf::from(&params.to);
187188

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

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

0 commit comments

Comments
 (0)