static void extract_cpio(int fd, const char *source_rpm) { archive_handle_t *archive_handle; if (source_rpm != NULL) { /* Binary rpm (it was built from some SRPM), install to root */ xchdir("/"); } /* else: SRPM, install to current dir */ /* Initialize */ archive_handle = init_handle(); archive_handle->seek = seek_by_read; archive_handle->action_data = data_extract_all; #if 0 /* For testing (rpm -i only lists the files in internal cpio): */ archive_handle->action_header = header_list; archive_handle->action_data = data_skip; #endif archive_handle->ah_flags = ARCHIVE_RESTORE_DATE | ARCHIVE_CREATE_LEADING_DIRS /* compat: overwrite existing files. * try "rpm -i foo.src.rpm" few times in a row - * standard rpm will not complain. */ | ARCHIVE_REPLACE_VIA_RENAME; archive_handle->src_fd = fd; /*archive_handle->offset = 0; - init_handle() did it */ setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1); while (get_header_cpio(archive_handle) == EXIT_SUCCESS) continue; }
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv) { struct rpm_lead lead; unsigned pos; if (argv[1]) { xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd); } xread(rpm_fd, &lead, sizeof(lead)); /* Just check the magic, the rest is irrelevant */ if (lead.magic != htonl(RPM_LEAD_MAGIC)) { bb_error_msg_and_die("invalid RPM magic"); } /* Skip the signature header, align to 8 bytes */ pos = skip_header(); seek_by_jump(rpm_fd, (-(int)pos) & 7); /* Skip the main header */ skip_header(); //if (SEAMLESS_COMPRESSION) // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ // signal(SIGCHLD, check_errors_in_children); /* This works, but doesn't report uncompress errors (they happen in child) */ setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1); if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0) bb_error_msg_and_die("error unpacking"); if (ENABLE_FEATURE_CLEAN_UP) { close(rpm_fd); } if (SEAMLESS_COMPRESSION) { check_errors_in_children(0); return bb_got_signal; } return EXIT_SUCCESS; }
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv) { const char *str; int rpm_fd; INIT_G(); G.pagesize = getpagesize(); rpm_fd = rpm_gettags(argv[1]); //if (SEAMLESS_COMPRESSION) - we do this at the end instead. // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ // signal(SIGCHLD, check_errors_in_children); if (ENABLE_FEATURE_SEAMLESS_LZMA && (str = rpm_getstr0(TAG_PAYLOADCOMPRESSOR)) != NULL && strcmp(str, "lzma") == 0 ) { // lzma compression can't be detected // set up decompressor without detection setup_lzma_on_fd(rpm_fd); } else { setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1); } if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0) bb_error_msg_and_die("error unpacking"); if (ENABLE_FEATURE_CLEAN_UP) { close(rpm_fd); } if (SEAMLESS_COMPRESSION) { check_errors_in_children(0); return bb_got_signal; } return EXIT_SUCCESS; }