* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
+#include <fcntl.h>
#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include <getopt.h>
+#include "unarchive.h"
#include "busybox.h"
extern int dpkg_deb_main(int argc, char **argv)
{
- const int dpkg_deb_contents = 1;
- const int dpkg_deb_control = 2;
-// const int dpkg_deb_info = 4;
- const int dpkg_deb_extract = 8;
- const int dpkg_deb_verbose_extract = 16;
- const int dpkg_deb_list = 32;
- char *target_dir = NULL;
+ archive_handle_t *ar_archive;
+ archive_handle_t *tar_gz_archive;
int opt = 0;
- int optflag = 0;
+#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
+ const llist_t *control_tar_gz_llist = add_to_list(NULL, "control.tar.gz");
+#endif
+#ifndef CONFIG_AR
+ char magic[7];
+#endif
+
+ /* a .deb file is an ar archive that contain three files,
+ * data.tar.gz, control.tar.gz and debian
+ */
- while ((opt = getopt(argc, argv, "cexXl")) != -1) {
+ /* Setup the tar archive handle */
+ tar_gz_archive = init_handle();
+
+ /* Setup an ar archive handle that refers to the gzip sub archive */
+ ar_archive = init_handle();
+ ar_archive->action_data_subarchive = get_header_tar_gz;
+ ar_archive->sub_archive = tar_gz_archive;
+ ar_archive->filter = filter_accept_list;
+ ar_archive->accept = add_to_list(NULL, "data.tar.gz");
+
+#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
+ while ((opt = getopt(argc, argv, "cefXx")) != -1) {
+#else
+ while ((opt = getopt(argc, argv, "x")) != -1) {
+#endif
switch (opt) {
+#ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
case 'c':
- optflag |= dpkg_deb_contents;
+ tar_gz_archive->action_header = header_verbose_list;
break;
case 'e':
- optflag |= dpkg_deb_control;
+ ar_archive->accept = control_tar_gz_llist;
+ tar_gz_archive->action_data = data_extract_all;
break;
- case 'X':
- optflag |= dpkg_deb_verbose_extract;
+ case 'f':
+ /* Print the entire control file
+ * it should accept a second argument which specifies a
+ * specific field to print */
+ ar_archive->accept = control_tar_gz_llist;
+ tar_gz_archive->accept = add_to_list(NULL, "./control");;
+ tar_gz_archive->filter = filter_accept_list;
+ tar_gz_archive->action_data = data_extract_to_stdout;
break;
+ case 'X':
+ tar_gz_archive->action_header = header_list;
+#endif
case 'x':
- optflag |= dpkg_deb_extract;
- break;
- case 'l':
- optflag |= dpkg_deb_list;
+ tar_gz_archive->action_data = data_extract_all;
break;
-/* case 'I':
- optflag |= dpkg_deb_info;
- break;
-*/
default:
show_usage();
}
}
- if (((optind + 1 ) > argc) || (optflag == 0)) {
+ if (optind + 2 < argc) {
show_usage();
}
- if ((optflag & dpkg_deb_control) || (optflag & dpkg_deb_extract) || (optflag & dpkg_deb_verbose_extract)) {
- if ( (optind + 1) == argc ) {
- target_dir = (char *) xmalloc(7);
- strcpy(target_dir, "DEBIAN");
- } else {
- target_dir = (char *) xmalloc(strlen(argv[optind + 1]));
- strcpy(target_dir, argv[optind + 1]);
- }
- }
- deb_extract(optflag, target_dir, argv[optind]);
-/* else if (optflag & dpkg_deb_info) {
- extract_flag = TRUE;
- extract_to_stdout = TRUE;
- strcpy(ar_filename, "control.tar.gz");
- extract_list = argv+optind+1;
- printf("list one is [%s]\n",extract_list[0]);
+
+ tar_gz_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
+
+ /* Workout where to extract the files */
+ /* 2nd argument is a dir name */
+ mkdir(argv[optind], 0777);
+ chdir(argv[optind]);
+
+#ifdef CONFIG_AR
+ unpack_ar_archive(ar_archive);
+#else
+ xread_all(ar_archive->src_fd, magic, 7);
+ if (strncmp(magic, "!<arch>", 7) != 0) {
+ error_msg_and_die("Invalid ar magic");
}
-*/
+ ar_archive->offset += 7;
+
+ while (get_header_ar(ar_archive) == EXIT_SUCCESS);
+#endif
+
+ /* Cleanup */
+ close (ar_archive->src_fd);
+
return(EXIT_SUCCESS);
}
+