1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #3280 from crazystylus/stat-fails-to-read-a-file-redirected-to-stdin

`stat`: Adds support to read a filename redirected to stdin
This commit is contained in:
Sylvestre Ledru 2022-04-09 09:11:48 +02:00 committed by GitHub
commit 53baecab49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -471,11 +471,24 @@ impl Stater {
}
fn new(matches: &ArgMatches) -> UResult<Self> {
let files: Vec<String> = matches
let mut files: Vec<String> = matches
.values_of(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default();
#[cfg(unix)]
if files.contains(&String::from("-")) {
let redirected_path = Path::new("/dev/stdin")
.canonicalize()
.expect("unable to canonicalize /dev/stdin")
.into_os_string()
.into_string()
.unwrap();
for file in &mut files {
if file == "-" {
*file = redirected_path.clone();
}
}
}
let format_str = if matches.is_present(options::PRINTF) {
matches
.value_of(options::PRINTF)