From e3ea6144cbb11376a4cf84862af200176d281456 Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Thu, 10 Aug 2023 08:33:53 +0530 Subject: [PATCH 1/2] stat: Output error when - and -f are used together. --- src/uu/stat/src/stat.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 69f3c276084..9ffa064b85e 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -614,6 +614,10 @@ impl Stater { fn do_stat(&self, file: &OsStr, stdin_is_fifo: bool) -> i32 { let display_name = file.to_string_lossy(); let file = if cfg!(unix) && display_name == "-" { + if self.show_fs { + show_error!("using '-' to denote standard input does not work in file system mode"); + return 1; + } if let Ok(p) = Path::new("/dev/stdin").canonicalize() { p.into_os_string() } else { @@ -622,7 +626,6 @@ impl Stater { } else { OsString::from(file) }; - if self.show_fs { #[cfg(unix)] let p = file.as_bytes(); From 414385926653fc14d1f692e638059b36b5c566ae Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Thu, 10 Aug 2023 08:41:19 +0530 Subject: [PATCH 2/2] tests/stat: Test case for using - and -f together --- tests/by-util/test_stat.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/by-util/test_stat.rs b/tests/by-util/test_stat.rs index 92a8bcd9881..d932b35d6ea 100644 --- a/tests/by-util/test_stat.rs +++ b/tests/by-util/test_stat.rs @@ -304,6 +304,19 @@ fn test_stdin_pipe_fifo2() { .succeeded(); } +#[test] +#[cfg(all(unix, not(target_os = "android")))] +fn test_stdin_with_fs_option() { + // $ stat -f - + new_ucmd!() + .arg("-f") + .arg("-") + .set_stdin(std::process::Stdio::null()) + .fails() + .code_is(1) + .stderr_contains("using '-' to denote standard input does not work in file system mode"); +} + #[test] #[cfg(all( unix,