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

View File

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