Fixes bug introduced in github issue #132 where renaming a file to itself can cause an unhandled error

flush-on-exit
Issac Goldstand 12 years ago
parent ad8229145e
commit 2da01cc611

@ -23,10 +23,12 @@ function DateRollingFileStream(filename, pattern, options, now) {
this.pattern = pattern || '.yyyy-MM-dd';
this.now = now || Date.now;
this.lastTimeWeWroteSomething = format.asString(this.pattern, new Date(this.now()));
this.alwaysIncludePattern = false;
this.baseFilename = filename;
if (options) {
if (options.alwaysIncludePattern) {
this.alwaysIncludePattern = true;
filename = filename + this.lastTimeWeWroteSomething;
}
delete options.alwaysIncludePattern;
@ -75,8 +77,13 @@ DateRollingFileStream.prototype.roll = function(filename, callback) {
}
function renameTheCurrentFile(cb) {
debug("Renaming the " + filename + " -> " + newFilename);
fs.rename(filename, newFilename, cb);
if (this.alwaysIncludePattern) {
// no-op
cb();
} else {
debug("Renaming the " + filename + " -> " + newFilename);
fs.rename(filename, newFilename, cb);
}
}
};

Loading…
Cancel
Save