Skip to content

Commit

Permalink
dd: misc gnu test (uutils#6084)
Browse files Browse the repository at this point in the history
* dd: check file is a dir for iflag directory

* Improve english

Co-authored-by: Daniel Hofstetter <[email protected]>

* dd: stderr output checking for "iflag directory" testcase

* dd: replace #[cfg(unix)] with #[test]

---------

Co-authored-by: Sylvestre Ledru <[email protected]>
Co-authored-by: Daniel Hofstetter <[email protected]>
  • Loading branch information
3 people authored Mar 20, 2024
1 parent 08172c2 commit 660014e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ impl<'a> Input<'a> {
};
#[cfg(unix)]
let mut src = Source::stdin_as_file();
#[cfg(unix)]
if let Source::StdinFile(f) = &src {
// GNU compatibility:
// this will check whether stdin points to a folder or not
if f.metadata()?.is_file() && settings.iflags.directory {
show_error!("standard input: not a directory");
return Err(1.into());
}
};
if settings.skip > 0 {
src.skip(settings.skip)?;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/by-util/test_dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,20 @@ fn test_reading_partial_blocks_from_fifo_unbuffered() {
assert!(output.stderr.starts_with(expected));
}

#[test]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_iflag_directory_fails_when_file_is_passed_via_std_in() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.make_file("input");
let filename = at.plus_as_string("input");
new_ucmd!()
.args(&["iflag=directory", "count=0"])
.set_stdin(std::process::Stdio::from(File::open(filename).unwrap()))
.fails()
.stderr_contains("standard input: not a directory");
}

#[test]
fn test_stdin_stdout_not_rewound_even_when_connected_to_seekable_file() {
use std::process::Stdio;
Expand Down

0 comments on commit 660014e

Please sign in to comment.