diff options
Diffstat (limited to 'src/Common/libzip/zip_close.c')
-rw-r--r-- | src/Common/libzip/zip_close.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/Common/libzip/zip_close.c b/src/Common/libzip/zip_close.c index 26572261..2a9fed25 100644 --- a/src/Common/libzip/zip_close.c +++ b/src/Common/libzip/zip_close.c @@ -1,7 +1,7 @@ /* zip_close.c -- close zip archive and update changes - Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at <libzip@nih.at> @@ -72,10 +72,12 @@ zip_close(zip_t *za) { /* don't create zip files with no entries */ if (survivors == 0) { if ((za->open_flags & ZIP_TRUNCATE) || changed) { if (zip_source_remove(za->src) < 0) { - _zip_error_set_from_source(&za->error, za->src); - return -1; + if (!((zip_error_code_zip(zip_source_error(za->src)) == ZIP_ER_REMOVE) && (zip_error_code_system(zip_source_error(za->src)) == ENOENT))) { + _zip_error_set_from_source(&za->error, za->src); + return -1; + } } } zip_discard(za); return 0; @@ -157,16 +159,25 @@ zip_close(zip_t *za) { return -1; } } - _zip_progress_start(za->progress); + if (_zip_progress_start(za->progress) != 0) { + zip_error_set(&za->error, ZIP_ER_CANCELLED, 0); + zip_source_rollback_write(za->src); + free(filelist); + return -1; + } error = 0; for (j = 0; j < survivors; j++) { int new_data; zip_entry_t *entry; zip_dirent_t *de; - _zip_progress_subrange(za->progress, (double)j / (double)survivors, (double)(j + 1) / (double)survivors); + if (_zip_progress_subrange(za->progress, (double)j / (double)survivors, (double)(j + 1) / (double)survivors) != 0) { + zip_error_set(&za->error, ZIP_ER_CANCELLED, 0); + error = 1; + break; + } i = filelist[j].idx; entry = za->entry + i; @@ -255,12 +266,11 @@ zip_close(zip_t *za) { if (zip_source_commit_write(za->src) != 0) { _zip_error_set_from_source(&za->error, za->src); error = 1; } + _zip_progress_end(za->progress); } - _zip_progress_end(za->progress); - if (error) { zip_source_rollback_write(za->src); return -1; } @@ -542,9 +552,12 @@ copy_data(zip_t *za, zip_uint64_t len) { } len -= n; - _zip_progress_update(za->progress, (total - (double)len) / total); + if (_zip_progress_update(za->progress, (total - (double)len) / total) != 0) { + zip_error_set(&za->error, ZIP_ER_CANCELLED, 0); + return -1; + } } byte_array_fini(buf); return 0; @@ -575,9 +588,13 @@ copy_source(zip_t *za, zip_source_t *src, zip_int64_t data_length) { break; } if (n == BUFSIZE && za->progress && data_length > 0) { current += n; - _zip_progress_update(za->progress, (double)current / (double)data_length); + if (_zip_progress_update(za->progress, (double)current / (double)data_length) != 0) { + zip_error_set(&za->error, ZIP_ER_CANCELLED, 0); + ret = -1; + break; + } } } if (n < 0) { |