diff options
Diffstat (limited to 'archival/dpkg_deb.c')
-rw-r--r-- | archival/dpkg_deb.c | 88 |
1 files changed, 35 insertions, 53 deletions
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index 0285273fe..86850469d 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c | |||
@@ -16,29 +16,20 @@ | |||
16 | //config: | 16 | //config: |
17 | //config: Unless you have a specific application which requires dpkg-deb, | 17 | //config: Unless you have a specific application which requires dpkg-deb, |
18 | //config: say N here. | 18 | //config: say N here. |
19 | //config: | ||
20 | //config:config FEATURE_DPKG_DEB_EXTRACT_ONLY | ||
21 | //config: bool "Extract only (-x)" | ||
22 | //config: default n | ||
23 | //config: depends on DPKG_DEB | ||
24 | //config: help | ||
25 | //config: This reduces dpkg-deb to the equivalent of | ||
26 | //config: "ar -p <deb> data.tar.gz | tar -zx". However it saves space as none | ||
27 | //config: of the extra dpkg-deb, ar or tar options are needed, they are linked | ||
28 | //config: to internally. | ||
29 | 19 | ||
30 | //applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb)) | 20 | //applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb)) |
21 | |||
31 | //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o | 22 | //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o |
32 | 23 | ||
33 | //usage:#define dpkg_deb_trivial_usage | 24 | //usage:#define dpkg_deb_trivial_usage |
34 | //usage: "[-cefxX] FILE [argument]" | 25 | //usage: "[-cefxX] FILE [DIR]" |
35 | //usage:#define dpkg_deb_full_usage "\n\n" | 26 | //usage:#define dpkg_deb_full_usage "\n\n" |
36 | //usage: "Perform actions on Debian packages (.debs)\n" | 27 | //usage: "Perform actions on Debian packages (.deb)\n" |
37 | //usage: "\n -c List contents of filesystem tree" | 28 | //usage: "\n -c List files" |
38 | //usage: "\n -e Extract control files to [argument] directory" | 29 | //usage: "\n -f Print control fields" |
39 | //usage: "\n -f Display control field name starting with [argument]" | 30 | //usage: "\n -e Extract control files to DIR (default: ./DEBIAN)" |
40 | //usage: "\n -x Extract packages filesystem tree to directory" | 31 | //usage: "\n -x Extract files to DIR (no default)" |
41 | //usage: "\n -X Verbose extract" | 32 | //usage: "\n -X Verbose -x" |
42 | //usage: | 33 | //usage: |
43 | //usage:#define dpkg_deb_example_usage | 34 | //usage:#define dpkg_deb_example_usage |
44 | //usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n" | 35 | //usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n" |
@@ -49,18 +40,17 @@ | |||
49 | #define DPKG_DEB_OPT_CONTENTS 1 | 40 | #define DPKG_DEB_OPT_CONTENTS 1 |
50 | #define DPKG_DEB_OPT_CONTROL 2 | 41 | #define DPKG_DEB_OPT_CONTROL 2 |
51 | #define DPKG_DEB_OPT_FIELD 4 | 42 | #define DPKG_DEB_OPT_FIELD 4 |
52 | #define DPKG_DEB_OPT_EXTRACT 8 | 43 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 8 |
53 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16 | 44 | #define DPKG_DEB_OPT_EXTRACT 16 |
54 | 45 | ||
55 | int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 46 | int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
56 | int dpkg_deb_main(int argc, char **argv) | 47 | int dpkg_deb_main(int argc UNUSED_PARAM, char **argv) |
57 | { | 48 | { |
58 | archive_handle_t *ar_archive; | 49 | archive_handle_t *ar_archive; |
59 | archive_handle_t *tar_archive; | 50 | archive_handle_t *tar_archive; |
60 | llist_t *control_tar_llist = NULL; | 51 | llist_t *control_tar_llist = NULL; |
61 | unsigned opt; | 52 | unsigned opt; |
62 | const char *extract_dir; | 53 | const char *extract_dir; |
63 | int need_args; | ||
64 | 54 | ||
65 | /* Setup the tar archive handle */ | 55 | /* Setup the tar archive handle */ |
66 | tar_archive = init_handle(); | 56 | tar_archive = init_handle(); |
@@ -89,53 +79,45 @@ int dpkg_deb_main(int argc, char **argv) | |||
89 | llist_add_to(&control_tar_llist, (char*)"control.tar.xz"); | 79 | llist_add_to(&control_tar_llist, (char*)"control.tar.xz"); |
90 | #endif | 80 | #endif |
91 | 81 | ||
92 | opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; | 82 | /* Must have 1 or 2 args */ |
83 | opt_complementary = "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; | ||
93 | opt = getopt32(argv, "cefXx"); | 84 | opt = getopt32(argv, "cefXx"); |
94 | argv += optind; | 85 | argv += optind; |
95 | argc -= optind; | 86 | //argc -= optind; |
96 | 87 | ||
97 | if (opt & DPKG_DEB_OPT_CONTENTS) { | 88 | extract_dir = argv[1]; |
89 | if (opt & DPKG_DEB_OPT_CONTENTS) { // -c | ||
98 | tar_archive->action_header = header_verbose_list; | 90 | tar_archive->action_header = header_verbose_list; |
91 | if (extract_dir) | ||
92 | bb_show_usage(); | ||
99 | } | 93 | } |
100 | extract_dir = NULL; | 94 | if (opt & DPKG_DEB_OPT_FIELD) { // -f |
101 | need_args = 1; | 95 | /* Print the entire control file */ |
102 | if (opt & DPKG_DEB_OPT_CONTROL) { | 96 | //TODO: standard tool accepts an optional list of fields to print |
103 | ar_archive->accept = control_tar_llist; | ||
104 | tar_archive->action_data = data_extract_all; | ||
105 | if (1 == argc) { | ||
106 | extract_dir = "./DEBIAN"; | ||
107 | } else { | ||
108 | need_args++; | ||
109 | } | ||
110 | } | ||
111 | if (opt & DPKG_DEB_OPT_FIELD) { | ||
112 | /* Print the entire control file | ||
113 | * it should accept a second argument which specifies a | ||
114 | * specific field to print */ | ||
115 | ar_archive->accept = control_tar_llist; | 97 | ar_archive->accept = control_tar_llist; |
116 | llist_add_to(&(tar_archive->accept), (char*)"./control"); | 98 | llist_add_to(&(tar_archive->accept), (char*)"./control"); |
117 | tar_archive->filter = filter_accept_list; | 99 | tar_archive->filter = filter_accept_list; |
118 | tar_archive->action_data = data_extract_to_stdout; | 100 | tar_archive->action_data = data_extract_to_stdout; |
101 | if (extract_dir) | ||
102 | bb_show_usage(); | ||
119 | } | 103 | } |
120 | if (opt & DPKG_DEB_OPT_EXTRACT) { | 104 | if (opt & DPKG_DEB_OPT_CONTROL) { // -e |
121 | tar_archive->action_header = header_list; | 105 | ar_archive->accept = control_tar_llist; |
122 | } | ||
123 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { | ||
124 | tar_archive->action_data = data_extract_all; | 106 | tar_archive->action_data = data_extract_all; |
125 | need_args = 2; | 107 | if (!extract_dir) |
108 | extract_dir = "./DEBIAN"; | ||
126 | } | 109 | } |
127 | 110 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { // -Xx | |
128 | if (need_args != argc) { | 111 | if (opt & DPKG_DEB_OPT_EXTRACT_VERBOSE) |
129 | bb_show_usage(); | 112 | tar_archive->action_header = header_list; |
113 | tar_archive->action_data = data_extract_all; | ||
114 | if (!extract_dir) | ||
115 | bb_show_usage(); | ||
130 | } | 116 | } |
131 | 117 | ||
132 | tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY); | 118 | /* Standard tool supports "-" */ |
119 | tar_archive->src_fd = ar_archive->src_fd = xopen_stdin(argv[0]); | ||
133 | 120 | ||
134 | /* Work out where to extract the files */ | ||
135 | /* 2nd argument is a dir name */ | ||
136 | if (argv[1]) { | ||
137 | extract_dir = argv[1]; | ||
138 | } | ||
139 | if (extract_dir) { | 121 | if (extract_dir) { |
140 | mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ | 122 | mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ |
141 | xchdir(extract_dir); | 123 | xchdir(extract_dir); |