From 00683f55db711d344a423a8f34f8aa2ef0fffef2 Mon Sep 17 00:00:00 2001 From: laggingreflex Date: Tue, 14 Aug 2018 14:58:00 +0530 Subject: [PATCH] fix: allow force close --- index.js | 2 +- lib/nodefs-handler.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 121703a3..875b429d 100644 --- a/index.js +++ b/index.js @@ -699,7 +699,7 @@ FSWatcher.prototype.close = function() { this.closed = true; Object.keys(this._closers).forEach(function(watchPath) { - this._closers[watchPath](); + this._closers[watchPath](true); delete this._closers[watchPath]; }, this); this._watched = Object.create(null); diff --git a/lib/nodefs-handler.js b/lib/nodefs-handler.js index c2877325..1673f22e 100644 --- a/lib/nodefs-handler.js +++ b/lib/nodefs-handler.js @@ -114,11 +114,14 @@ function setFsWatchListener(path, fullPath, options, handlers) { // removes this instance's listeners and closes the underlying fs.watch // instance if there are no more listeners left - return function close() { + return function close(force) { delete container.listeners[listenerIndex]; delete container.errHandlers[listenerIndex]; delete container.rawEmitters[listenerIndex]; - if (!Object.keys(container.listeners).length) { + if (force) { + container.watcher.close(); + delete FsWatchInstances[fullPath]; + } else if (!Object.keys(container.listeners).length) { if (!container.watcherUnusable) { // check to protect against issue #730 container.watcher.close(); } @@ -190,10 +193,10 @@ function setFsWatchFileListener(path, fullPath, options, handlers) { // removes this instance's listeners and closes the underlying fs.watchFile // instance if there are no more listeners left - return function close() { + return function close(force) { delete container.listeners[listenerIndex]; delete container.rawEmitters[listenerIndex]; - if (!Object.keys(container.listeners).length) { + if (force || !Object.keys(container.listeners).length) { fs.unwatchFile(fullPath); delete FsWatchFileInstances[fullPath]; }