windows throws an EEXIST error when renaming, need to handle it
This commit is contained in:
parent
cea3dc97d1
commit
f10a6e164e
@ -54,6 +54,14 @@ function fileAppender (file, layout, logSize, numBackups) {
|
||||
function increaseFileIndex (fileToRename) {
|
||||
var idx = index(fileToRename);
|
||||
if (idx < numBackups) {
|
||||
//on windows, you can get a EEXIST error if you rename a file to an existing file
|
||||
//so, we'll try to delete the file we're renaming to first
|
||||
try {
|
||||
fs.unlinkSync(file + '.' + (idx+1));
|
||||
} catch (e) {
|
||||
//couldn't delete, but that could be because it doesn't exist
|
||||
//try renaming anyway
|
||||
}
|
||||
fs.renameSync(path.join(path.dirname(file), fileToRename), file + '.' + (idx + 1));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user