From 1bc6cc5634cded23be1e2486c358ca0f63839577 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 28 Mar 2019 19:42:09 -0700 Subject: [PATCH] Fix log rotation --- miss/miss.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/miss/miss.cpp b/miss/miss.cpp index cf23657..a3ef211 100644 --- a/miss/miss.cpp +++ b/miss/miss.cpp @@ -752,11 +752,12 @@ void ResetLogFile() ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-old.log", oldLogFilePath, sizeof(oldLogFilePath)); ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-current.log", currentLogFilePath, sizeof(currentLogFilePath)); - // Delete the old log file - DeleteFileA(oldLogFilePath); + // Close the existing stdout handle. This is important because otherwise + // it may still be open as stdout when we try to MoveFileEx below. + fclose(stdout); - // Rotate the current to the old log file - MoveFileA(currentLogFilePath, oldLogFilePath); + // Rotate the current to the old log file + MoveFileExA(currentLogFilePath, oldLogFilePath, MOVEFILE_REPLACE_EXISTING); // Redirect stdout to this new file freopen(currentLogFilePath, "w", stdout);