From 92c3f6044064fb1797f9c981a8f21fa0d8e9579e Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Thu, 18 Aug 2022 22:04:57 +0200 Subject: [PATCH] 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. --- src/uu/tail/src/tail.rs | 8 ++++---- tests/by-util/test_tail.rs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 6f169d3f4b5..a20c1db0987 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -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; diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index 6afd55f51d7..54cc7bbf13d 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -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();