From f10a6e164e15dc1249f62a6e9ff8eb39f7d5c7d6 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Thu, 24 Nov 2011 08:37:05 +1100 Subject: [PATCH] windows throws an EEXIST error when renaming, need to handle it --- lib/appenders/file.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/appenders/file.js b/lib/appenders/file.js index 6ea01ca..c6be910 100644 --- a/lib/appenders/file.js +++ b/lib/appenders/file.js @@ -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)); } }