208 |
|
|
209 |
static void unzip_skip(off_t skip) |
static void unzip_skip(off_t skip) |
210 |
{ |
{ |
211 |
bb_copyfd_exact_size(zip_fd, -1, skip); |
if (lseek(zip_fd, skip, SEEK_CUR) == (off_t)-1) |
212 |
|
bb_copyfd_exact_size(zip_fd, -1, skip); |
213 |
} |
} |
214 |
|
|
215 |
static void unzip_create_leading_dirs(const char *fn) |
static void unzip_create_leading_dirs(const char *fn) |
253 |
enum { O_PROMPT, O_NEVER, O_ALWAYS }; |
enum { O_PROMPT, O_NEVER, O_ALWAYS }; |
254 |
|
|
255 |
zip_header_t zip_header; |
zip_header_t zip_header; |
256 |
smallint verbose = 1; |
smallint quiet = 0; |
257 |
|
IF_NOT_DESKTOP(const) smallint verbose = 0; |
258 |
smallint listing = 0; |
smallint listing = 0; |
259 |
smallint overwrite = O_PROMPT; |
smallint overwrite = O_PROMPT; |
260 |
#if ENABLE_DESKTOP |
#if ENABLE_DESKTOP |
261 |
uint32_t cds_offset; |
uint32_t cds_offset; |
262 |
unsigned cds_entries; |
unsigned cds_entries; |
263 |
#endif |
#endif |
264 |
unsigned total_size; |
unsigned long total_usize; |
265 |
|
unsigned long total_size; |
266 |
unsigned total_entries; |
unsigned total_entries; |
267 |
int dst_fd = -1; |
int dst_fd = -1; |
268 |
char *src_fn = NULL; |
char *src_fn = NULL; |
275 |
char key_buf[80]; |
char key_buf[80]; |
276 |
struct stat stat_buf; |
struct stat stat_buf; |
277 |
|
|
278 |
|
/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP: |
279 |
|
* |
280 |
|
* # /usr/bin/unzip -qq -v decompress_unlzma.i.zip |
281 |
|
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i |
282 |
|
* # /usr/bin/unzip -q -v decompress_unlzma.i.zip |
283 |
|
* Length Method Size Ratio Date Time CRC-32 Name |
284 |
|
* -------- ------ ------- ----- ---- ---- ------ ---- |
285 |
|
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i |
286 |
|
* -------- ------- --- ------- |
287 |
|
* 204372 35278 83% 1 file |
288 |
|
* # /usr/bin/unzip -v decompress_unlzma.i.zip |
289 |
|
* Archive: decompress_unlzma.i.zip |
290 |
|
* Length Method Size Ratio Date Time CRC-32 Name |
291 |
|
* -------- ------ ------- ----- ---- ---- ------ ---- |
292 |
|
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i |
293 |
|
* -------- ------- --- ------- |
294 |
|
* 204372 35278 83% 1 file |
295 |
|
* # unzip -v decompress_unlzma.i.zip |
296 |
|
* Archive: decompress_unlzma.i.zip |
297 |
|
* Length Date Time Name |
298 |
|
* -------- ---- ---- ---- |
299 |
|
* 204372 09-06-09 14:23 decompress_unlzma.i |
300 |
|
* -------- ------- |
301 |
|
* 204372 1 files |
302 |
|
* # /usr/bin/unzip -l -qq decompress_unlzma.i.zip |
303 |
|
* 204372 09-06-09 14:23 decompress_unlzma.i |
304 |
|
* # /usr/bin/unzip -l -q decompress_unlzma.i.zip |
305 |
|
* Length Date Time Name |
306 |
|
* -------- ---- ---- ---- |
307 |
|
* 204372 09-06-09 14:23 decompress_unlzma.i |
308 |
|
* -------- ------- |
309 |
|
* 204372 1 file |
310 |
|
* # /usr/bin/unzip -l decompress_unlzma.i.zip |
311 |
|
* Archive: decompress_unlzma.i.zip |
312 |
|
* Length Date Time Name |
313 |
|
* -------- ---- ---- ---- |
314 |
|
* 204372 09-06-09 14:23 decompress_unlzma.i |
315 |
|
* -------- ------- |
316 |
|
* 204372 1 file |
317 |
|
*/ |
318 |
|
|
319 |
/* '-' makes getopt return 1 for non-options */ |
/* '-' makes getopt return 1 for non-options */ |
320 |
while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) { |
while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) { |
321 |
switch (opt_range) { |
switch (opt_range) { |
322 |
case 0: /* Options */ |
case 0: /* Options */ |
323 |
switch (opt) { |
switch (opt) { |
337 |
dst_fd = STDOUT_FILENO; |
dst_fd = STDOUT_FILENO; |
338 |
|
|
339 |
case 'q': /* Be quiet */ |
case 'q': /* Be quiet */ |
340 |
verbose = 0; |
quiet++; |
341 |
|
break; |
342 |
|
|
343 |
|
case 'v': /* Verbose list */ |
344 |
|
IF_DESKTOP(verbose++;) |
345 |
|
listing = 1; |
346 |
break; |
break; |
347 |
|
|
348 |
case 1: /* The zip file */ |
case 1: /* The zip file */ |
421 |
if (base_dir) |
if (base_dir) |
422 |
xchdir(base_dir); |
xchdir(base_dir); |
423 |
|
|
424 |
if (verbose) { |
if (quiet <= 1) { /* not -qq */ |
425 |
printf("Archive: %s\n", src_fn); |
if (quiet == 0) |
426 |
if (listing){ |
printf("Archive: %s\n", src_fn); |
427 |
puts(" Length Date Time Name\n" |
if (listing) { |
428 |
" -------- ---- ---- ----"); |
puts(verbose ? |
429 |
|
" Length Method Size Ratio Date Time CRC-32 Name\n" |
430 |
|
"-------- ------ ------- ----- ---- ---- ------ ----" |
431 |
|
: |
432 |
|
" Length Date Time Name\n" |
433 |
|
" -------- ---- ---- ----" |
434 |
|
); |
435 |
} |
} |
436 |
} |
} |
437 |
|
|
438 |
|
total_usize = 0; |
439 |
total_size = 0; |
total_size = 0; |
440 |
total_entries = 0; |
total_entries = 0; |
441 |
#if ENABLE_DESKTOP |
#if ENABLE_DESKTOP |
504 |
|
|
505 |
} else { /* Extract entry */ |
} else { /* Extract entry */ |
506 |
if (listing) { /* List entry */ |
if (listing) { /* List entry */ |
507 |
if (verbose) { |
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); |
508 |
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); |
if (!verbose) { |
509 |
printf("%9u %02u-%02u-%02u %02u:%02u %s\n", |
// " Length Date Time Name\n" |
510 |
zip_header.formatted.ucmpsize, |
// " -------- ---- ---- ----" |
511 |
(dostime & 0x01e00000) >> 21, |
printf( "%9u %02u-%02u-%02u %02u:%02u %s\n", |
512 |
(dostime & 0x001f0000) >> 16, |
(unsigned)zip_header.formatted.ucmpsize, |
513 |
(((dostime & 0xfe000000) >> 25) + 1980) % 100, |
(dostime & 0x01e00000) >> 21, |
514 |
(dostime & 0x0000f800) >> 11, |
(dostime & 0x001f0000) >> 16, |
515 |
(dostime & 0x000007e0) >> 5, |
(((dostime & 0xfe000000) >> 25) + 1980) % 100, |
516 |
dst_fn); |
(dostime & 0x0000f800) >> 11, |
517 |
total_size += zip_header.formatted.ucmpsize; |
(dostime & 0x000007e0) >> 5, |
518 |
|
dst_fn); |
519 |
|
total_usize += zip_header.formatted.ucmpsize; |
520 |
} else { |
} else { |
521 |
/* short listing -- filenames only */ |
unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize; |
522 |
puts(dst_fn); |
percents = percents * 100; |
523 |
|
if (zip_header.formatted.ucmpsize) |
524 |
|
percents /= zip_header.formatted.ucmpsize; |
525 |
|
// " Length Method Size Ratio Date Time CRC-32 Name\n" |
526 |
|
// "-------- ------ ------- ----- ---- ---- ------ ----" |
527 |
|
printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n", |
528 |
|
(unsigned)zip_header.formatted.ucmpsize, |
529 |
|
(unsigned)zip_header.formatted.cmpsize, |
530 |
|
(unsigned)percents, |
531 |
|
(dostime & 0x01e00000) >> 21, |
532 |
|
(dostime & 0x001f0000) >> 16, |
533 |
|
(((dostime & 0xfe000000) >> 25) + 1980) % 100, |
534 |
|
(dostime & 0x0000f800) >> 11, |
535 |
|
(dostime & 0x000007e0) >> 5, |
536 |
|
zip_header.formatted.crc32, |
537 |
|
dst_fn); |
538 |
|
total_usize += zip_header.formatted.ucmpsize; |
539 |
|
total_size += zip_header.formatted.cmpsize; |
540 |
} |
} |
541 |
i = 'n'; |
i = 'n'; |
542 |
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ |
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ |
546 |
if (errno != ENOENT) { |
if (errno != ENOENT) { |
547 |
bb_perror_msg_and_die("can't stat '%s'", dst_fn); |
bb_perror_msg_and_die("can't stat '%s'", dst_fn); |
548 |
} |
} |
549 |
if (verbose) { |
if (!quiet) { |
550 |
printf(" creating: %s\n", dst_fn); |
printf(" creating: %s\n", dst_fn); |
551 |
} |
} |
552 |
unzip_create_leading_dirs(dst_fn); |
unzip_create_leading_dirs(dst_fn); |
594 |
unzip_create_leading_dirs(dst_fn); |
unzip_create_leading_dirs(dst_fn); |
595 |
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC); |
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC); |
596 |
case -1: /* Unzip */ |
case -1: /* Unzip */ |
597 |
if (verbose) { |
if (!quiet) { |
598 |
printf(" inflating: %s\n", dst_fn); |
printf(" inflating: %s\n", dst_fn); |
599 |
} |
} |
600 |
unzip_extract(&zip_header, dst_fd); |
unzip_extract(&zip_header, dst_fd); |
623 |
goto check_file; |
goto check_file; |
624 |
|
|
625 |
default: |
default: |
626 |
printf("error: invalid response [%c]\n",(char)i); |
printf("error: invalid response [%c]\n", (char)i); |
627 |
goto check_file; |
goto check_file; |
628 |
} |
} |
629 |
|
|
630 |
total_entries++; |
total_entries++; |
631 |
} |
} |
632 |
|
|
633 |
if (listing && verbose) { |
if (listing && quiet <= 1) { |
634 |
printf(" -------- -------\n" |
if (!verbose) { |
635 |
"%9d %d files\n", |
// " Length Date Time Name\n" |
636 |
total_size, total_entries); |
// " -------- ---- ---- ----" |
637 |
|
printf( " -------- -------\n" |
638 |
|
"%9lu" " %u files\n", |
639 |
|
total_usize, total_entries); |
640 |
|
} else { |
641 |
|
unsigned long percents = total_usize - total_size; |
642 |
|
percents = percents * 100; |
643 |
|
if (total_usize) |
644 |
|
percents /= total_usize; |
645 |
|
// " Length Method Size Ratio Date Time CRC-32 Name\n" |
646 |
|
// "-------- ------ ------- ----- ---- ---- ------ ----" |
647 |
|
printf( "-------- ------- --- -------\n" |
648 |
|
"%8lu" "%17lu%4u%% %u files\n", |
649 |
|
total_usize, total_size, (unsigned)percents, |
650 |
|
total_entries); |
651 |
|
} |
652 |
} |
} |
653 |
|
|
654 |
return 0; |
return 0; |