+
+ /* Filter zip entries */
+ if (find_list_entry(zreject, dst_fn) ||
+ (zaccept && !find_list_entry(zaccept, dst_fn))) { /* Skip entry */
+ i = 'n';
+
+ } else { /* Extract entry */
+ total_size += zip_header.formated.ucmpsize;
+
+ if (verbosity == v_list) { /* List entry */
+ unsigned int dostime = zip_header.formated.modtime | (zip_header.formated.moddate << 16);
+ printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
+ zip_header.formated.ucmpsize,
+ (dostime & 0x01e00000) >> 21,
+ (dostime & 0x001f0000) >> 16,
+ (((dostime & 0xfe000000) >> 25) + 1980) % 100,
+ (dostime & 0x0000f800) >> 11,
+ (dostime & 0x000007e0) >> 5,
+ dst_fn);
+ total_entries++;
+ i = 'n';
+
+ } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
+ i = -1;
+
+ } else if (last_char_is(dst_fn, '/')) { /* Extract directory */
+ if (stat(dst_fn, &stat_buf) == -1) {
+ if (errno != ENOENT) {
+ bb_perror_msg_and_die("Cannot stat '%s'",dst_fn);
+ }
+ if (verbosity == v_normal) {
+ printf(" creating: %s\n", dst_fn);
+ }
+ unzip_create_leading_dirs(dst_fn);
+ if (bb_make_directory(dst_fn, 0777, 0)) {
+ bb_error_msg_and_die("Exiting");
+ }
+ } else {
+ if (!S_ISDIR(stat_buf.st_mode)) {
+ bb_error_msg_and_die("'%s' exists but is not directory", dst_fn);
+ }
+ }
+ i = 'n';
+
+ } else { /* Extract file */
+ _check_file:
+ if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */
+ if (errno != ENOENT) {
+ bb_perror_msg_and_die("Cannot stat '%s'",dst_fn);
+ }
+ i = 'y';
+
+ } else { /* 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);
+ if (!fgets(key_buf, 512, stdin)) {
+ bb_perror_msg_and_die("Cannot read input");
+ }
+ i = key_buf[0];
+ }
+
+ } else { /* File is not regular file */
+ bb_error_msg_and_die("'%s' exists but is not regular file",dst_fn);
+ }
+ }
+ }
+ }
+
+ switch (i) {
+ case 'A':
+ overwrite = o_always;
+ case 'y': /* Open file and fall into unzip */
+ unzip_create_leading_dirs(dst_fn);
+ dst_fd = bb_xopen(dst_fn, O_WRONLY | O_CREAT);
+ case -1: /* Unzip */
+ if (verbosity == v_normal) {
+ printf(" inflating: %s\n", dst_fn);
+ }
+ if (unzip_extract(&zip_header, src_fd, dst_fd)) {
+ failed = 1;
+ }
+ if (dst_fd != STDOUT_FILENO) {
+ /* closing STDOUT is potentially bad for future business */
+ close(dst_fd);
+ }
+ break;
+
+ case 'N':
+ overwrite = o_never;
+ case 'n':
+ /* Skip entry data */
+ unzip_skip(src_fd, zip_header.formated.cmpsize);
+ break;
+
+ case 'r':
+ /* Prompt for new name */
+ printf("new name: ");
+ if (!fgets(key_buf, 512, stdin)) {
+ bb_perror_msg_and_die("Cannot read input");
+ }
+ free(dst_fn);
+ dst_fn = bb_xstrdup(key_buf);
+ chomp(dst_fn);
+ goto _check_file;
+
+ default:
+ printf("error: invalid response [%c]\n",(char)i);
+ goto _check_file;
+ }
+
+ /* Data descriptor section */
+ if (zip_header.formated.flags & 4) {
+ /* skip over duplicate crc, compressed size and uncompressed size */
+ unzip_skip(src_fd, 12);
+ }
+ }
+
+ if (verbosity == v_list) {
+ printf(" -------- -------\n"
+ "%9d %d files\n", total_size, total_entries);