Fixed unwatchfile method for issue551

This commit is contained in:
Vince 2018-10-22 15:36:02 -04:00
parent db315eae13
commit d68361a99b
2 changed files with 15 additions and 14 deletions

View File

@ -17,7 +17,6 @@ var providers = require('../providers/index.js');
var Shell = require('../shell/shell.js'); var Shell = require('../shell/shell.js');
var Intercom = require('../../lib/intercom.js'); var Intercom = require('../../lib/intercom.js');
var FSWatcher = require('../fs-watcher.js'); var FSWatcher = require('../fs-watcher.js');
//var unwatcher = require('../unwatcherFile.js');
var Errors = require('../errors.js'); var Errors = require('../errors.js');
var defaultGuidFn = require('../shared.js').guid; var defaultGuidFn = require('../shared.js').guid;
@ -166,19 +165,15 @@ function FileSystem(options, callback) {
} }
listener = listener || nop; listener = listener || nop;
if(listener == nop){ var unwatcher = new FSWatcher();
this.removeAllListeners(); unwatcher.start(filename, false, options.recursive);
if(listener != nop){
unwatcher.closeOneListener(filename);
} }
else{ else{
this.off('change', listener); unwatcher.close();
} }
/*var unwatch = new unwatchFile(); return unwatcher;
if(listener == nop){
unwatch.removeListeners();
}
else{
unwatch.removeSingleListener(listener);
}*/
}; };
// Deal with various approaches to node ID creation // Deal with various approaches to node ID creation

View File

@ -1,7 +1,7 @@
var EventEmitter = require('../lib/eventemitter.js'); var EventEmitter = require('../lib/eventemitter.js');
var Path = require('./path.js'); var Path = require('./path.js');
var Intercom = require('../lib/intercom.js'); var Intercom = require('../lib/intercom.js');
var _watchers = {};
/** /**
* FSWatcher based on node.js' FSWatcher * FSWatcher based on node.js' FSWatcher
* see https://github.com/joyent/node/blob/master/lib/fs.js * see https://github.com/joyent/node/blob/master/lib/fs.js
@ -45,11 +45,15 @@ function FSWatcher() {
if(recursive) { if(recursive) {
recursivePathPrefix = filename === '/' ? '/' : filename + '/'; recursivePathPrefix = filename === '/' ? '/' : filename + '/';
} }
_watchers[filename] = self;
var intercom = Intercom.getInstance(); var intercom = Intercom.getInstance();
intercom.on('change', onchange); intercom.on('change', onchange);
}; };
self.closeOneListener = function(filename){
_watchers[filename].close();
};
self.close = function() { self.close = function() {
var intercom = Intercom.getInstance(); var intercom = Intercom.getInstance();
intercom.off('change', onchange); intercom.off('change', onchange);
@ -58,5 +62,7 @@ function FSWatcher() {
} }
FSWatcher.prototype = new EventEmitter(); FSWatcher.prototype = new EventEmitter();
FSWatcher.prototype.constructor = FSWatcher; FSWatcher.prototype.constructor = FSWatcher;
FSWatcher.getWatcherForFilename = function(filename) {
return _watchers[filename];
};
module.exports = FSWatcher; module.exports = FSWatcher;