mirror of
https://github.com/uutils/coreutils
synced 2024-12-15 07:42:48 +00:00
Merge pull request #3959 from Joining7943/tail-reactivate-presume-input-pipe
tail: Reactivate ---presume-input-pipe option
This commit is contained in:
commit
4b517a361d
2 changed files with 77 additions and 8 deletions
|
@ -159,7 +159,8 @@ fn tail_file(
|
||||||
Ok(mut file) => {
|
Ok(mut file) => {
|
||||||
input_service.print_header(input);
|
input_service.print_header(input);
|
||||||
let mut reader;
|
let mut reader;
|
||||||
if file.is_seekable(if input.is_stdin() { offset } else { 0 })
|
if !settings.presume_input_pipe
|
||||||
|
&& file.is_seekable(if input.is_stdin() { offset } else { 0 })
|
||||||
&& metadata.as_ref().unwrap().get_block_size() > 0
|
&& metadata.as_ref().unwrap().get_block_size() > 0
|
||||||
{
|
{
|
||||||
bounded_tail(&mut file, settings);
|
bounded_tail(&mut file, settings);
|
||||||
|
@ -379,9 +380,9 @@ fn backwards_thru_file(file: &mut File, num_delimiters: u64, delimiter: u8) {
|
||||||
/// `BLOCK_SIZE` until we find the location of the first line/byte. This ends up
|
/// `BLOCK_SIZE` until we find the location of the first line/byte. This ends up
|
||||||
/// being a nice performance win for very large files.
|
/// being a nice performance win for very large files.
|
||||||
fn bounded_tail(file: &mut File, settings: &Settings) {
|
fn bounded_tail(file: &mut File, settings: &Settings) {
|
||||||
|
debug_assert!(!settings.presume_input_pipe);
|
||||||
|
|
||||||
// Find the position in the file to start printing from.
|
// Find the position in the file to start printing from.
|
||||||
// dbg!("bounded");
|
|
||||||
// dbg!(&settings.mode);
|
|
||||||
match &settings.mode {
|
match &settings.mode {
|
||||||
FilterMode::Lines(Signum::Negative(count), delimiter) => {
|
FilterMode::Lines(Signum::Negative(count), delimiter) => {
|
||||||
backwards_thru_file(file, *count, *delimiter);
|
backwards_thru_file(file, *count, *delimiter);
|
||||||
|
@ -418,8 +419,6 @@ fn bounded_tail(file: &mut File, settings: &Settings) {
|
||||||
fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) -> UResult<()> {
|
fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) -> UResult<()> {
|
||||||
let stdout = stdout();
|
let stdout = stdout();
|
||||||
let mut writer = BufWriter::new(stdout.lock());
|
let mut writer = BufWriter::new(stdout.lock());
|
||||||
// dbg!("unbounded");
|
|
||||||
// dbg!(&settings.mode);
|
|
||||||
match &settings.mode {
|
match &settings.mode {
|
||||||
FilterMode::Lines(Signum::Negative(count), sep) => {
|
FilterMode::Lines(Signum::Negative(count), sep) => {
|
||||||
let mut chunks = chunks::LinesChunkBuffer::new(*sep, *count);
|
let mut chunks = chunks::LinesChunkBuffer::new(*sep, *count);
|
||||||
|
|
|
@ -7,10 +7,9 @@
|
||||||
// spell-checker:ignore (libs) kqueue
|
// spell-checker:ignore (libs) kqueue
|
||||||
// spell-checker:ignore (jargon) tailable untailable
|
// spell-checker:ignore (jargon) tailable untailable
|
||||||
|
|
||||||
// TODO: add tests for presume_input_pipe
|
|
||||||
|
|
||||||
extern crate tail;
|
extern crate tail;
|
||||||
|
|
||||||
|
use crate::common::random::*;
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
use std::char::from_digit;
|
use std::char::from_digit;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -2516,7 +2515,6 @@ fn test_illegal_seek() {
|
||||||
#[cfg(all(not(target_os = "android"), not(target_os = "windows")))] // FIXME: See https://github.com/uutils/coreutils/issues/3881
|
#[cfg(all(not(target_os = "android"), not(target_os = "windows")))] // FIXME: See https://github.com/uutils/coreutils/issues/3881
|
||||||
mod pipe_tests {
|
mod pipe_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::common::random::*;
|
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use tail::chunks::BUFFER_SIZE as CHUNK_BUFFER_SIZE;
|
use tail::chunks::BUFFER_SIZE as CHUNK_BUFFER_SIZE;
|
||||||
|
|
||||||
|
@ -3251,3 +3249,75 @@ fn test_seek_bytes_forward_outside_file() {
|
||||||
.run()
|
.run()
|
||||||
.stdout_is("");
|
.stdout_is("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some basic tests for ---presume-input-pipe. These tests build upon the
|
||||||
|
// debug_assert in bounded tail to detect that we're using the bounded_tail in
|
||||||
|
// case the option is given on command line.
|
||||||
|
#[cfg(all(not(target_os = "android"), not(target_os = "windows")))] // FIXME:
|
||||||
|
#[test]
|
||||||
|
fn test_args_when_presume_input_pipe_given_input_is_pipe() {
|
||||||
|
let random_string = RandomString::generate(AlphanumericNewline, 1000);
|
||||||
|
let random_string = random_string.as_str();
|
||||||
|
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["---presume-input-pipe", "-c", "-0"])
|
||||||
|
.pipe_in(random_string)
|
||||||
|
.ignore_stdin_write_error()
|
||||||
|
.succeeds()
|
||||||
|
.no_stdout()
|
||||||
|
.no_stderr();
|
||||||
|
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["---presume-input-pipe", "-c", "+0"])
|
||||||
|
.pipe_in(random_string)
|
||||||
|
.ignore_stdin_write_error()
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only(random_string);
|
||||||
|
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["---presume-input-pipe", "-n", "-0"])
|
||||||
|
.pipe_in(random_string)
|
||||||
|
.ignore_stdin_write_error()
|
||||||
|
.succeeds()
|
||||||
|
.no_stdout()
|
||||||
|
.no_stderr();
|
||||||
|
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["---presume-input-pipe", "-n", "+0"])
|
||||||
|
.pipe_in(random_string)
|
||||||
|
.ignore_stdin_write_error()
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only(random_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_args_when_presume_input_pipe_given_input_is_file() {
|
||||||
|
let random_string = RandomString::generate(AlphanumericNewline, 1000);
|
||||||
|
let random_string = random_string.as_str();
|
||||||
|
|
||||||
|
let ts = TestScenario::new(util_name!());
|
||||||
|
let at = &ts.fixtures;
|
||||||
|
at.write("data", random_string);
|
||||||
|
|
||||||
|
ts.ucmd()
|
||||||
|
.args(&["---presume-input-pipe", "-c", "-0", "data"])
|
||||||
|
.succeeds()
|
||||||
|
.no_stdout()
|
||||||
|
.no_stderr();
|
||||||
|
|
||||||
|
ts.ucmd()
|
||||||
|
.args(&["---presume-input-pipe", "-c", "+0", "data"])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only(random_string);
|
||||||
|
|
||||||
|
ts.ucmd()
|
||||||
|
.args(&["---presume-input-pipe", "-n", "-0", "data"])
|
||||||
|
.succeeds()
|
||||||
|
.no_stdout()
|
||||||
|
.no_stderr();
|
||||||
|
|
||||||
|
ts.ucmd()
|
||||||
|
.args(&["---presume-input-pipe", "-n", "+0", "data"])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only(random_string);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue