- /* Data section */
- archive_handle->file_header->size = zip_header.formated.cmpsize;
- if (archive_handle->action_data) {
- archive_handle->action_data(archive_handle);
- } else {
- dst_fd = xopen(archive_handle->file_header->name, O_WRONLY | O_CREAT);
- inflate(archive_handle->src_fd, dst_fd);
- close(dst_fd);
- chmod(archive_handle->file_header->name, archive_handle->file_header->mode);
-
- /* Validate decompression - crc */
- if (zip_header.formated.crc32 != (gunzip_crc ^ 0xffffffffL)) {
- error_msg("Invalid compressed data--crc error");
+ /* 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.formatted.ucmpsize;
+
+ if (verbosity == v_list) { /* List entry */
+ unsigned int dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
+ printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
+ zip_header.formatted.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);
+ }
+ }