From 0da46c1d4bacd34576150654c2f4e35c74c31568 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 20 Jan 2020 11:25:16 +0100 Subject: [PATCH] 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. --- lib/remote/apilistener.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 5566affca..6f4b42164 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -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(); + } } }