Skip to content

Fix false positives when using watch flag. #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Fix false positives when using watch flag. #191

wants to merge 1 commit into from

Conversation

albrow
Copy link
Contributor

@albrow albrow commented Mar 4, 2015

The watch flag is an awesome feature! However, I noticed one small issue when I watched what was going on closely. There were some false positives triggering a rebuild when it wasn't necessary.

Here's a demo in which I save the file once but two rebuilds are triggered. One immediately, then another about a second later:

False positive demo

I have used fsnotify before to watch for changes, so I had a hunch for where to look. I found two cases which were causing false positives:

  1. Temporary files being created or edited, e.g. those used by editors like Sublime Text for atomic saves. I fixed this by ignoring changes to temporary files.
  2. Mac OS Finder indexing the file and making it look like a change. I fixed this by keeping a hash of each file and comparing the hashes to see if anything actually changed. It's possible other operating systems have similar problems, but I'm not sure.

I can understand if you have some hesitation about keeping a large number of hashes of files, but in practice, I haven't noticed any impact on performance. I used xxhash which is pretty fast. That being said, it's possible the code could be optimized a bit more. For example, here I'm using ioutil to read the entire source file so I can calculate the hash. If you are already reading the source file somewhere, it might make sense to calculate the hash at that point instead of reading the whole file twice. However, I couldn't find a more appropriate place to put it at first glance.

There were two cases which were causing false positives:
1. Temporary files created by editors which use atomic saves. I fixed this
by ignoring changes to temporary files.
2. Mac OS indexing the file and making it look like a change. I fixed this
by keeping a hash of each file and comparing the hashes to see if anything
actually changed.
@neelance neelance closed this in 702c1e9 Mar 4, 2015
@neelance
Copy link
Member

neelance commented Mar 4, 2015

Hey. Thanks for wanting to contribute, much appreciated! The check for temporary files was a good one, but the Finder issue could be more easily resolved by checking ev.Op, because in that case ev.Op == fsnotify.Chmod only.

@albrow
Copy link
Contributor Author

albrow commented Mar 4, 2015

Gotcha. Thanks!

@albrow albrow deleted the fix-watch-false-positives branch April 21, 2015 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants