diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-07-08 16:31:07 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-07-09 15:48:43 +0200 |
commit | 5b5362aa8d80d0822f37e2448d024452dd3c0a98 (patch) | |
tree | a26aa6b3da32fcf3f8b54d6051894b857bc9216e /lib | |
parent | bf539f9bfd2cde4c18557f2607455a4f44fc1565 (diff) | |
download | nodejs-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.js | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -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; } |