mirror of
https://github.com/zlib-ng/minizip-ng
synced 2026-08-25 14:26:08 -04:00
Refactor file rename error handling when backup fails
This commit is contained in:
parent
2dcae48df3
commit
d2d6b76d79
1 changed files with 8 additions and 3 deletions
11
minizip.c
11
minizip.c
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue