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

tail: fix stdin redirect when file is not at its beginning

Previously, if stdin redirect pointed to a regular file,
tailing started at the beginning of the file. However,
tailing needs to start at the current position because this
is expected by tests/tail-2/start-middle.sh.

This fixes the issue by taking the current offset into account
while going backwards through the stdin redirected file.
This commit is contained in:
Jan Scheer 2022-08-29 01:41:06 +02:00 committed by Sylvestre Ledru
parent 92c3f60440
commit 942928b0ea
3 changed files with 60 additions and 11 deletions

View file

@ -94,6 +94,26 @@ fn test_stdin_redirect_file() {
assert!(buf_stderr.is_empty());
}
#[test]
#[cfg(all(unix, not(any(target_os = "android", target_vendor = "apple"))))] // FIXME: make this work not just on Linux
fn test_stdin_redirect_offset() {
// inspired by: "gnu/tests/tail-2/start-middle.sh"
use std::io::{Seek, SeekFrom};
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.write("k", "1\n2\n");
let mut fh = std::fs::File::open(at.plus("k")).unwrap();
fh.seek(SeekFrom::Start(2)).unwrap();
ts.ucmd()
.set_stdin(fh)
.run()
.stdout_is("2\n")
.succeeded();
}
#[test]
fn test_nc_0_wo_follow() {
// verify that -[nc]0 without -f, exit without reading