Ensure that log replay files are properly renamed on Windows

rename() without _unlink() before doesn't work on Windows.
This commits also adds an error message which was swallowed
previously.
This commit is contained in:
Michael Friedrich 2020-01-20 11:25:16 +01:00
parent 18eb06e334
commit 0da46c1d4b
1 changed files with 7 additions and 1 deletions

View File

@ -1193,7 +1193,13 @@ void ApiListener::RotateLogFile()
// If the log is being rotated more than once per second,
// don't overwrite the previous one, but silently deny rotation.
if (!Utility::PathExists(newpath)) {
(void) rename(oldpath.CStr(), newpath.CStr());
try {
Utility::RenameFile(oldpath, newpath);
} catch (const std::exception& ex) {
Log(LogCritical, "ApiListener")
<< "Cannot rotate replay log file from '" << oldpath << "' to '"
<< newpath << "': " << ex.what();
}
}
}