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

tail: fix stdin redirect (#3842)

This fixes a bug where calling `tail - < file.txt` would result
in invoking `unbounded_tail()`.
However, it is a stdin redirect to a seekable regular file and
therefore `bounded_tail` should be invoked as if `tail file.txt` had
been called.
This commit is contained in:
Jan Scheer 2022-08-18 22:04:57 +02:00 committed by Sylvestre Ledru
parent e28301e969
commit 92c3f60440
2 changed files with 5 additions and 4 deletions

View file

@ -436,9 +436,9 @@ fn uu_tail(mut settings: Settings) -> UResult<()> {
let metadata = path.metadata().ok();
if display_name.is_stdin() && path_is_tailable {
if display_name.is_stdin() && path_is_tailable && !path.is_file() {
if settings.verbose {
files.print_header(Path::new(text::STDIN_HEADER), !first_header);
files.print_header(&display_name, !first_header);
first_header = false;
}
@ -452,7 +452,7 @@ fn uu_tail(mut settings: Settings) -> UResult<()> {
PathData {
reader: Some(Box::new(reader)),
metadata: None,
display_name: PathBuf::from(text::STDIN_HEADER),
display_name,
},
true,
);
@ -476,7 +476,7 @@ fn uu_tail(mut settings: Settings) -> UResult<()> {
match File::open(&path) {
Ok(mut file) => {
if settings.verbose {
files.print_header(&path, !first_header);
files.print_header(&display_name, !first_header);
first_header = false;
}
let mut reader;

View file

@ -76,6 +76,7 @@ fn test_stdin_redirect_file() {
.set_stdin(std::fs::File::open(at.plus("f")).unwrap())
.arg("-v")
.run()
.no_stderr()
.stdout_is("==> standard input <==\nfoo")
.succeeded();