Refactor file rename error handling when backup fails

This commit is contained in:
Paul Marquess 2026-03-11 16:10:49 +00:00 committed by Nathan Moinvaziri
parent 2dcae48df3
commit d2d6b76d79
No known key found for this signature in database

View file

@ -532,11 +532,16 @@ int32_t minizip_erase(const char *src_path, const char *target_path, int32_t arg
if (mz_os_file_exists(bak_path) == MZ_OK)
mz_os_unlink(bak_path);
if (mz_os_rename(src_path, bak_path) != MZ_OK)
err = mz_os_rename(src_path, bak_path);
if (err != MZ_OK) {
printf("Error backing up archive before replacing %s\n", bak_path);
} else {
err = mz_os_rename(tmp_path, src_path);
if (err != MZ_OK)
printf("Error replacing archive with temp %s\n", tmp_path);
}
if (mz_os_rename(tmp_path, src_path) != MZ_OK)
printf("Error replacing archive with temp %s\n", tmp_path);
return err;
}
return MZ_OK;