Browse Source

Bugfix: watchFile, unwatch, watch causes error

Fixed bug that caused application to cast a "TypeError: Cannot call method
'addListener' of undefined" when first watching a file, unwatching and then
watching same file again.
v0.7.4-release
Johan Dahlberg 15 years ago
committed by Ryan Dahl
parent
commit
18de108e4c
  1. 4
      lib/fs.js
  2. 18
      test/pummel/test-watch-file.js

4
lib/fs.js

@ -319,7 +319,7 @@ exports.watchFile = function (filename) {
if (options.persistent === undefined) options.persistent = true;
if (options.interval === undefined) options.interval = 0;
if (filename in statWatchers) {
if (statWatchers[filename]) {
stat = statWatchers[filename];
} else {
statWatchers[filename] = new fs.StatWatcher();
@ -331,7 +331,7 @@ exports.watchFile = function (filename) {
};
exports.unwatchFile = function (filename) {
if (filename in statWatchers) {
if (statWatchers[filename]) {
stat = statWatchers[filename];
stat.stop();
statWatchers[filename] = undefined;

18
test/pummel/test-watch-file.js

@ -9,12 +9,18 @@ var f2 = path.join(fixturesDir, "x2.txt");
puts("watching for changes of " + f);
var changes = 0;
fs.watchFile(f, function (curr, prev) {
puts(f + " change");
changes++;
assert.ok(curr.mtime != prev.mtime);
fs.unwatchFile(f);
});
function watchFile () {
fs.watchFile(f, function (curr, prev) {
puts(f + " change");
changes++;
assert.ok(curr.mtime != prev.mtime);
fs.unwatchFile(f);
watchFile();
fs.unwatchFile(f);
});
}
watchFile();
var fd = fs.openSync(f, "w+");

Loading…
Cancel
Save