Skip to content

Commit 0f747f9

Browse files
rscharfegitster
authored andcommitted
archive-zip: use a local variable to store the creator version
Use a simpler conditional right next to the code which makes a higher creator version necessary -- namely symlink handling and support for executable files -- instead of a long line with a ternary operator. The resulting code has more lines but is simpler and allows reuse of the value easily. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 19ee294 commit 0f747f9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

archive-zip.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ static int write_zip_entry(struct archiver_args *args,
223223
unsigned long size;
224224
int is_binary = -1;
225225
const char *path_without_prefix = path + args->baselen;
226+
unsigned int creator_version = 0;
226227

227228
crc = crc32(0, NULL, 0);
228229

@@ -251,6 +252,8 @@ static int write_zip_entry(struct archiver_args *args,
251252
method = 0;
252253
attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
253254
(mode & 0111) ? ((mode) << 16) : 0;
255+
if (S_ISLNK(mode) || (mode & 0111))
256+
creator_version = 0x0317;
254257
if (S_ISREG(mode) && args->compression_level != 0 && size > 0)
255258
method = 8;
256259

@@ -303,8 +306,7 @@ static int write_zip_entry(struct archiver_args *args,
303306
}
304307

305308
copy_le32(dirent.magic, 0x02014b50);
306-
copy_le16(dirent.creator_version,
307-
S_ISLNK(mode) || (S_ISREG(mode) && (mode & 0111)) ? 0x0317 : 0);
309+
copy_le16(dirent.creator_version, creator_version);
308310
copy_le16(dirent.version, 10);
309311
copy_le16(dirent.flags, flags);
310312
copy_le16(dirent.compression_method, method);

0 commit comments

Comments
 (0)