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:
parent
e28301e969
commit
92c3f60440
2 changed files with 5 additions and 4 deletions
|
@ -436,9 +436,9 @@ fn uu_tail(mut settings: Settings) -> UResult<()> {
|
||||||
|
|
||||||
let metadata = path.metadata().ok();
|
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 {
|
if settings.verbose {
|
||||||
files.print_header(Path::new(text::STDIN_HEADER), !first_header);
|
files.print_header(&display_name, !first_header);
|
||||||
first_header = false;
|
first_header = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,7 +452,7 @@ fn uu_tail(mut settings: Settings) -> UResult<()> {
|
||||||
PathData {
|
PathData {
|
||||||
reader: Some(Box::new(reader)),
|
reader: Some(Box::new(reader)),
|
||||||
metadata: None,
|
metadata: None,
|
||||||
display_name: PathBuf::from(text::STDIN_HEADER),
|
display_name,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
@ -476,7 +476,7 @@ fn uu_tail(mut settings: Settings) -> UResult<()> {
|
||||||
match File::open(&path) {
|
match File::open(&path) {
|
||||||
Ok(mut file) => {
|
Ok(mut file) => {
|
||||||
if settings.verbose {
|
if settings.verbose {
|
||||||
files.print_header(&path, !first_header);
|
files.print_header(&display_name, !first_header);
|
||||||
first_header = false;
|
first_header = false;
|
||||||
}
|
}
|
||||||
let mut reader;
|
let mut reader;
|
||||||
|
|
|
@ -76,6 +76,7 @@ fn test_stdin_redirect_file() {
|
||||||
.set_stdin(std::fs::File::open(at.plus("f")).unwrap())
|
.set_stdin(std::fs::File::open(at.plus("f")).unwrap())
|
||||||
.arg("-v")
|
.arg("-v")
|
||||||
.run()
|
.run()
|
||||||
|
.no_stderr()
|
||||||
.stdout_is("==> standard input <==\nfoo")
|
.stdout_is("==> standard input <==\nfoo")
|
||||||
.succeeded();
|
.succeeded();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue