coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

`tail`: piped or redirected input on windows and android platforms is not implemented

Open Joining7943 opened this issue 3 years ago • 2 comments

When input comes from a pipe or fifo on windows and android platforms there is no output and no processing of that input, at all. This is part of the problem when determining if the input is a fifo, pipe, file etc. A related issue is #3845. The if check here

https://github.com/uutils/coreutils/blob/0dbcdde64e1ef35ff79122622a9c4fbe3d251292/src/uu/tail/src/tail.rs#L439

fails because path_is_tailable resolves to false because the check in path.is_tailable()

https://github.com/uutils/coreutils/blob/0dbcdde64e1ef35ff79122622a9c4fbe3d251292/src/uu/tail/src/tail.rs#L1635

returns false. On windows platforms (and I assume on android platforms, too) the statement self.is_file() || self.exists() = false resolves to false. This leads to the input not handled and silently ignored, since the if ... else if .. else if chain above misses an else branch, where I would at least expect an error message. To me, the determination of tailable and if a path is fifo, pipe looks broken and is scattered over a 2000 lines file. Wouldn't it be clearer to determine with which kind of input and files we're dealing with right from the start when parsing the settings, store what we've found in a struct or enum and then handle all cases? Looking at this big tail file. refactoring tail.rs to be clearer would help resolving the different handling of input on different platforms.

Joining7943 avatar Aug 27 '22 03:08 Joining7943

On windows platforms (and I assume on android platforms, too) the statement self.is_file() || self.exists() = false resolves to false. This leads to the input not handled and silently ignored, since the if ... else if .. else if chain above misses an else branch, where I would at least expect an error message.

Handling piped or redirected input for tail was added only recently with the primary focus on Linux in order to pass the GNU test suite.

To me, the determination of tailable and if a path is fifo, pipe looks broken and is scattered over a 2000 lines file.

PRs to improve and expand this functionality to other platforms are of course always welcome.

If you decide to work on this, please keep in mind to also activate the tests regarding piped input in tests_tail.rs for the platform you chose. Right now they only run on Linux.

Wouldn't it be clearer to determine with which kind of input and files we're dealing with right from the start when parsing the settings, store what we've found in a struct or enum and then handle all cases?

Keep in mind that the status, e.g. if a path is tailable or not, can change during runtime with --follow.

jhscheer avatar Aug 28 '22 10:08 jhscheer

Keep in mind that the status, e.g. if a path is tailable or not, can change during runtime with --follow. ... If you decide to work on this, please keep in mind to also activate the tests regarding piped input in tests_tail.rs for the platform you chose. Right now they only run on Linux.

Thanks for the tip.

I can try adding windows to the functionality of tail, at least with regard of piped input. I currently don't have a working android or macos environment for testing.

Joining7943 avatar Aug 28 '22 23:08 Joining7943