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
Fix polling on Windows with multiple "add" events + support of "delete" #124
Conversation
@@ -273,6 +273,15 @@ FSWatcher.prototype._handleFile = function(file, stats, initialAdd) { | |||
var _this = this; | |||
if (initialAdd == null) initialAdd = false; | |||
this._watch(file, function(file, newStats) { | |||
if (newStats && newStats.mtime.getTime() === 0) { | |||
if (!fs.existsSync(file)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what i f we do this async
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't fs.existsSync an anti pattern in most cases? But since we are just raising events it should be okay?
"In particular, checking if a file exists before opening it is an anti-pattern that leaves you vulnerable to race conditions: another process may remove the file between the calls to fs.exists() and fs.open(). Just open the file and handle the error when it's not there."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
does this also fix multiple events that are fired under Windows 7 when Polling is disabled? |
It might but I haven't tested it. It fixed an issue with directory names. If you test it, please give us some feedback. |
Could you merge the PR with master please? |
Done. Sorry for the delay though... |
Landed in master branch. I cherry-picked the commits, resolved conflicts and ensured tests kept passing one at a time. |
Create .npmignore
When 'usePolling' is enabled on Windows, this fix avoid multiple "add" events that occured when creating a file in the same folder as other files.
"Unlink" events are now fired, even when using polling for both directories and files.
Before merging, please run tests on MacOS and Linux. (Tested on Windows 7)