mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 17:23:01 +01: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:
parent
53a7530e8a
commit
0554bf0240
11
src/log.c
11
src/log.c
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user