From b9180f8f5ae414aa94cc9379b92a84fff00e049a Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 10 Jul 2018 14:33:38 +0300 Subject: [PATCH] Fix to a windows issue, where very high rotation rates sometimes fail if antivirus is running. --- include/spdlog/sinks/rotating_file_sink.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/spdlog/sinks/rotating_file_sink.h b/include/spdlog/sinks/rotating_file_sink.h index dbbc75cd..84c71799 100644 --- a/include/spdlog/sinks/rotating_file_sink.h +++ b/include/spdlog/sinks/rotating_file_sink.h @@ -95,7 +95,14 @@ private: } if (details::file_helper::file_exists(src) && details::os::rename(src, target) != 0) { - throw spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno); + // if failed try again after small delay. + // this is a workaround to a windows issue, where on high rotation rates the rename fails sometimes (because of antivirus?). + details::os::sleep_for_millis(20); + details::os::remove(target); + if (details::os::rename(src, target) != 0) + { + throw spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno); + } } } file_helper_.reopen(true);