diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-27 04:48:53 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-27 04:48:53 +0100 |
| commit | 351ab8278e9719cfdc2abb348017b4e5909bcee8 (patch) | |
| tree | 52cd838a80b4f8285877b75fd5a516d0bcff5816 | |
| parent | 6747bdac88d44d1b3729f56760ae7f6829c85d9f (diff) | |
| download | busybox-w32-351ab8278e9719cfdc2abb348017b4e5909bcee8.tar.gz busybox-w32-351ab8278e9719cfdc2abb348017b4e5909bcee8.tar.bz2 busybox-w32-351ab8278e9719cfdc2abb348017b4e5909bcee8.zip | |
dpkg-deb: shorten code, improve help text
function old new delta
packed_usage 30261 30236 -25
dpkg_deb_main 437 401 -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-61) Total: -61 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | archival/dpkg_deb.c | 77 |
1 files changed, 34 insertions, 43 deletions
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index d34de254a..86850469d 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c | |||
| @@ -22,14 +22,14 @@ | |||
| 22 | //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o | 22 | //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o |
| 23 | 23 | ||
| 24 | //usage:#define dpkg_deb_trivial_usage | 24 | //usage:#define dpkg_deb_trivial_usage |
| 25 | //usage: "[-cefxX] FILE [argument]" | 25 | //usage: "[-cefxX] FILE [DIR]" |
| 26 | //usage:#define dpkg_deb_full_usage "\n\n" | 26 | //usage:#define dpkg_deb_full_usage "\n\n" |
| 27 | //usage: "Perform actions on Debian packages (.debs)\n" | 27 | //usage: "Perform actions on Debian packages (.deb)\n" |
| 28 | //usage: "\n -c List contents of filesystem tree" | 28 | //usage: "\n -c List files" |
| 29 | //usage: "\n -e Extract control files to [argument] directory" | 29 | //usage: "\n -f Print control fields" |
| 30 | //usage: "\n -f Display control field name starting with [argument]" | 30 | //usage: "\n -e Extract control files to DIR (default: ./DEBIAN)" |
| 31 | //usage: "\n -x Extract packages filesystem tree to directory" | 31 | //usage: "\n -x Extract files to DIR (no default)" |
| 32 | //usage: "\n -X Verbose extract" | 32 | //usage: "\n -X Verbose -x" |
| 33 | //usage: | 33 | //usage: |
| 34 | //usage:#define dpkg_deb_example_usage | 34 | //usage:#define dpkg_deb_example_usage |
| 35 | //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" |
| @@ -40,18 +40,17 @@ | |||
| 40 | #define DPKG_DEB_OPT_CONTENTS 1 | 40 | #define DPKG_DEB_OPT_CONTENTS 1 |
| 41 | #define DPKG_DEB_OPT_CONTROL 2 | 41 | #define DPKG_DEB_OPT_CONTROL 2 |
| 42 | #define DPKG_DEB_OPT_FIELD 4 | 42 | #define DPKG_DEB_OPT_FIELD 4 |
| 43 | #define DPKG_DEB_OPT_EXTRACT 8 | 43 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 8 |
| 44 | #define DPKG_DEB_OPT_EXTRACT_VERBOSE 16 | 44 | #define DPKG_DEB_OPT_EXTRACT 16 |
| 45 | 45 | ||
| 46 | int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 46 | int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 47 | int dpkg_deb_main(int argc, char **argv) | 47 | int dpkg_deb_main(int argc UNUSED_PARAM, char **argv) |
| 48 | { | 48 | { |
| 49 | archive_handle_t *ar_archive; | 49 | archive_handle_t *ar_archive; |
| 50 | archive_handle_t *tar_archive; | 50 | archive_handle_t *tar_archive; |
| 51 | llist_t *control_tar_llist = NULL; | 51 | llist_t *control_tar_llist = NULL; |
| 52 | unsigned opt; | 52 | unsigned opt; |
| 53 | const char *extract_dir; | 53 | const char *extract_dir; |
| 54 | int need_args; | ||
| 55 | 54 | ||
| 56 | /* Setup the tar archive handle */ | 55 | /* Setup the tar archive handle */ |
| 57 | tar_archive = init_handle(); | 56 | tar_archive = init_handle(); |
| @@ -80,53 +79,45 @@ int dpkg_deb_main(int argc, char **argv) | |||
| 80 | llist_add_to(&control_tar_llist, (char*)"control.tar.xz"); | 79 | llist_add_to(&control_tar_llist, (char*)"control.tar.xz"); |
| 81 | #endif | 80 | #endif |
| 82 | 81 | ||
| 83 | 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"; | ||
| 84 | opt = getopt32(argv, "cefXx"); | 84 | opt = getopt32(argv, "cefXx"); |
| 85 | argv += optind; | 85 | argv += optind; |
| 86 | argc -= optind; | 86 | //argc -= optind; |
| 87 | 87 | ||
| 88 | if (opt & DPKG_DEB_OPT_CONTENTS) { | 88 | extract_dir = argv[1]; |
| 89 | if (opt & DPKG_DEB_OPT_CONTENTS) { // -c | ||
| 89 | tar_archive->action_header = header_verbose_list; | 90 | tar_archive->action_header = header_verbose_list; |
| 91 | if (extract_dir) | ||
| 92 | bb_show_usage(); | ||
| 90 | } | 93 | } |
| 91 | extract_dir = NULL; | 94 | if (opt & DPKG_DEB_OPT_FIELD) { // -f |
| 92 | need_args = 1; | 95 | /* Print the entire control file */ |
| 93 | if (opt & DPKG_DEB_OPT_CONTROL) { | 96 | //TODO: standard tool accepts an optional list of fields to print |
| 94 | ar_archive->accept = control_tar_llist; | ||
| 95 | tar_archive->action_data = data_extract_all; | ||
| 96 | if (1 == argc) { | ||
| 97 | extract_dir = "./DEBIAN"; | ||
| 98 | } else { | ||
| 99 | need_args++; | ||
| 100 | } | ||
| 101 | } | ||
| 102 | if (opt & DPKG_DEB_OPT_FIELD) { | ||
| 103 | /* Print the entire control file | ||
| 104 | * it should accept a second argument which specifies a | ||
| 105 | * specific field to print */ | ||
| 106 | ar_archive->accept = control_tar_llist; | 97 | ar_archive->accept = control_tar_llist; |
| 107 | llist_add_to(&(tar_archive->accept), (char*)"./control"); | 98 | llist_add_to(&(tar_archive->accept), (char*)"./control"); |
| 108 | tar_archive->filter = filter_accept_list; | 99 | tar_archive->filter = filter_accept_list; |
| 109 | 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(); | ||
| 110 | } | 103 | } |
| 111 | if (opt & DPKG_DEB_OPT_EXTRACT) { | 104 | if (opt & DPKG_DEB_OPT_CONTROL) { // -e |
| 112 | tar_archive->action_header = header_list; | 105 | ar_archive->accept = control_tar_llist; |
| 113 | } | ||
| 114 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { | ||
| 115 | tar_archive->action_data = data_extract_all; | 106 | tar_archive->action_data = data_extract_all; |
| 116 | need_args = 2; | 107 | if (!extract_dir) |
| 108 | extract_dir = "./DEBIAN"; | ||
| 117 | } | 109 | } |
| 118 | 110 | if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { // -Xx | |
| 119 | if (need_args != argc) { | 111 | if (opt & DPKG_DEB_OPT_EXTRACT_VERBOSE) |
| 120 | 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(); | ||
| 121 | } | 116 | } |
| 122 | 117 | ||
| 123 | 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]); | ||
| 124 | 120 | ||
| 125 | /* Work out where to extract the files */ | ||
| 126 | /* 2nd argument is a dir name */ | ||
| 127 | if (argv[1]) { | ||
| 128 | extract_dir = argv[1]; | ||
| 129 | } | ||
| 130 | if (extract_dir) { | 121 | if (extract_dir) { |
| 131 | mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ | 122 | mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ |
| 132 | xchdir(extract_dir); | 123 | xchdir(extract_dir); |
