Fix log backup logic 50/265950/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 2 Nov 2021 08:26:27 +0000 (17:26 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 2 Nov 2021 08:26:27 +0000 (17:26 +0900)
Rotation logic was not working properly because
std::remove() with file which is not exists will return negative integer.

Change-Id: I2f1b1b792e306024af4545e4586fb5069a0330d9
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/utils/file_logbackend.cc

index 4f034bc..a30d5f6 100644 (file)
@@ -52,6 +52,11 @@ void FileLogBackend::WriteLogToFile() {
 bool FileLogBackend::Rotate() {
   for (int i = max_rotation_; i > 0; i--) {
     std::string old_log = file_name_ + "." + std::to_string(i);
+
+    struct stat tmp_buffer;
+    if (stat(old_log.c_str(), &tmp_buffer) != 0)
+      continue;
+
     // the oldest log will be removed
     if (i == max_rotation_) {
       if (std::remove(old_log.c_str()) != 0)