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.persistent === undefined) options.persistent = true;
|
||||||
if (options.interval === undefined) options.interval = 0;
|
if (options.interval === undefined) options.interval = 0;
|
||||||
|
|
||||||
if (filename in statWatchers) {
|
if (statWatchers[filename]) {
|
||||||
stat = statWatchers[filename];
|
stat = statWatchers[filename];
|
||||||
} else {
|
} else {
|
||||||
statWatchers[filename] = new fs.StatWatcher();
|
statWatchers[filename] = new fs.StatWatcher();
|
||||||
@ -331,7 +331,7 @@ exports.watchFile = function (filename) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.unwatchFile = function (filename) {
|
exports.unwatchFile = function (filename) {
|
||||||
if (filename in statWatchers) {
|
if (statWatchers[filename]) {
|
||||||
stat = statWatchers[filename];
|
stat = statWatchers[filename];
|
||||||
stat.stop();
|
stat.stop();
|
||||||
statWatchers[filename] = undefined;
|
statWatchers[filename] = undefined;
|
||||||
|
@ -9,12 +9,18 @@ var f2 = path.join(fixturesDir, "x2.txt");
|
|||||||
puts("watching for changes of " + f);
|
puts("watching for changes of " + f);
|
||||||
|
|
||||||
var changes = 0;
|
var changes = 0;
|
||||||
fs.watchFile(f, function (curr, prev) {
|
function watchFile () {
|
||||||
puts(f + " change");
|
fs.watchFile(f, function (curr, prev) {
|
||||||
changes++;
|
puts(f + " change");
|
||||||
assert.ok(curr.mtime != prev.mtime);
|
changes++;
|
||||||
fs.unwatchFile(f);
|
assert.ok(curr.mtime != prev.mtime);
|
||||||
});
|
fs.unwatchFile(f);
|
||||||
|
watchFile();
|
||||||
|
fs.unwatchFile(f);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
watchFile();
|
||||||
|
|
||||||
|
|
||||||
var fd = fs.openSync(f, "w+");
|
var fd = fs.openSync(f, "w+");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user