tail: fix -f/-F not following files on Windows (#4827)#13248
Open
crutkas wants to merge 1 commit into
Open
Conversation
Merging this PR will degrade performance by 4.62%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
|
GNU testsuite comparison: |
`handle_event` matched `Modify(Data(..))` and `Modify(Metadata(..))` but not the bare `Modify(ModifyKind::Any)` that notify's Windows `ReadDirectoryChangesW` backend emits for every write (`FILE_ACTION_MODIFIED`). Every append/truncate event was therefore dropped and `tail -f` never followed a growing file on Windows. The same event is emitted by the macOS/BSD `kqueue` backend (`NOTE_WRITE`), so this also hardens follow there. Linux inotify and the polling fallback emit the more specific `Modify(Data/Metadata)` variants, so this arm is a no-op for them. Re-enable the seven Windows follow tests previously disabled with "FIXME: test times out"/"currently not working platforms" - they timed out precisely because of this bug and now pass: - test_follow_single, test_follow_multiple, test_follow_name_multiple - test_n0_with_follow - test_follow_name_truncate1, test_follow_name_truncate2, test_follow_name_truncate3 Verified: without the fix test_follow_single and test_follow_name_truncate1 fail; with the fix the full Windows follow suite is green (18 passed). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c32e4c7 to
120a4e8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #4827 —
tail -f/tail -Fdoes not follow a growing file on Windows.tailprints the initial tail, then never emits appended content.Root cause
The follow event loop in
src/uu/tail/src/follow/watch.rs(Observer::handle_event) matched:Modify(Data(DataChange::Any))Modify(Metadata(Any | WriteTime))Modify(Name(RenameMode::To))Create(..)…but not the bare
Modify(ModifyKind::Any).notify's Windows
ReadDirectoryChangesWbackend maps every file write (FILE_ACTION_MODIFIED) to exactlyEventKind::Modify(ModifyKind::Any)(notify/src/windows.rs). So on Windows every append/truncate event fell through to_ => {}and was silently dropped — the file was watched, events arrived, paths matched, but nothing was ever read/printed.Linux inotify emits the more specific
Modify(Data(..)), which is why the bug is Windows-only. The macOS/BSDkqueuebackend also emitsModify(ModifyKind::Any)forNOTE_WRITE, so this fix hardens follow there too. The polling fallback only emitsData/Metadata, so this arm is a no-op for it and for inotify.Fix
Add
ModifyKind::Anyto the match arm (one line + explanatory comment). It routes through the existing tailable/truncation logic, so appends and in-place truncation are both handled.Tests
Re-enabled the seven Windows follow tests that were disabled with
// FIXME: test times out/for currently not working platforms— they timed out because of this bug and now pass:test_follow_single,test_follow_multiple,test_follow_name_multiple,test_n0_with_followtest_follow_name_truncate1,test_follow_name_truncate2,test_follow_name_truncate3These are genuine regression guards (verified on Windows):
test_follow_singleandtest_follow_name_truncate1FAIL.Known limitation (out of scope for this PR)
test_follow_name_truncate4and the move/rename follow tests remain Windows-disabled for a different reason:MetadataExtTail::file_id_eq()is stubbed tofalseon Windows inpaths.rs(it needsGetFileInformationByHandle/ thewindows_by_handleAPI to compare file identity). Truncate-to-same-content and rename detection depend on that, so tail spuriously reports "file has been replaced". That is a separate follow-up.