From d30aa6d621cdd6c5af4eb8514ba30b3ddc97d567 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Wed, 9 Nov 2011 19:54:43 +0100 Subject: [PATCH] Ensuring that fs.watch duplication does not occur --- lib/coffee-script/command.js | 7 ++++--- src/command.coffee | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index 61b4d7e5..59c22ef1 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -197,11 +197,12 @@ watch = function(source, base) { return fs.stat(source, function(err, prevStats) { - var callback; + var callback, watcher; if (err) throw err; - return fs.watch(source, callback = function(event) { + return watcher = fs.watch(source, callback = function(event) { if (event === 'rename') { - return fs.watch(source, callback); + watcher.close(); + return watcher = fs.watch(source, callback); } else if (event === 'change') { return fs.stat(source, function(err, stats) { if (err) throw err; diff --git a/src/command.coffee b/src/command.coffee index a06d1ea4..44c89c15 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -174,9 +174,10 @@ loadRequires = -> watch = (source, base) -> fs.stat source, (err, prevStats)-> throw err if err - fs.watch source, callback = (event) -> + watcher = fs.watch source, callback = (event) -> if event is 'rename' - fs.watch source, callback + watcher.close() + watcher = fs.watch source, callback else if event is 'change' fs.stat source, (err, stats) -> throw err if err