From c4c0c0d1f48cd93054d219939a0eab51bb0edf07 Mon Sep 17 00:00:00 2001 From: jfreegman Date: Tue, 24 Nov 2020 21:47:21 -0500 Subject: [PATCH] Another logging fix When renaming a log file, if the new name already exists we just start appending to it and delete the old file. There's no need to create a backup. This fixes an issue where leaving and rejoining the same group multiple times will eventually lead to the logger not working due to trying to use the same file name over and over again. --- src/log.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/log.c b/src/log.c index 30f113f..c15e52f 100644 --- a/src/log.c +++ b/src/log.c @@ -358,19 +358,8 @@ int rename_logfile(const char *src, const char *dest, const char *selfkey, const } if (file_exists(newpath)) { - char new_backup[MAX_STR_SIZE + 4]; - snprintf(new_backup, sizeof(new_backup), "%s.old", newpath); - - if (file_exists(new_backup)) { - goto on_error; - } - - if (rename(newpath, new_backup) != 0) { - goto on_error; - } - } - - if (rename(oldpath, newpath) != 0) { + remove(oldpath); + } else if (rename(oldpath, newpath) != 0) { goto on_error; }