Skip to content

Commit 20d26aa

Browse files
committed
head: fix meaning of ---presume-input-pipe
The option ---presume-input-pipe is debug option that should disable the seeking optimization, not force it to read stdin. This fixes the GNU test head-elide-tail.
1 parent 69bc6a7 commit 20d26aa

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/uu/head/src/head.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ fn head_backwards_file(input: &mut File, options: &HeadOptions) -> io::Result<u6
425425
let st = input.metadata()?;
426426
let seekable = is_seekable(input);
427427
let blksize_limit = uucore::fs::sane_blksize::sane_blksize_from_metadata(&st);
428-
if !seekable || st.len() <= blksize_limit {
428+
if !seekable || st.len() <= blksize_limit || options.presume_input_pipe {
429429
head_backwards_without_seek_file(input, options)
430430
} else {
431431
head_backwards_on_seekable_file(input, options)
@@ -474,8 +474,8 @@ fn head_file(input: &mut File, options: &HeadOptions) -> io::Result<u64> {
474474
fn uu_head(options: &HeadOptions) -> UResult<()> {
475475
let mut first = true;
476476
for file in &options.files {
477-
let res = match (file.as_str(), options.presume_input_pipe) {
478-
(_, true) | ("-", false) => {
477+
let res = match file.as_str() {
478+
"-" => {
479479
if (options.files.len() > 1 && !options.quiet) || options.verbose {
480480
if !first {
481481
println!();
@@ -519,7 +519,7 @@ fn uu_head(options: &HeadOptions) -> UResult<()> {
519519

520520
Ok(())
521521
}
522-
(name, false) => {
522+
name => {
523523
let mut file = match File::open(name) {
524524
Ok(f) => f,
525525
Err(err) => {

tests/by-util/test_head.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ fn test_single_1_line() {
9292
.stdout_is_fixture("lorem_ipsum_1_line.expected");
9393
}
9494

95+
#[test]
96+
fn test_single_1_line_presume_input_pipe() {
97+
new_ucmd!()
98+
.args(&["---presume-input-pipe", "-n", "1", INPUT])
99+
.succeeds()
100+
.stdout_is_fixture("lorem_ipsum_1_line.expected");
101+
}
102+
95103
#[test]
96104
fn test_single_5_chars() {
97105
new_ucmd!()

0 commit comments

Comments
 (0)