aboutsummaryrefslogtreecommitdiff
path: root/archival/dpkg_deb.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/dpkg_deb.c')
-rw-r--r--archival/dpkg_deb.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index cbacc91f8..9e6340fd3 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -20,8 +20,8 @@ int dpkg_deb_main(int argc, char **argv)
20 archive_handle_t *tar_archive; 20 archive_handle_t *tar_archive;
21 llist_t *control_tar_llist = NULL; 21 llist_t *control_tar_llist = NULL;
22 unsigned opt; 22 unsigned opt;
23 const char *extract_dir = NULL; 23 const char *extract_dir;
24 short argcount = 1; 24 int need_args;
25 25
26 /* Setup the tar archive handle */ 26 /* Setup the tar archive handle */
27 tar_archive = init_handle(); 27 tar_archive = init_handle();
@@ -43,17 +43,21 @@ int dpkg_deb_main(int argc, char **argv)
43 43
44 opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; 44 opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
45 opt = getopt32(argv, "cefXx"); 45 opt = getopt32(argv, "cefXx");
46 argv += optind;
47 argc -= optind;
46 48
47 if (opt & DPKG_DEB_OPT_CONTENTS) { 49 if (opt & DPKG_DEB_OPT_CONTENTS) {
48 tar_archive->action_header = header_verbose_list; 50 tar_archive->action_header = header_verbose_list;
49 } 51 }
52 extract_dir = NULL;
53 need_args = 1;
50 if (opt & DPKG_DEB_OPT_CONTROL) { 54 if (opt & DPKG_DEB_OPT_CONTROL) {
51 ar_archive->accept = control_tar_llist; 55 ar_archive->accept = control_tar_llist;
52 tar_archive->action_data = data_extract_all; 56 tar_archive->action_data = data_extract_all;
53 if (optind + 1 == argc) { 57 if (1 == argc) {
54 extract_dir = "./DEBIAN"; 58 extract_dir = "./DEBIAN";
55 } else { 59 } else {
56 argcount++; 60 need_args++;
57 } 61 }
58 } 62 }
59 if (opt & DPKG_DEB_OPT_FIELD) { 63 if (opt & DPKG_DEB_OPT_FIELD) {
@@ -70,28 +74,31 @@ int dpkg_deb_main(int argc, char **argv)
70 } 74 }
71 if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { 75 if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
72 tar_archive->action_data = data_extract_all; 76 tar_archive->action_data = data_extract_all;
73 argcount = 2; 77 need_args = 2;
74 } 78 }
75 79
76 if ((optind + argcount) != argc) { 80 if (need_args != argc) {
77 bb_show_usage(); 81 bb_show_usage();
78 } 82 }
79 83
80 tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY); 84 tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY);
81 85
82 /* Workout where to extract the files */ 86 /* Work out where to extract the files */
83 /* 2nd argument is a dir name */ 87 /* 2nd argument is a dir name */
84 if (argv[optind]) { 88 if (argv[1]) {
85 extract_dir = argv[optind]; 89 extract_dir = argv[1];
86 } 90 }
87 if (extract_dir) { 91 if (extract_dir) {
88 mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ 92 mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
89 xchdir(extract_dir); 93 xchdir(extract_dir);
90 } 94 }
95
96 /* Do it */
91 unpack_ar_archive(ar_archive); 97 unpack_ar_archive(ar_archive);
92 98
93 /* Cleanup */ 99 /* Cleanup */
94 close(ar_archive->src_fd); 100 if (ENABLE_FEATURE_CLEAN_UP)
101 close(ar_archive->src_fd);
95 102
96 return EXIT_SUCCESS; 103 return EXIT_SUCCESS;
97} 104}