unzip: match "Defl:?" display with info-zip; cosmetic code shuffling
Large nested indented code blocks made more sane with a few gotos. function old new delta unzip_main 2491 2519 +28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
6b4f4b5284
commit
8c1d857d25
@ -659,8 +659,9 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
xread(zip_fd, zip.raw, ZIP_HEADER_LEN);
|
||||
FIX_ENDIANNESS_ZIP(zip);
|
||||
if (zip.fmt.zip_flags & SWAP_LE16(0x0009)) {
|
||||
bb_error_msg_and_die("zip flags 1 and 8 are not supported");
|
||||
if (zip.fmt.zip_flags & SWAP_LE16(0x0008)) {
|
||||
bb_error_msg_and_die("zip flag %s is not supported",
|
||||
"8 (streaming)");
|
||||
}
|
||||
}
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
@ -704,7 +705,8 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
if (zip.fmt.zip_flags & SWAP_LE16(0x0001)) {
|
||||
/* 0x0001 - encrypted */
|
||||
bb_error_msg_and_die("zip flag 1 (encryption) is not supported");
|
||||
bb_error_msg_and_die("zip flag %s is not supported",
|
||||
"1 (encryption)");
|
||||
}
|
||||
dbg("File cmpsize:0x%x extra_len:0x%x ucmpsize:0x%x",
|
||||
(unsigned)zip.fmt.cmpsize,
|
||||
@ -727,8 +729,9 @@ int unzip_main(int argc, char **argv)
|
||||
if (find_list_entry(zreject, dst_fn)
|
||||
|| (zaccept && !find_list_entry(zaccept, dst_fn))
|
||||
) { /* Skip entry */
|
||||
i = 'n';
|
||||
} else {
|
||||
goto skip_cmpsize;
|
||||
}
|
||||
|
||||
if (listing) {
|
||||
/* List entry */
|
||||
char dtbuf[sizeof("mm-dd-yyyy hh:mm")];
|
||||
@ -752,6 +755,14 @@ int unzip_main(int argc, char **argv)
|
||||
unsigned long percents;
|
||||
|
||||
sprintf(method6, "%6u", zip.fmt.method);
|
||||
if (zip.fmt.method == 0) {
|
||||
strcpy(method6, "Stored");
|
||||
}
|
||||
if (zip.fmt.method == 8) {
|
||||
strcpy(method6, "Defl:N");
|
||||
/* normal, maximum, fast, superfast */
|
||||
IF_DESKTOP(method6[5] = "NXFS"[(zip.fmt.zip_flags >> 1) & 3];)
|
||||
}
|
||||
percents = zip.fmt.ucmpsize - zip.fmt.cmpsize;
|
||||
if ((int32_t)percents < 0)
|
||||
percents = 0; /* happens if ucmpsize < cmpsize */
|
||||
@ -762,9 +773,7 @@ int unzip_main(int argc, char **argv)
|
||||
// "-------- ------ ------- ---- ---------- ----- -------- ----"
|
||||
printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n",
|
||||
(unsigned)zip.fmt.ucmpsize,
|
||||
zip.fmt.method == 0 ? "Stored"
|
||||
: zip.fmt.method == 8 ? "Defl:N"
|
||||
: method6,
|
||||
method6,
|
||||
(unsigned)zip.fmt.cmpsize,
|
||||
(unsigned)percents,
|
||||
dtbuf,
|
||||
@ -773,11 +782,14 @@ int unzip_main(int argc, char **argv)
|
||||
total_size += zip.fmt.cmpsize;
|
||||
}
|
||||
total_usize += zip.fmt.ucmpsize;
|
||||
i = 'n';
|
||||
} else if (dst_fd == STDOUT_FILENO) {
|
||||
goto skip_cmpsize;
|
||||
}
|
||||
|
||||
if (dst_fd == STDOUT_FILENO) {
|
||||
/* Extracting to STDOUT */
|
||||
i = -1;
|
||||
} else if (last_char_is(dst_fn, '/')) {
|
||||
goto do_extract;
|
||||
}
|
||||
if (last_char_is(dst_fn, '/')) {
|
||||
/* Extract directory */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
@ -796,49 +808,44 @@ int unzip_main(int argc, char **argv)
|
||||
dst_fn, "directory");
|
||||
}
|
||||
}
|
||||
i = 'n';
|
||||
} else {
|
||||
/* Extract file */
|
||||
goto skip_cmpsize;
|
||||
}
|
||||
check_file:
|
||||
/* Extract file */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
/* File does not exist */
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
}
|
||||
i = 'y';
|
||||
} else {
|
||||
goto do_open_and_extract;
|
||||
}
|
||||
/* File already exists */
|
||||
if (overwrite == O_NEVER) {
|
||||
i = 'n';
|
||||
} else if (S_ISREG(stat_buf.st_mode)) {
|
||||
/* File is regular file */
|
||||
if (overwrite == O_ALWAYS) {
|
||||
i = 'y';
|
||||
} else {
|
||||
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
|
||||
my_fgets80(key_buf);
|
||||
i = key_buf[0];
|
||||
goto skip_cmpsize;
|
||||
}
|
||||
} else {
|
||||
if (!S_ISREG(stat_buf.st_mode)) {
|
||||
/* File is not regular file */
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
dst_fn, "regular file");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* File is regular file */
|
||||
if (overwrite == O_ALWAYS)
|
||||
goto do_open_and_extract;
|
||||
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
|
||||
my_fgets80(key_buf);
|
||||
|
||||
switch (i) {
|
||||
switch (key_buf[0]) {
|
||||
case 'A':
|
||||
overwrite = O_ALWAYS;
|
||||
case 'y': /* Open file and fall into unzip */
|
||||
do_open_and_extract:
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT | O_TRUNC, file_mode);
|
||||
#else
|
||||
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
#endif
|
||||
case -1: /* Unzip */
|
||||
do_extract:
|
||||
if (!quiet) {
|
||||
printf(/* zip.fmt.method == 0
|
||||
? " extracting: %s\n"
|
||||
@ -853,8 +860,8 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
case 'N':
|
||||
overwrite = O_NEVER;
|
||||
case 'n':
|
||||
/* Skip entry data */
|
||||
case 'n': /* Skip entry data */
|
||||
skip_cmpsize:
|
||||
unzip_skip(zip.fmt.cmpsize);
|
||||
break;
|
||||
|
||||
@ -868,7 +875,7 @@ int unzip_main(int argc, char **argv)
|
||||
goto check_file;
|
||||
|
||||
default:
|
||||
printf("error: invalid response [%c]\n", (char)i);
|
||||
printf("error: invalid response [%c]\n", (char)key_buf[0]);
|
||||
goto check_file;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user