Commit graph

77 commits

Author SHA1 Message Date
Jan Scheer
75edeea5e4
tail: reduce CPU load for polling (#3618)
* tail: reduce CPU load for polling

This reduces the CPU load for polling drastically (from ~80% down to ~5%)
by removing/fixing several previous workarounds related to polling,
while still passing all related GNU test-suite checks.
* set Notify::PollWatcher delay to: sleep_sec/10 instead of
  sleep_sec/100
* set recv_timeout to sleep_sec instead of sleep_sec/100
* remove the manual polling of watched files

Bugs:
* fix an issue with headers to consistently pass
"test_follow_name_retry_headers" and "gnu/tests/tail-2/overlay-headers.sh"

Code clean-up and refactor
* make fields of struct FileHandling private (and add getters/setters)
to ensure that the paths are absolute and match the paths returned by
Notify::Events
* replace calls to "crash!" with "return USimpleError"
* clean-up formatting
2022-06-21 22:21:19 +02:00
Jan Scheer
435984713a
test_tail: increase delay for test_follow_name_move_create2
Increase delay for this test to be more resillient against
load-jitter on the CI test VMs.
2022-06-09 23:44:37 +02:00
Jan Scheer
e8834597f3
Merge branch 'main' into tail_notify 2022-06-06 16:00:46 +02:00
Jan Scheer
beb2b7cf5e
tail: use functionality from uucore::error where applicable
* minor code clean-up
* remove test-suite summary from README
2022-06-06 14:36:51 +02:00
Jan Scheer
e0efd6cc90
tail: update readme
* add clippy fixes
* add cicd fixes
2022-06-03 13:35:58 +02:00
Jan Scheer
94fe42634b
test_tail: a lot of minor improvements
* fix test_retry7
* fix test_follow_descriptor_vs_rename2
* set permissions with set_permissions instead of a call to chmod
* improve documentation
2022-06-02 17:03:49 +02:00
Jan Scheer
2e918813c1
test_tail: add test_follow_name_move_create2 2022-06-02 17:01:22 +02:00
Jan Scheer
42fa386d89
test_tail: add test_follow_truncate_fast 2022-06-02 16:56:09 +02:00
Jan Scheer
f3aacac9d8
test_tail: add test_follow_name_truncate4 2022-06-02 16:55:04 +02:00
Jan Scheer
bb5dc8bd2f
tail: verify that -[nc]0 without -f, exit without reading
This passes: "gnu/tests/tail-2/tail-n0f.sh"

* add tests for "-[nc]0 wo -f"

* add bubble-up UResult
* rename return_code -> exit_code
2022-05-27 23:36:31 +02:00
Jan Scheer
4bbf708c81
tail: fix handling of PermissionDenied Error
* add tests for opening unreadable files
2022-05-26 13:00:40 +02:00
Jan Scheer
519ab2d172
test_tail: add two new tests for --follow
* add test_follow_name_move2
* add test_follow_multiple_untailable

* disable some tests which do not run properly on Android and/or macOS
2022-05-25 23:25:08 +02:00
Jan Scheer
6a7b6ccdbe
tail: add test_follow_name_move_retry
* add fixes to pass test_follow_name_move_retry
* fix test_follow_name_remove

* bump notify to 5.0.0-pre.15
* adjust PollWatcher::with_delay -> PollWatcher::with_config
2022-05-23 00:51:02 +02:00
Jan Scheer
84480f892d
tail: add equivalent of stdin_is_pipe_or_fifo() for Windows
* add support to determine if stdin is readable on Windows
2022-05-19 22:55:47 +02:00
Jan Scheer
07231e6c6c
tail: fix handling of stdin redirects for macOS
On macOS path.is_dir() can be false for directories
if it was a redirect, e.g. ` tail < DIR`

* fix some tests for macOS

Cleanup:
* fix clippy/spell-checker
* fix build for windows by refactoring stdin_is_pipe_or_fifo()
2022-05-18 14:22:53 +02:00
Jan Scheer
ede73745f5
test_tail: add various tests for follow-stdin and redirect-stdin
* add various tests adapted from `gnu/tests/tail-2/follow-stdin.sh`
* explicitly set_stdin to null where needed, otherwise stdin is always
  `piped`
* tighten some existing tests (no_stderr, code_is, etc)
* add test for fifo
2022-05-16 22:17:09 +02:00
Jan Scheer
59827bca1a
test_tail: add various tests for stdin-follow and stdin-redirect
* add various tests adapted from `gnu/tests/tail-2/follow-stdin.sh`
* explicitly set_stdin to null where needed, otherwise stdin is always
  `piped`
* tighten some existing tests (no_stderr, code_is, etc)
* add test for fifo
2022-05-16 22:02:47 +02:00
Jan Scheer
90a0226844
tail: improve support for polling
* Fix a timing related bug with polling (---disable-inotify) where some
Events weren't delivered fast enough by `Notify::PollWatcher` to pass all
of tests/tail-2/retry.sh and test_tail::{test_retry4, retry7}.

* uu_tail now reverts to polling automatically if inotify backend reports
too many open files (this mimics the behavior of GNU's tail).
2022-04-30 12:02:42 +02:00
Jan Scheer
5331a10a7b
tail: update README 2022-04-24 15:09:28 +02:00
Jan Scheer
ceb2e993c0
tail: update readmes 2022-04-23 00:26:22 +02:00
Jan Scheer
4a56d2916d
tail: fix handling of -f with non regular files
This makes uu_tail pass the "gnu/tests/tail-2/inotify-only-regular" test
again by adding support for charater devices.

test_tail:
* add test_follow_inotify_only_regular
* add clippy fixes for windows
2022-04-21 22:52:17 +02:00
Jan Scheer
7228902e55
Merge branch 'main' into tail_notify 2022-04-19 22:25:35 +02:00
Jan Scheer
eb21330ade
Merge branch 'main' into tail_notify 2022-04-19 22:14:55 +02:00
Jan Scheer
a9fa94824d
tail: switch from Notify 5.0.0-pre.13 to 5.0.0-pre.14 2022-04-05 22:19:25 +02:00
Terts Diepraam
18369dc0be all: use array intoiterator 2022-04-05 10:39:31 +02:00
DevSabb
1eee2194a3 head, tail: include presume-input-pipe parameter 2022-04-01 11:55:33 +02:00
Omer Tuchfeld
fa60898354 Adjust 32-bit tests for tail,split,truncate,head 2022-02-22 13:49:20 +01:00
Hanif Bin Ariffin
3586465917 dont use is_numeric to check for digits
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.43262@gmail.com>
2022-02-03 21:42:22 +08:00
Daniel Eades
5af66753af remove needless borrows 2022-01-30 14:01:21 +01:00
Sylvestre Ledru
b8b642101f
Merge pull request #2898 from jfinkels/tail-lines-zero-terminated
tail: support zero-terminated lines in streams
2022-01-30 09:44:04 +01:00
Jeffrey Finkelstein
83f96ec29d tail: don't error when following non-UTF-8 data
Fix a bug where `tail -f` would terminate with an error due to failing
to parse a UTF-8 string from a sequence of bytes read from the
followed file. This commit replaces the call to `BufRead::read_line()`
with a call to `BufRead::read_until()` so that any sequence of bytes
regardless of encoding can be read.

Fixes #1050.
2022-01-24 21:32:52 -05:00
Jeffrey Finkelstein
f595edaded tail: fix a bug in tail [ -n | -c ] +NUM <file>
Fix a bug when getting all but the first NUM lines or bytes of a file
via `tail -n +NUM <file>` or `tail -c +NUM <file>`. The bug only
existed when a file is given as an argument; it did not exist when the
input data came from stdin.
2022-01-21 19:05:53 -05:00
Jeffrey Finkelstein
58d84d5107 tail: support zero-terminated lines in streams
Support `-z` option when the input is not a seekable file. Previously,
the option was accepted by the argument parser, but it was being
ignored by the application logic.
2022-01-21 18:31:15 -05:00
Jeffrey Finkelstein
ca812a7558 tail: rm trailing \n if input doesn't end with one
Fix a bug where `tail` would inappropriately add a newline to the last
line of output even though the input did not end with one.
2022-01-18 17:34:41 -05:00
Jeffrey Finkelstein
e575007629 tail: improve error handling when file not found 2022-01-17 10:57:24 -05:00
Smicry
fc851e036b
Implement tail -<number> (#2747)
And add obsolete_syntax test
2021-11-19 21:37:47 +01:00
Jan Scheer
18a06c310e
tail: add some tweaks to pass more of GNU's testsuite checks related to -F 2021-11-03 14:40:57 +01:00
Jan Scheer
a9c34ef810
test_tail: add more tests for --follow=name 2021-10-26 16:12:52 +02:00
Jan Scheer
1d2940b159
test_tail: add test_follow_name_truncate1-3 2021-10-24 22:31:14 +02:00
Jan Scheer
3f4b0146a1
test_tail: add test_follow_descriptor_vs_rename1-2 2021-10-24 22:28:30 +02:00
Jan Scheer
07eb50248b
test_tail: add test_retry8-9 2021-10-24 22:21:36 +02:00
Jan Scheer
016291b92e
test_tail: add test_retr7 2021-10-24 22:19:10 +02:00
Jan Scheer
c7c5deb3d8
test_tail: add test_retry6 2021-10-24 22:17:54 +02:00
Jan Scheer
4bfb462387
test_tail: add test_retry5 2021-10-24 22:15:14 +02:00
Jan Scheer
5770921f52
test_tail: add test_retry4 2021-10-24 22:13:58 +02:00
Jan Scheer
8c5c52801d
test_tail: add test_retry3 2021-10-24 22:12:40 +02:00
Jan Scheer
9338b3fd77
test_tail: add test_retry1-2 2021-10-24 22:03:00 +02:00
Jan Scheer
e3b35867a5
test_tail: clean up tests for --follow=name 2021-10-10 00:07:59 +02:00
Jan Scheer
a1206154b1
tail: fix the behavior for -f and rename events
This makes uu_tail pass the "gnu/tests/tail-2/descriptor-vs-rename" test.

* add tests for descriptor-vs-rename (with/without verbose)
* fix some minor error messages
2021-10-08 23:36:41 +02:00
Jan Scheer
23d3e58f33
tail: improve file handling for --follow=name
* Change data structure from Vec to HashMap in order to better
keep track of files while watching them with `--follow=name`.
E.g. file paths that were removed while watching them and exit
if no files are remaining, etc.

* Move all logic related to file handling into a FileHandling trait

* Simplify handling of the verbose flag.
2021-10-07 14:37:02 +02:00