Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

head,tail: implement undocumented option ---presume-input-pipe #2907

Closed
jfinkels opened this issue Jan 22, 2022 · 4 comments · Fixed by #3345
Closed

head,tail: implement undocumented option ---presume-input-pipe #2907

jfinkels opened this issue Jan 22, 2022 · 4 comments · Fixed by #3345

Comments

@jfinkels
Copy link
Collaborator

GNU head and tail have an undocumented option ---presume-input-pipe (notice the three dashes instead of two). I don't know what it does, but here is an example of it:

$ printf "%0.sa\n" {1..100} | head ---presume-input-pipe
a
a
a
a
a
a
a
a
a
a

Lack of support for this option is preventing some of the GNU test suite test cases to fail.

(See similar issue in split here #2864.)

@tertsdiepraam
Copy link
Member

Possibly interesting context: https://lists.gnu.org/archive/html/coreutils/2020-08/msg00017.html, specifically:

In fact, look at all the spots where 'presume_input_pipe' is used, to distinguish between seekable files where lseek works, and pipes where it doesn't (there is even an undocumented 'tail ---presume-input-pipe' option that lets you force-disable the lseek optimization, to get the speed penalty of a non-seekable file even when testing on seekable input).

I think it's okay to implement it as a noop for now, though.

On the clap side of things, clap does not normally allow 3 leading dashes anymore since clap 3, but there is a workaround: to use alias instead. In rm, I've implemented it a similar flag like this:

static PRESUME_INPUT_TTY: &str = "-presume-input-tty";
// snip
App::new(uucore::util_name())
  .version(crate_version!())
  .about(ABOUT)
  .arg(
      Arg::new(PRESUME_INPUT_TTY)
      .long(PRESUME_INPUT_TTY)
      .alias(PRESUME_INPUT_TTY)
      .hide(true)
  )

@ghost
Copy link

ghost commented Feb 14, 2022

I looked into GNU coreutils. The parameter is used to bypass file seek operations. In uutils I see the below code differentiate between stdin (pipe) and file

let res = match file.as_str() {

I am thinking of doing "-" || PRESUME_INPUT_PIPE. Let me know if it works. I'll make the change.

Edit: I am not correct syntactically in the proposed solution, but I guess you get the idea. What I am trying to say is that the if the flag presume-input-pipe is true, then the code will follow the same path as stdin.

@ghost
Copy link

ghost commented Feb 21, 2022

Is this still required? Can someone confirm if my approach is acceptable? I don't want to work on a PR that gets eventually rejected.

@tertsdiepraam
Copy link
Member

tertsdiepraam commented Feb 21, 2022

@DevSabb I think what you're proposing is correct, at least that's what I would expect it to do based on your information and the mailing list I posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants