mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 23:02:38 +00:00
tail: fix offset for stdin redirect if multiple input files
This commit is contained in:
parent
74f359bd76
commit
88d3aee71c
2 changed files with 37 additions and 3 deletions
|
@ -503,8 +503,11 @@ fn uu_tail(mut settings: Settings) -> UResult<()> {
|
|||
}
|
||||
|
||||
let mut reader;
|
||||
if file.is_seekable(settings.stdin_offset)
|
||||
&& metadata.as_ref().unwrap().get_block_size() > 0
|
||||
if file.is_seekable(if display_name.is_stdin() {
|
||||
settings.stdin_offset
|
||||
} else {
|
||||
0
|
||||
}) && metadata.as_ref().unwrap().get_block_size() > 0
|
||||
{
|
||||
bounded_tail(&mut file, &settings);
|
||||
reader = BufReader::new(file);
|
||||
|
|
|
@ -107,7 +107,38 @@ fn test_stdin_redirect_offset() {
|
|||
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();
|
||||
ts.ucmd()
|
||||
.set_stdin(fh)
|
||||
.run()
|
||||
.no_stderr()
|
||||
.stdout_is("2\n")
|
||||
.succeeded();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(any(target_os = "android", target_vendor = "apple"))))] // FIXME: make this work not just on Linux
|
||||
fn test_stdin_redirect_offset2() {
|
||||
// like test_stdin_redirect_offset but with multiple files
|
||||
use std::io::{Seek, SeekFrom};
|
||||
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.write("k", "1\n2\n");
|
||||
at.write("l", "3\n4\n");
|
||||
at.write("m", "5\n6\n");
|
||||
let mut fh = std::fs::File::open(at.plus("k")).unwrap();
|
||||
fh.seek(SeekFrom::Start(2)).unwrap();
|
||||
|
||||
ts.ucmd()
|
||||
.set_stdin(fh)
|
||||
.args(&["k", "-", "l", "m"])
|
||||
.run()
|
||||
.no_stderr()
|
||||
.stdout_is(
|
||||
"==> k <==\n1\n2\n\n==> standard input <==\n2\n\n==> l <==\n3\n4\n\n==> m <==\n5\n6\n",
|
||||
)
|
||||
.succeeded();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue