diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-09-21 01:01:46 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-09-21 01:01:46 +0000 |
commit | 006e8628fc0a25c08df99f3b86d0c47f44aacc2b (patch) | |
tree | 823e77f5a3ede4ce1d3f4b32b460f2667545a0d8 /archival/unzip.c | |
parent | eef6077d7efe7c1b76f88f406379a47cee24729c (diff) | |
download | busybox-w32-006e8628fc0a25c08df99f3b86d0c47f44aacc2b.tar.gz busybox-w32-006e8628fc0a25c08df99f3b86d0c47f44aacc2b.tar.bz2 busybox-w32-006e8628fc0a25c08df99f3b86d0c47f44aacc2b.zip |
unzip: handle "central directory"
needed for OpenOffice, gmail attachment .zips etc
conditional on CONFIG_DESKTOP
function old new delta
unzip_main 1643 1939 +296
find_cds_offset - 173 +173
unzip_skip 11 16 +5
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 474/0) Total: 474 bytes
Diffstat (limited to 'archival/unzip.c')
-rw-r--r-- | archival/unzip.c | 243 |
1 files changed, 196 insertions, 47 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index 1c9bc246c..e468ff451 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -16,12 +16,7 @@ | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | /* TODO | 18 | /* TODO |
19 | * Endian issues | ||
20 | * Zip64 + other methods | 19 | * Zip64 + other methods |
21 | * Improve handling of zip format, ie. | ||
22 | * - deferred CRC, comp. & uncomp. lengths (zip header flags bit 3) | ||
23 | * - unix file permissions, etc. | ||
24 | * - central directory | ||
25 | */ | 20 | */ |
26 | 21 | ||
27 | #include "libbb.h" | 22 | #include "libbb.h" |
@@ -31,12 +26,12 @@ enum { | |||
31 | #if BB_BIG_ENDIAN | 26 | #if BB_BIG_ENDIAN |
32 | ZIP_FILEHEADER_MAGIC = 0x504b0304, | 27 | ZIP_FILEHEADER_MAGIC = 0x504b0304, |
33 | ZIP_CDS_MAGIC = 0x504b0102, | 28 | ZIP_CDS_MAGIC = 0x504b0102, |
34 | ZIP_CDS_END_MAGIC = 0x504b0506, | 29 | ZIP_CDE_MAGIC = 0x504b0506, |
35 | ZIP_DD_MAGIC = 0x504b0708, | 30 | ZIP_DD_MAGIC = 0x504b0708, |
36 | #else | 31 | #else |
37 | ZIP_FILEHEADER_MAGIC = 0x04034b50, | 32 | ZIP_FILEHEADER_MAGIC = 0x04034b50, |
38 | ZIP_CDS_MAGIC = 0x02014b50, | 33 | ZIP_CDS_MAGIC = 0x02014b50, |
39 | ZIP_CDS_END_MAGIC = 0x06054b50, | 34 | ZIP_CDE_MAGIC = 0x06054b50, |
40 | ZIP_DD_MAGIC = 0x08074b50, | 35 | ZIP_DD_MAGIC = 0x08074b50, |
41 | #endif | 36 | #endif |
42 | }; | 37 | }; |
@@ -46,16 +41,16 @@ enum { | |||
46 | typedef union { | 41 | typedef union { |
47 | uint8_t raw[ZIP_HEADER_LEN]; | 42 | uint8_t raw[ZIP_HEADER_LEN]; |
48 | struct { | 43 | struct { |
49 | uint16_t version; /* 0-1 */ | 44 | uint16_t version; /* 0-1 */ |
50 | uint16_t flags; /* 2-3 */ | 45 | uint16_t flags; /* 2-3 */ |
51 | uint16_t method; /* 4-5 */ | 46 | uint16_t method; /* 4-5 */ |
52 | uint16_t modtime; /* 6-7 */ | 47 | uint16_t modtime; /* 6-7 */ |
53 | uint16_t moddate; /* 8-9 */ | 48 | uint16_t moddate; /* 8-9 */ |
54 | uint32_t crc32 PACKED; /* 10-13 */ | 49 | uint32_t crc32 PACKED; /* 10-13 */ |
55 | uint32_t cmpsize PACKED; /* 14-17 */ | 50 | uint32_t cmpsize PACKED; /* 14-17 */ |
56 | uint32_t ucmpsize PACKED; /* 18-21 */ | 51 | uint32_t ucmpsize PACKED; /* 18-21 */ |
57 | uint16_t filename_len; /* 22-23 */ | 52 | uint16_t filename_len; /* 22-23 */ |
58 | uint16_t extra_len; /* 24-25 */ | 53 | uint16_t extra_len; /* 24-25 */ |
59 | } formatted PACKED; | 54 | } formatted PACKED; |
60 | } zip_header_t; /* PACKED - gcc 4.2.1 doesn't like it (spews warning) */ | 55 | } zip_header_t; /* PACKED - gcc 4.2.1 doesn't like it (spews warning) */ |
61 | 56 | ||
@@ -65,11 +60,11 @@ typedef union { | |||
65 | */ | 60 | */ |
66 | struct BUG_zip_header_must_be_26_bytes { | 61 | struct BUG_zip_header_must_be_26_bytes { |
67 | char BUG_zip_header_must_be_26_bytes[ | 62 | char BUG_zip_header_must_be_26_bytes[ |
68 | offsetof(zip_header_t, formatted.extra_len) + 2 == | 63 | offsetof(zip_header_t, formatted.extra_len) + 2 |
69 | ZIP_HEADER_LEN ? 1 : -1]; | 64 | == ZIP_HEADER_LEN ? 1 : -1]; |
70 | }; | 65 | }; |
71 | 66 | ||
72 | #define FIX_ENDIANNESS(zip_header) do { \ | 67 | #define FIX_ENDIANNESS_ZIP(zip_header) do { \ |
73 | (zip_header).formatted.version = SWAP_LE16((zip_header).formatted.version ); \ | 68 | (zip_header).formatted.version = SWAP_LE16((zip_header).formatted.version ); \ |
74 | (zip_header).formatted.flags = SWAP_LE16((zip_header).formatted.flags ); \ | 69 | (zip_header).formatted.flags = SWAP_LE16((zip_header).formatted.flags ); \ |
75 | (zip_header).formatted.method = SWAP_LE16((zip_header).formatted.method ); \ | 70 | (zip_header).formatted.method = SWAP_LE16((zip_header).formatted.method ); \ |
@@ -82,9 +77,138 @@ struct BUG_zip_header_must_be_26_bytes { | |||
82 | (zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \ | 77 | (zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \ |
83 | } while (0) | 78 | } while (0) |
84 | 79 | ||
85 | static void unzip_skip(int fd, off_t skip) | 80 | #define CDS_HEADER_LEN 42 |
81 | |||
82 | typedef union { | ||
83 | uint8_t raw[CDS_HEADER_LEN]; | ||
84 | struct { | ||
85 | /* uint32_t signature; 50 4b 01 02 */ | ||
86 | uint16_t version_made_by; /* 0-1 */ | ||
87 | uint16_t version_needed; /* 2-3 */ | ||
88 | uint16_t cds_flags; /* 4-5 */ | ||
89 | uint16_t method; /* 6-7 */ | ||
90 | uint16_t mtime; /* 8-9 */ | ||
91 | uint16_t mdate; /* 10-11 */ | ||
92 | uint32_t crc32; /* 12-15 */ | ||
93 | uint32_t cmpsize; /* 16-19 */ | ||
94 | uint32_t ucmpsize; /* 20-23 */ | ||
95 | uint16_t file_name_length; /* 24-25 */ | ||
96 | uint16_t extra_field_length; /* 26-27 */ | ||
97 | uint16_t file_comment_length; /* 28-29 */ | ||
98 | uint16_t disk_number_start; /* 30-31 */ | ||
99 | uint16_t internal_file_attributes; /* 32-33 */ | ||
100 | uint32_t external_file_attributes PACKED; /* 34-37 */ | ||
101 | uint32_t relative_offset_of_local_header PACKED; /* 38-41 */ | ||
102 | } formatted PACKED; | ||
103 | } cds_header_t; | ||
104 | |||
105 | struct BUG_cds_header_must_be_42_bytes { | ||
106 | char BUG_cds_header_must_be_42_bytes[ | ||
107 | offsetof(cds_header_t, formatted.relative_offset_of_local_header) + 4 | ||
108 | == CDS_HEADER_LEN ? 1 : -1]; | ||
109 | }; | ||
110 | |||
111 | #define FIX_ENDIANNESS_CDS(cds_header) do { \ | ||
112 | (cds_header).formatted.crc32 = SWAP_LE32((cds_header).formatted.crc32 ); \ | ||
113 | (cds_header).formatted.cmpsize = SWAP_LE32((cds_header).formatted.cmpsize ); \ | ||
114 | (cds_header).formatted.ucmpsize = SWAP_LE32((cds_header).formatted.ucmpsize ); \ | ||
115 | (cds_header).formatted.file_name_length = SWAP_LE16((cds_header).formatted.file_name_length); \ | ||
116 | (cds_header).formatted.extra_field_length = SWAP_LE16((cds_header).formatted.extra_field_length); \ | ||
117 | (cds_header).formatted.file_comment_length = SWAP_LE16((cds_header).formatted.file_comment_length); \ | ||
118 | } while (0) | ||
119 | |||
120 | #define CDE_HEADER_LEN 16 | ||
121 | |||
122 | typedef union { | ||
123 | uint8_t raw[CDE_HEADER_LEN]; | ||
124 | struct { | ||
125 | /* uint32_t signature; 50 4b 05 06 */ | ||
126 | uint16_t this_disk_no; | ||
127 | uint16_t disk_with_cds_no; | ||
128 | uint16_t cds_entries_on_this_disk; | ||
129 | uint16_t cds_entries_total; | ||
130 | uint32_t cds_size; | ||
131 | uint32_t cds_offset; | ||
132 | /* uint16_t file_comment_length; */ | ||
133 | /* .ZIP file comment (variable size) */ | ||
134 | } formatted PACKED; | ||
135 | } cde_header_t; | ||
136 | |||
137 | struct BUG_cde_header_must_be_16_bytes { | ||
138 | char BUG_cde_header_must_be_16_bytes[ | ||
139 | sizeof(cde_header_t) == CDE_HEADER_LEN ? 1 : -1]; | ||
140 | }; | ||
141 | |||
142 | #define FIX_ENDIANNESS_CDE(cde_header) do { \ | ||
143 | (cde_header).formatted.cds_offset = SWAP_LE16((cde_header).formatted.cds_offset); \ | ||
144 | } while (0) | ||
145 | |||
146 | enum { zip_fd = 3 }; | ||
147 | |||
148 | |||
149 | #if ENABLE_DESKTOP | ||
150 | /* NB: does not preserve file position! */ | ||
151 | static uint32_t find_cds_offset(void) | ||
152 | { | ||
153 | unsigned char buf[1024]; | ||
154 | cde_header_t cde_header; | ||
155 | unsigned char *p; | ||
156 | off_t end; | ||
157 | |||
158 | end = xlseek(zip_fd, 0, SEEK_END); | ||
159 | if (end < 1024) | ||
160 | end = 1024; | ||
161 | end -= 1024; | ||
162 | xlseek(zip_fd, end, SEEK_SET); | ||
163 | full_read(zip_fd, buf, 1024); | ||
164 | |||
165 | p = buf; | ||
166 | while (p <= buf + 1024 - CDE_HEADER_LEN - 4) { | ||
167 | if (*p != 'P') { | ||
168 | p++; | ||
169 | continue; | ||
170 | } | ||
171 | if (*++p != 'K') | ||
172 | continue; | ||
173 | if (*++p != 5) | ||
174 | continue; | ||
175 | if (*++p != 6) | ||
176 | continue; | ||
177 | /* we found CDE! */ | ||
178 | memcpy(cde_header.raw, p + 1, CDE_HEADER_LEN); | ||
179 | FIX_ENDIANNESS_CDE(cde_header); | ||
180 | return cde_header.formatted.cds_offset; | ||
181 | } | ||
182 | bb_error_msg_and_die("can't find file table"); | ||
183 | }; | ||
184 | |||
185 | static uint32_t read_next_cds(int count_m1, uint32_t cds_offset, cds_header_t *cds_ptr) | ||
86 | { | 186 | { |
87 | bb_copyfd_exact_size(fd, -1, skip); | 187 | off_t org; |
188 | |||
189 | org = xlseek(zip_fd, 0, SEEK_CUR); | ||
190 | |||
191 | if (!cds_offset) | ||
192 | cds_offset = find_cds_offset(); | ||
193 | |||
194 | while (count_m1-- >= 0) { | ||
195 | xlseek(zip_fd, cds_offset + 4, SEEK_SET); | ||
196 | xread(zip_fd, cds_ptr->raw, CDS_HEADER_LEN); | ||
197 | FIX_ENDIANNESS_CDS(*cds_ptr); | ||
198 | cds_offset += 4 + CDS_HEADER_LEN | ||
199 | + cds_ptr->formatted.file_name_length | ||
200 | + cds_ptr->formatted.extra_field_length | ||
201 | + cds_ptr->formatted.file_comment_length; | ||
202 | } | ||
203 | |||
204 | xlseek(zip_fd, org, SEEK_SET); | ||
205 | return cds_offset; | ||
206 | }; | ||
207 | #endif | ||
208 | |||
209 | static void unzip_skip(off_t skip) | ||
210 | { | ||
211 | bb_copyfd_exact_size(zip_fd, -1, skip); | ||
88 | } | 212 | } |
89 | 213 | ||
90 | static void unzip_create_leading_dirs(const char *fn) | 214 | static void unzip_create_leading_dirs(const char *fn) |
@@ -97,17 +221,17 @@ static void unzip_create_leading_dirs(const char *fn) | |||
97 | free(name); | 221 | free(name); |
98 | } | 222 | } |
99 | 223 | ||
100 | static void unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd) | 224 | static void unzip_extract(zip_header_t *zip_header, int dst_fd) |
101 | { | 225 | { |
102 | if (zip_header->formatted.method == 0) { | 226 | if (zip_header->formatted.method == 0) { |
103 | /* Method 0 - stored (not compressed) */ | 227 | /* Method 0 - stored (not compressed) */ |
104 | off_t size = zip_header->formatted.ucmpsize; | 228 | off_t size = zip_header->formatted.ucmpsize; |
105 | if (size) | 229 | if (size) |
106 | bb_copyfd_exact_size(src_fd, dst_fd, size); | 230 | bb_copyfd_exact_size(zip_fd, dst_fd, size); |
107 | } else { | 231 | } else { |
108 | /* Method 8 - inflate */ | 232 | /* Method 8 - inflate */ |
109 | inflate_unzip_result res; | 233 | inflate_unzip_result res; |
110 | if (inflate_unzip(&res, zip_header->formatted.cmpsize, src_fd, dst_fd) < 0) | 234 | if (inflate_unzip(&res, zip_header->formatted.cmpsize, zip_fd, dst_fd) < 0) |
111 | bb_error_msg_and_die("inflate error"); | 235 | bb_error_msg_and_die("inflate error"); |
112 | /* Validate decompression - crc */ | 236 | /* Validate decompression - crc */ |
113 | if (zip_header->formatted.crc32 != (res.crc ^ 0xffffffffL)) { | 237 | if (zip_header->formatted.crc32 != (res.crc ^ 0xffffffffL)) { |
@@ -131,9 +255,12 @@ int unzip_main(int argc, char **argv) | |||
131 | smallint verbose = 1; | 255 | smallint verbose = 1; |
132 | smallint listing = 0; | 256 | smallint listing = 0; |
133 | smallint overwrite = O_PROMPT; | 257 | smallint overwrite = O_PROMPT; |
258 | #if ENABLE_DESKTOP | ||
259 | uint32_t cds_offset; | ||
260 | unsigned cds_entries; | ||
261 | #endif | ||
134 | unsigned total_size; | 262 | unsigned total_size; |
135 | unsigned total_entries; | 263 | unsigned total_entries; |
136 | int src_fd = -1; | ||
137 | int dst_fd = -1; | 264 | int dst_fd = -1; |
138 | char *src_fn = NULL; | 265 | char *src_fn = NULL; |
139 | char *dst_fn = NULL; | 266 | char *dst_fn = NULL; |
@@ -221,13 +348,14 @@ int unzip_main(int argc, char **argv) | |||
221 | 348 | ||
222 | /* Open input file */ | 349 | /* Open input file */ |
223 | if (LONE_DASH(src_fn)) { | 350 | if (LONE_DASH(src_fn)) { |
224 | src_fd = STDIN_FILENO; | 351 | xdup2(STDIN_FILENO, zip_fd); |
225 | /* Cannot use prompt mode since zip data is arriving on STDIN */ | 352 | /* Cannot use prompt mode since zip data is arriving on STDIN */ |
226 | if (overwrite == O_PROMPT) | 353 | if (overwrite == O_PROMPT) |
227 | overwrite = O_NEVER; | 354 | overwrite = O_NEVER; |
228 | } else { | 355 | } else { |
229 | static const char extn[][5] = {"", ".zip", ".ZIP"}; | 356 | static const char extn[][5] = {"", ".zip", ".ZIP"}; |
230 | int orig_src_fn_len = strlen(src_fn); | 357 | int orig_src_fn_len = strlen(src_fn); |
358 | int src_fd = -1; | ||
231 | 359 | ||
232 | for (i = 0; (i < 3) && (src_fd == -1); i++) { | 360 | for (i = 0; (i < 3) && (src_fd == -1); i++) { |
233 | strcpy(src_fn + orig_src_fn_len, extn[i]); | 361 | strcpy(src_fn + orig_src_fn_len, extn[i]); |
@@ -237,6 +365,7 @@ int unzip_main(int argc, char **argv) | |||
237 | src_fn[orig_src_fn_len] = '\0'; | 365 | src_fn[orig_src_fn_len] = '\0'; |
238 | bb_error_msg_and_die("can't open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn); | 366 | bb_error_msg_and_die("can't open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn); |
239 | } | 367 | } |
368 | xmove_fd(src_fd, zip_fd); | ||
240 | } | 369 | } |
241 | 370 | ||
242 | /* Change dir if necessary */ | 371 | /* Change dir if necessary */ |
@@ -253,37 +382,63 @@ int unzip_main(int argc, char **argv) | |||
253 | 382 | ||
254 | total_size = 0; | 383 | total_size = 0; |
255 | total_entries = 0; | 384 | total_entries = 0; |
385 | #if ENABLE_DESKTOP | ||
386 | cds_entries = 0; | ||
387 | cds_offset = 0; | ||
388 | #endif | ||
256 | while (1) { | 389 | while (1) { |
257 | uint32_t magic; | 390 | uint32_t magic; |
258 | 391 | ||
259 | /* Check magic number */ | 392 | /* Check magic number */ |
260 | xread(src_fd, &magic, 4); | 393 | xread(zip_fd, &magic, 4); |
261 | /* Central directory? It's at the end, so exit */ | 394 | /* Central directory? It's at the end, so exit */ |
262 | if (magic == ZIP_CDS_MAGIC) | 395 | if (magic == ZIP_CDS_MAGIC) |
263 | break; | 396 | break; |
397 | #if ENABLE_DESKTOP | ||
398 | /* Data descriptor? It was a streaming file, go on */ | ||
399 | if (magic == ZIP_DD_MAGIC) { | ||
400 | /* skip over duplicate crc32, cmpsize and ucmpsize */ | ||
401 | unzip_skip(3 * 4); | ||
402 | continue; | ||
403 | } | ||
404 | #endif | ||
264 | if (magic != ZIP_FILEHEADER_MAGIC) | 405 | if (magic != ZIP_FILEHEADER_MAGIC) |
265 | bb_error_msg_and_die("invalid zip magic %08X", (int)magic); | 406 | bb_error_msg_and_die("invalid zip magic %08X", (int)magic); |
266 | 407 | ||
267 | /* Read the file header */ | 408 | /* Read the file header */ |
268 | xread(src_fd, zip_header.raw, ZIP_HEADER_LEN); | 409 | xread(zip_fd, zip_header.raw, ZIP_HEADER_LEN); |
269 | FIX_ENDIANNESS(zip_header); | 410 | FIX_ENDIANNESS_ZIP(zip_header); |
270 | if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) { | 411 | if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) { |
271 | bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method); | 412 | bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method); |
272 | } | 413 | } |
273 | if (zip_header.formatted.flags & (0x0008|0x0001)) { | 414 | #if !ENABLE_DESKTOP |
415 | if (zip_header.formatted.flags & 0x0009) { | ||
416 | bb_error_msg_and_die("zip flags 1 and 8 are not supported"); | ||
417 | } | ||
418 | #else | ||
419 | if (zip_header.formatted.flags & 0x0001) { | ||
274 | /* 0x0001 - encrypted */ | 420 | /* 0x0001 - encrypted */ |
421 | bb_error_msg_and_die("zip flag 1 (encryption) is not supported"); | ||
422 | } | ||
423 | if (zip_header.formatted.flags & 0x0008) { | ||
424 | cds_header_t cds_header; | ||
275 | /* 0x0008 - streaming. [u]cmpsize can be reliably gotten | 425 | /* 0x0008 - streaming. [u]cmpsize can be reliably gotten |
276 | * only from Central Directory. See unzip_doc.txt */ | 426 | * only from Central Directory. See unzip_doc.txt */ |
277 | bb_error_msg_and_die("zip flags 8 and 1 are not supported"); | 427 | cds_offset = read_next_cds(total_entries - cds_entries, cds_offset, &cds_header); |
428 | cds_entries = total_entries + 1; | ||
429 | zip_header.formatted.crc32 = cds_header.formatted.crc32; | ||
430 | zip_header.formatted.cmpsize = cds_header.formatted.cmpsize; | ||
431 | zip_header.formatted.ucmpsize = cds_header.formatted.ucmpsize; | ||
278 | } | 432 | } |
433 | #endif | ||
279 | 434 | ||
280 | /* Read filename */ | 435 | /* Read filename */ |
281 | free(dst_fn); | 436 | free(dst_fn); |
282 | dst_fn = xzalloc(zip_header.formatted.filename_len + 1); | 437 | dst_fn = xzalloc(zip_header.formatted.filename_len + 1); |
283 | xread(src_fd, dst_fn, zip_header.formatted.filename_len); | 438 | xread(zip_fd, dst_fn, zip_header.formatted.filename_len); |
284 | 439 | ||
285 | /* Skip extra header bytes */ | 440 | /* Skip extra header bytes */ |
286 | unzip_skip(src_fd, zip_header.formatted.extra_len); | 441 | unzip_skip(zip_header.formatted.extra_len); |
287 | 442 | ||
288 | /* Filter zip entries */ | 443 | /* Filter zip entries */ |
289 | if (find_list_entry(zreject, dst_fn) | 444 | if (find_list_entry(zreject, dst_fn) |
@@ -304,7 +459,6 @@ int unzip_main(int argc, char **argv) | |||
304 | (dostime & 0x000007e0) >> 5, | 459 | (dostime & 0x000007e0) >> 5, |
305 | dst_fn); | 460 | dst_fn); |
306 | total_size += zip_header.formatted.ucmpsize; | 461 | total_size += zip_header.formatted.ucmpsize; |
307 | total_entries++; | ||
308 | } else { | 462 | } else { |
309 | /* short listing -- filenames only */ | 463 | /* short listing -- filenames only */ |
310 | puts(dst_fn); | 464 | puts(dst_fn); |
@@ -315,7 +469,7 @@ int unzip_main(int argc, char **argv) | |||
315 | } else if (last_char_is(dst_fn, '/')) { /* Extract directory */ | 469 | } else if (last_char_is(dst_fn, '/')) { /* Extract directory */ |
316 | if (stat(dst_fn, &stat_buf) == -1) { | 470 | if (stat(dst_fn, &stat_buf) == -1) { |
317 | if (errno != ENOENT) { | 471 | if (errno != ENOENT) { |
318 | bb_perror_msg_and_die("cannot stat '%s'", dst_fn); | 472 | bb_perror_msg_and_die("can't stat '%s'", dst_fn); |
319 | } | 473 | } |
320 | if (verbose) { | 474 | if (verbose) { |
321 | printf(" creating: %s\n", dst_fn); | 475 | printf(" creating: %s\n", dst_fn); |
@@ -335,7 +489,7 @@ int unzip_main(int argc, char **argv) | |||
335 | check_file: | 489 | check_file: |
336 | if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */ | 490 | if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */ |
337 | if (errno != ENOENT) { | 491 | if (errno != ENOENT) { |
338 | bb_perror_msg_and_die("cannot stat '%s'", dst_fn); | 492 | bb_perror_msg_and_die("can't stat '%s'", dst_fn); |
339 | } | 493 | } |
340 | i = 'y'; | 494 | i = 'y'; |
341 | } else { /* File already exists */ | 495 | } else { /* File already exists */ |
@@ -347,7 +501,7 @@ int unzip_main(int argc, char **argv) | |||
347 | } else { | 501 | } else { |
348 | printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn); | 502 | printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn); |
349 | if (!fgets(key_buf, sizeof(key_buf), stdin)) { | 503 | if (!fgets(key_buf, sizeof(key_buf), stdin)) { |
350 | bb_perror_msg_and_die("cannot read input"); | 504 | bb_perror_msg_and_die("can't read input"); |
351 | } | 505 | } |
352 | i = key_buf[0]; | 506 | i = key_buf[0]; |
353 | } | 507 | } |
@@ -368,7 +522,7 @@ int unzip_main(int argc, char **argv) | |||
368 | if (verbose) { | 522 | if (verbose) { |
369 | printf(" inflating: %s\n", dst_fn); | 523 | printf(" inflating: %s\n", dst_fn); |
370 | } | 524 | } |
371 | unzip_extract(&zip_header, src_fd, dst_fd); | 525 | unzip_extract(&zip_header, dst_fd); |
372 | if (dst_fd != STDOUT_FILENO) { | 526 | if (dst_fd != STDOUT_FILENO) { |
373 | /* closing STDOUT is potentially bad for future business */ | 527 | /* closing STDOUT is potentially bad for future business */ |
374 | close(dst_fd); | 528 | close(dst_fd); |
@@ -379,14 +533,14 @@ int unzip_main(int argc, char **argv) | |||
379 | overwrite = O_NEVER; | 533 | overwrite = O_NEVER; |
380 | case 'n': | 534 | case 'n': |
381 | /* Skip entry data */ | 535 | /* Skip entry data */ |
382 | unzip_skip(src_fd, zip_header.formatted.cmpsize); | 536 | unzip_skip(zip_header.formatted.cmpsize); |
383 | break; | 537 | break; |
384 | 538 | ||
385 | case 'r': | 539 | case 'r': |
386 | /* Prompt for new name */ | 540 | /* Prompt for new name */ |
387 | printf("new name: "); | 541 | printf("new name: "); |
388 | if (!fgets(key_buf, sizeof(key_buf), stdin)) { | 542 | if (!fgets(key_buf, sizeof(key_buf), stdin)) { |
389 | bb_perror_msg_and_die("cannot read input"); | 543 | bb_perror_msg_and_die("can't read input"); |
390 | } | 544 | } |
391 | free(dst_fn); | 545 | free(dst_fn); |
392 | dst_fn = xstrdup(key_buf); | 546 | dst_fn = xstrdup(key_buf); |
@@ -398,12 +552,7 @@ int unzip_main(int argc, char **argv) | |||
398 | goto check_file; | 552 | goto check_file; |
399 | } | 553 | } |
400 | 554 | ||
401 | // Looks like bug (data descriptor cannot be identified this way) | 555 | total_entries++; |
402 | // /* Data descriptor section */ | ||
403 | // if (zip_header.formatted.flags & 4) { | ||
404 | // /* skip over duplicate crc, compressed size and uncompressed size */ | ||
405 | // unzip_skip(src_fd, 12); | ||
406 | // } | ||
407 | } | 556 | } |
408 | 557 | ||
409 | if (listing && verbose) { | 558 | if (listing && verbose) { |