0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

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.
This commit is contained in:
Johan Dahlberg 2010-03-30 15:27:23 +02:00 committed by Ryan Dahl
parent aec80d47bb
commit 18de108e4c
2 changed files with 14 additions and 8 deletions

View File

@ -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;

View File

@ -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+");