Repository navigation
Add filtered Windows watcher operations - #6
Draft
SearidangPa wants to merge 1 commit into
Draft
SearidangPa wants to merge 1 commit into
SearidangPa wants to merge 1 commit into
Conversation
SearidangPa
marked this pull request as draft
August 25, 2026 21:22
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.
Summary
Watcher.AddWithOpsAPI for selecting fsnotify operationsFILE_ACTION_MODIFIEDto map toChmodfor attributes-only subscriptionsWritemapping for legacy combinedAddsubscriptionsMotivation
ReadDirectoryChangesWreports bothFILE_NOTIFY_CHANGE_LAST_WRITEandFILE_NOTIFY_CHANGE_ATTRIBUTESasFILE_ACTION_MODIFIED. When both filters are used by one watcher, the backend cannot tell which filter matched.Using independent watchers with
AddWithOps(..., Write)andAddWithOps(..., Chmod)lets consumers distinguish the subscription that fired. This is needed by the Windows cloud-drive watcher to separate placeholder pin-state metadata from content-write notifications.Compatibility
The existing
Addbehavior is unchanged: combined modified notifications continue to be emitted asWrite.The fsnotify branch does not detect “pin” directly. It separates two kinds of Windows filesystem notifications so the caller can interpret them differently.
The original behavior
The current Windows backend effectively does this:
The important problem is that Windows reports both:
FILE_NOTIFY_CHANGE_LAST_WRITEFILE_NOTIFY_CHANGE_ATTRIBUTESas the same raw action:
So the old backend loses the distinction and always converts it to:
That is why pin operations currently look like local writes.
What the fsnotify branch adds
1. A filtered watch API
The branch adds:
Example:
or:
Internally, it converts the public fsnotify operations into Windows notification filters:
Chmodis being used because it is the existing fsnotify operation that represents filesystem attribute changes. On Windows, this meansFILE_NOTIFY_CHANGE_ATTRIBUTES; it does not necessarily mean a Unix-style permission change.2. Modified events can now be emitted as
ChmodWhen Windows reports:
the backend looks at the filter used for that watch:
So the backend can now produce:
The existing
Add()API is intentionally preserved:still behaves as before and treats modified events as
Write.Why two fsnotify watchers are required
This is the most important part.
This is not sufficient:
Those filters are merged onto the same underlying Windows watch. The resulting
ReadDirectoryChangesWrequest contains both filters, and Windows still only reports:At that point, the backend cannot know which filter caused the event.
Instead, the caller must create two independent fsnotify watchers:
This produces two separate Windows requests:
Then the application reads from both channels and combines them into its own event pipeline.
That is what the corresponding changes in this repository do.
Actual event behavior
Pinning a placeholder
The Windows test showed:
The local changes watcher then interprets
Chmodas:It reads the Cloud Files placeholder metadata to determine whether the state is:
The fsnotify library itself does not determine which pin state occurred.
Writing a normal file
The test showed:
This is treated as a content update.
Writing a placeholder
This is the caveat:
Placeholder writes modify both file content and placeholder/in-sync metadata. Therefore, separating the notification streams does not guarantee exactly one event per operation.
The application still needs logic to ignore the attribute event when it is merely a side effect of a content write. The current local changes handler does that by comparing the file modification time against the placeholder identity metadata.
What the branch does and does not solve
It solves
fsnotify.Add()users remain compatible.It does not solve
PinnedorUnpinneddirectly.fsnotify.Watcherinstances.The intended flow is therefore:
Tests
go test ./...on WindowsChmodbut notWriteWritebut notChmod