1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-06-19 00:16:35 +02:00

Create backup of duplicate log file instead of deleting it

This case should never occur, but just in case it does it's good to handle it
without any data loss
This commit is contained in:
jfreegman
2020-11-18 17:19:08 -05:00
parent 53a7530e8a
commit 0554bf0240

View File

@ -358,8 +358,15 @@ int rename_logfile(const char *src, const char *dest, const char *selfkey, const
}
if (file_exists(newpath)) {
if (remove(oldpath) != 0) {
fprintf(stderr, "Failed to remove old path `%s`\n", oldpath);
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;
}
} else {
if (rename(oldpath, newpath) != 0) {