Navigation Menu

Skip to content
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

Closed
wants to merge 9 commits into from

Conversation

tym-network
Copy link
Contributor

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)

@@ -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)) {
Copy link
Owner

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

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."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@es128 es128 mentioned this pull request Jun 11, 2014
@Freundschaft
Copy link

does this also fix multiple events that are fired under Windows 7 when Polling is disabled?

@tym-network
Copy link
Contributor Author

It might but I haven't tested it. It fixed an issue with directory names. If you test it, please give us some feedback.

@paulmillr
Copy link
Owner

Could you merge the PR with master please?

@tym-network
Copy link
Contributor Author

Done. Sorry for the delay though...

@es128
Copy link
Collaborator

es128 commented Oct 10, 2014

Landed in master branch. I cherry-picked the commits, resolved conflicts and ensured tests kept passing one at a time.

@es128 es128 closed this Oct 10, 2014
taratatach pushed a commit to taratatach/chokidar that referenced this pull request Oct 2, 2023
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.

None yet

6 participants