From 997d84bfa0b8c53144590547bcffdb6d30695e9b Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 17 Apr 2019 14:31:49 +0200 Subject: [PATCH] ApiListener#RotateLogFile(): don't overwrite previous log --- lib/remote/apilistener.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 8aea09159..a5bbb8079 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -1148,13 +1148,11 @@ void ApiListener::RotateLogFile() String oldpath = GetApiDir() + "log/current"; String newpath = GetApiDir() + "log/" + Convert::ToString(static_cast(ts)+1); - -#ifdef _WIN32 - _unlink(newpath.CStr()); -#endif /* _WIN32 */ - - - (void) rename(oldpath.CStr(), newpath.CStr()); + // 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()); + } } void ApiListener::LogGlobHandler(std::vector& files, const String& file)