Skip to content

Commit

Permalink
tail: fix stdin redirect (uutils#3842)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhscheer authored and sylvestre committed Sep 5, 2022
1 parent e28301e commit 92c3f60
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/uu/tail/src/tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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,
);
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/by-util/test_tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 92c3f60

Please sign in to comment.