Skip to content

Conversation

@milas
Copy link

@milas milas commented Jun 30, 2021

Windows allows filtering file events to include changes to file
attributes. However, when reporting the actual event, attribute
changes are included as FILE_ACTION_MODIFIED so it's impossible
to distinguish from file writes.

This means the library's op::Chmod is never actually populated
on Windows and so attribute changes aren't really usable. Since
the API does not support specifying an event type filter as a
caller, attribute changes on Windows are ignored rather than being
misreported.

@milas milas added the bug Something isn't working label Jun 30, 2021
@milas milas requested review from landism and nicks June 30, 2021 20:09
@milas milas marked this pull request as draft June 30, 2021 20:14
@milas milas force-pushed the milas/fix-windows-attrib branch 3 times, most recently from 878aa1b to 8a6b26b Compare June 30, 2021 20:57
Windows allows filtering file events to include changes to file
attributes. However, when reporting the actual event, attribute
changes are included as `FILE_ACTION_MODIFIED` so it's impossible
to distinguish from file writes.

This means the library's `op::Chmod` is never actually populated
on Windows and so attribute changes aren't really usable. Since
the API does not support specifying an event type filter as a
caller, attribute changes on Windows are ignored rather than being
misreported.
@milas milas force-pushed the milas/fix-windows-attrib branch from 8a6b26b to f6dca35 Compare June 30, 2021 20:59
@milas milas marked this pull request as ready for review June 30, 2021 20:59
@milas
Copy link
Author

milas commented Jun 30, 2021

From MSDN docs on FILE_NOTIFY_INFORMATION (emphasis mine):

Value Meaning
FILE_ACTION_MODIFIED0x00000003 The file was modified. This can be a change in the time stamp or attributes.

Given that the expected behavior from the library contract is to emit these as Op::Chmod (impossible on Windows), I think filtering them out is better than misreporting as Op::Write.

@milas
Copy link
Author

milas commented Jun 30, 2021

Worth mentioning all tests including new one still pass on Windows 10 x64 with Go 1.16 for me

Copy link
Member

@nicks nicks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I might add a note to the effect of
"windows tends to have random security daemons that twiddle file attributes, generating spurious changes"

i could imagine some future person wanting to watch for file attribute changes on windows. But i agree that from a product standpoint, we can ignore them (especially since windows filesystems don't have an executable bit)

@milas
Copy link
Author

milas commented Jul 1, 2021

Good call - I added some more context as well as a quick "notable changes" section in the README for anyone who ends up on this repo 🙃

@milas milas merged commit dd52449 into master Jul 1, 2021
@milas milas deleted the milas/fix-windows-attrib branch July 1, 2021 14:10
milas added a commit to tilt-dev/tilt that referenced this pull request Jul 1, 2021
Ignore file attribute changes on Windows.

See tilt-dev/fsnotify#8 for details.
milas added a commit to tilt-dev/tilt that referenced this pull request Jul 1, 2021
Ignore file attribute changes on Windows.

See tilt-dev/fsnotify#8 for details.
milas added a commit to tilt-dev/tilt that referenced this pull request Jul 1, 2021
Ignore file attribute changes on Windows.

See tilt-dev/fsnotify#8 for details.
milas added a commit to tilt-dev/tilt that referenced this pull request Jul 1, 2021
Ignore file attribute changes on Windows.

See tilt-dev/fsnotify#8 for details.
@milas milas restored the milas/fix-windows-attrib branch June 2, 2022 15:00
arp242 added a commit to fsnotify/fsnotify that referenced this pull request Oct 14, 2022
On Windows a FILE_ACTION_MODIFIED event (i.e. a Write event) is
triggered on file attribute changes, rather than some dedicates
ATTRIBUTE_CHANGED event. Looking at the docs, I don't really see a way
to distinguish between "real" write events and attribute changes. This is
very odd, but seems to be how the ReadDirectoryChangesW() API works.

The only way I can see to distinguish between the two events is to set
up two filters: one with a FILE_NOTIFY_CHANGE_ATTRIBUTES, and one
without. But that seems overly complex, and no one asked to get Chmod
events for Windows; it's not really all that interesting on Windows
anyway.

The problem is that some software (anti-virus, backup software, etc.)
can issue lots of attribute changes, causing a lot of "fake" Write
events.

So remove the FILE_NOTIFY_CHANGE_ATTRIBUTES and sysFSATTRIB flags.

This was adapted from the tilt-dev/fsnotify fork:
tilt-dev#8

Fixes #487
arp242 added a commit to fsnotify/fsnotify that referenced this pull request Oct 14, 2022
On Windows a FILE_ACTION_MODIFIED event (i.e. a Write event) is
triggered on file attribute changes, rather than some dedicates
ATTRIBUTE_CHANGED event. Looking at the docs, I don't really see a way
to distinguish between "real" write events and attribute changes. This is
very odd, but seems to be how the ReadDirectoryChangesW() API works.

The only way I can see to distinguish between the two events is to set
up two filters: one with a FILE_NOTIFY_CHANGE_ATTRIBUTES, and one
without. But that seems overly complex, and no one asked to get Chmod
events for Windows; it's not really all that interesting on Windows
anyway.

The problem is that some software (anti-virus, backup software, etc.)
can issue lots of attribute changes, causing a lot of "fake" Write
events.

So remove the FILE_NOTIFY_CHANGE_ATTRIBUTES and sysFSATTRIB flags.

This was adapted from the tilt-dev/fsnotify fork:
tilt-dev#8

Fixes #487
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants