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.
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();
};
exports.unwatchFile = function (filename) {
- if (filename in statWatchers) {
+ if (statWatchers[filename]) {
stat = statWatchers[filename];
stat.stop();
statWatchers[filename] = undefined;
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+");