From 452937c8c025375d855c52c790eda248d7d9e27a Mon Sep 17 00:00:00 2001 From: Alex Gorbatchev Date: Tue, 21 Mar 2017 13:52:59 -0700 Subject: [PATCH] Fixes race condition with watchDir --- lib/gaze.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/gaze.js b/lib/gaze.js index ce84081..864b5fc 100644 --- a/lib/gaze.js +++ b/lib/gaze.js @@ -284,6 +284,12 @@ Gaze.prototype._addToWatched = function (files) { Gaze.prototype._watchDir = function (dir, done) { var self = this; var timeoutId; + + // race condition. Ensure that this directory still exists before watching it. + if (!fs.existsSync(dir)) { + return this; + } + try { this._watchers[dir] = fs.watch(dir, function (event) { // race condition. Let's give the fs a little time to settle down. so we