Skip to content

Commit 134a199

Browse files
committed
Remove ZIP_CM_REPLACED_DEFAULT, use chagned flag ZIP_DIRENT_COMP_METHOD instead.
1 parent 542fc1c commit 134a199

6 files changed

Lines changed: 7 additions & 28 deletions

File tree

lib/zip_close.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static int add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de) {
326326
st.comp_method = ZIP_CM_STORE;
327327
}
328328

329-
if (de->comp_method == ZIP_CM_REPLACED_DEFAULT && st.comp_method != ZIP_CM_STORE) {
329+
if ((de->changed & ZIP_DIRENT_COMP_METHOD) == 0 && st.comp_method != ZIP_CM_STORE) {
330330
de->comp_method = st.comp_method;
331331
}
332332
else if (de->comp_method == ZIP_CM_STORE && (st.valid & ZIP_STAT_SIZE)) {
@@ -356,13 +356,14 @@ static int add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de) {
356356
}
357357
else {
358358
de->uncomp_size = st.size;
359-
/* this is technically incorrect (copy_source counts compressed data), but it's the best we have */
360-
data_length = (zip_int64_t)st.size;
361359

362360
if ((st.valid & ZIP_STAT_COMP_SIZE) == 0) {
363361
zip_uint64_t max_compressed_size;
364362
zip_uint16_t compression_method = ZIP_CM_ACTUAL(de->comp_method);
365363

364+
/* this is technically incorrect (copy_source counts compressed data), but it's the best we have */
365+
data_length = (zip_int64_t)st.size;
366+
366367
if (compression_method == ZIP_CM_STORE) {
367368
max_compressed_size = st.size;
368369
}

lib/zip_file_replace.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,6 @@ _zip_file_replace(zip_t *za, zip_uint64_t idx, const char *name, zip_source_t *s
9393
* needed for a double add of the same file name */
9494
_zip_unchange_data(za->entry + idx);
9595

96-
if (za->entry[idx].orig != NULL && (za->entry[idx].changes == NULL || (za->entry[idx].changes->changed & ZIP_DIRENT_COMP_METHOD) == 0)) {
97-
if (za->entry[idx].changes == NULL) {
98-
if ((za->entry[idx].changes = _zip_dirent_clone(za->entry[idx].orig)) == NULL) {
99-
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
100-
return -1;
101-
}
102-
}
103-
104-
za->entry[idx].changes->comp_method = ZIP_CM_REPLACED_DEFAULT;
105-
za->entry[idx].changes->changed |= ZIP_DIRENT_COMP_METHOD;
106-
}
107-
10896
za->entry[idx].source = source;
10997

11098
return (zip_int64_t)idx;

lib/zip_source_compress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static struct context *context_new(zip_int32_t method, bool compress, zip_uint32
161161
return NULL;
162162
}
163163
zip_error_init(&ctx->error);
164-
ctx->can_store = compress ? ZIP_CM_IS_DEFAULT(method) : false;
164+
ctx->can_store = compress ? method == ZIP_CM_DEFAULT : false;
165165
ctx->algorithm = algorithm;
166166
ctx->method = method;
167167
ctx->compress = compress;

lib/zip_stat_index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ zip_stat_index(zip_t *za, zip_uint64_t index, zip_flags_t flags, zip_stat_t *st)
5858
return -1;
5959
}
6060

61-
if (ZIP_CM_IS_DEFAULT(de->comp_method)) {
61+
if (de->comp_method == ZIP_CM_DEFAULT) {
6262
if (!(st->valid & ZIP_STAT_COMP_METHOD) || st->comp_method == ZIP_CM_STORE) {
6363
st->valid &= ~(ZIP_STAT_COMP_SIZE|ZIP_STAT_COMP_METHOD);
6464
}

lib/zip_unchange_data.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,5 @@ _zip_unchange_data(zip_entry_t *ze) {
4141
ze->source = NULL;
4242
}
4343

44-
if (ze->changes != NULL && (ze->changes->changed & ZIP_DIRENT_COMP_METHOD) && ze->changes->comp_method == ZIP_CM_REPLACED_DEFAULT) {
45-
ze->changes->changed &= ~ZIP_DIRENT_COMP_METHOD;
46-
if (ze->changes->changed == 0) {
47-
_zip_dirent_free(ze->changes);
48-
ze->changes = NULL;
49-
}
50-
}
51-
5244
ze->deleted = 0;
5345
}

lib/zipint.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878

7979
#define ZIP_CRYPTO_PKWARE_HEADERLEN 12
8080

81-
#define ZIP_CM_REPLACED_DEFAULT (-2)
8281
#define ZIP_CM_WINZIP_AES 99 /* Winzip AES encrypted */
8382

8483
#define WINZIP_AES_PASSWORD_VERIFY_LENGTH 2
@@ -87,8 +86,7 @@
8786
#define HMAC_LENGTH 10
8887
#define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16))
8988

90-
#define ZIP_CM_IS_DEFAULT(x) ((x) == ZIP_CM_DEFAULT || (x) == ZIP_CM_REPLACED_DEFAULT)
91-
#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)(ZIP_CM_IS_DEFAULT(x) ? ZIP_CM_DEFLATE : (x)))
89+
#define ZIP_CM_ACTUAL(x) ((zip_uint16_t)((x) == ZIP_CM_DEFAULT ? ZIP_CM_DEFLATE : (x)))
9290

9391
#define ZIP_EF_UTF_8_COMMENT 0x6375
9492
#define ZIP_EF_UTF_8_NAME 0x7075

0 commit comments

Comments
 (0)