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:
parent
aec80d47bb
commit
18de108e4c
@ -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;
|
||||
|
@ -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…
Reference in New Issue
Block a user