Fix log rotation

This commit is contained in:
Cameron Gutman
2019-03-28 19:42:09 -07:00
parent 0941cc5bc1
commit 1bc6cc5634
+4 -3
View File
@@ -752,11 +752,12 @@ void ResetLogFile()
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-old.log", oldLogFilePath, sizeof(oldLogFilePath)); ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-old.log", oldLogFilePath, sizeof(oldLogFilePath));
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-current.log", currentLogFilePath, sizeof(currentLogFilePath)); ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-current.log", currentLogFilePath, sizeof(currentLogFilePath));
// Delete the old log file // Close the existing stdout handle. This is important because otherwise
DeleteFileA(oldLogFilePath); // it may still be open as stdout when we try to MoveFileEx below.
fclose(stdout);
// Rotate the current to the old log file // Rotate the current to the old log file
MoveFileA(currentLogFilePath, oldLogFilePath); MoveFileExA(currentLogFilePath, oldLogFilePath, MOVEFILE_REPLACE_EXISTING);
// Redirect stdout to this new file // Redirect stdout to this new file
freopen(currentLogFilePath, "w", stdout); freopen(currentLogFilePath, "w", stdout);