Skip to content

Commit

Permalink
Use fs.watchFile instead of fs.watch
Browse files Browse the repository at this point in the history
fs.watch doesn't play well with vim
  • Loading branch information
avital committed Jun 26, 2012
1 parent a39aabc commit b02f985
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions app/meteor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ var DependencyWatcher = function (deps, app_dir, on_change) {

self.app_dir = app_dir;
self.on_change = on_change;
self.watches = {}; // path => fs.watch handle
self.watches = {}; // path => unwatch function with no arguments
self.last_contents = {}; // path => last contents (array of filenames)
self.mtimes = {}; // path => last seen mtime

Expand Down Expand Up @@ -296,7 +296,7 @@ _.extend(DependencyWatcher.prototype, {
var self = this;
self.on_change = function () {};
for (var filepath in self.watches)
self.watches[filepath].close();
self.watches[filepath](); // unwatch
self.watches = {};
},

Expand Down Expand Up @@ -330,9 +330,8 @@ _.extend(DependencyWatcher.prototype, {

if (!stats) {
// A directory (or an uninteresting file) was removed
var watcher = self.watches[filepath];
if (watcher)
watcher.close();
var unwatch = self.watches[filepath];
unwatch && unwatch();
delete self.watches[filepath];
delete self.last_contents[filepath];
delete self.mtimes[filepath];
Expand All @@ -343,9 +342,18 @@ _.extend(DependencyWatcher.prototype, {
// monitor it if necessary
if (!(filepath in self.watches) &&
(is_interesting || stats.isDirectory())) {
self.watches[filepath] =
fs.watch(filepath, {interval: 500}, // poll a lot!
_.bind(self._scan, self, false, filepath));
if (!stats.isDirectory()) {
// Intentionally not using fs.watch since it doesn't play well with
// vim (https://github.com/joyent/node/issues/3172)
fs.watchFile(filepath, {interval: 500}, // poll a lot!
_.bind(self._scan, self, false, filepath));
self.watches[filepath] = function() { fs.unwatchFile(filepath); };
} else {
// fs.watchFile doesn't work for directories (as tested on ubuntu)
var watch = fs.watch(filepath, {interval: 500}, // poll a lot!
_.bind(self._scan, self, false, filepath));
self.watches[filepath] = function() { watch.close(); };
}
self.mtimes[filepath] = stats.mtime;
}

Expand Down

0 comments on commit b02f985

Please sign in to comment.