summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2012-07-08 16:31:07 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2012-07-09 15:48:43 +0200
commit5b5362aa8d80d0822f37e2448d024452dd3c0a98 (patch)
treea26aa6b3da32fcf3f8b54d6051894b857bc9216e /lib
parentbf539f9bfd2cde4c18557f2607455a4f44fc1565 (diff)
downloadnodejs-5b5362aa8d80d0822f37e2448d024452dd3c0a98.tar.gz
nodejs-5b5362aa8d80d0822f37e2448d024452dd3c0a98.tar.bz2
nodejs-5b5362aa8d80d0822f37e2448d024452dd3c0a98.zip
fs: make unwatchFile() remove a specific listener
Before this commit, `fs.unwatchFile(path)` removed *all* listeners for `path`. The function is overloaded now: `fs.unwatchFile(path)` still removes all listeners, but `fs.unwatchFile(path, cb)` lets you remove a specific listener. Fixes #3660.
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.js16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 7c622375e..ae9cdf4c4 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -943,10 +943,18 @@ fs.watchFile = function(filename) {
return stat;
};
-fs.unwatchFile = function(filename) {
- var stat;
- if (inStatWatchers(filename)) {
- stat = statWatchers[filename];
+fs.unwatchFile = function(filename, listener) {
+ if (!inStatWatchers(filename)) return;
+
+ var stat = statWatchers[filename];
+
+ if (typeof listener === 'function') {
+ stat.removeListener('change', listener);
+ } else {
+ stat.removeAllListeners('change');
+ }
+
+ if (stat.listeners('change').length === 0) {
stat.stop();
statWatchers[filename] = undefined;
}