diff --git a/src/filesystem/interface.js b/src/filesystem/interface.js index c66dd71..789b0b8 100644 --- a/src/filesystem/interface.js +++ b/src/filesystem/interface.js @@ -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 diff --git a/src/fs-watcher.js b/src/fs-watcher.js index e236bcb..e7714e4 100644 --- a/src/fs-watcher.js +++ b/src/fs-watcher.js @@ -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;