source: MondoRescue/branches/3.2/mindi-busybox/archival/dpkg_deb.c@ 3232

Last change on this file since 3232 was 3232, checked in by Bruno Cornec, 10 years ago
  • Update mindi-busybox to 1.21.1
File size: 3.5 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
3 * dpkg-deb packs, unpacks and provides information about Debian archives.
4 *
[2725]5 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]6 */
[3232]7
8//usage:#define dpkg_deb_trivial_usage
9//usage: "[-cefxX] FILE [argument"
10//usage:#define dpkg_deb_full_usage "\n\n"
11//usage: "Perform actions on Debian packages (.debs)\n"
12//usage: "\n -c List contents of filesystem tree"
13//usage: "\n -e Extract control files to [argument] directory"
14//usage: "\n -f Display control field name starting with [argument]"
15//usage: "\n -x Extract packages filesystem tree to directory"
16//usage: "\n -X Verbose extract"
17//usage:
18//usage:#define dpkg_deb_example_usage
19//usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n"
20
[1765]21#include "libbb.h"
[3232]22#include "bb_archive.h"
[821]23
[2725]24#define DPKG_DEB_OPT_CONTENTS 1
25#define DPKG_DEB_OPT_CONTROL 2
26#define DPKG_DEB_OPT_FIELD 4
27#define DPKG_DEB_OPT_EXTRACT 8
28#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
[821]29
[2725]30int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
[821]31int dpkg_deb_main(int argc, char **argv)
32{
33 archive_handle_t *ar_archive;
34 archive_handle_t *tar_archive;
35 llist_t *control_tar_llist = NULL;
[1765]36 unsigned opt;
[2725]37 const char *extract_dir;
38 int need_args;
[821]39
40 /* Setup the tar archive handle */
41 tar_archive = init_handle();
42
43 /* Setup an ar archive handle that refers to the gzip sub archive */
44 ar_archive = init_handle();
[2725]45 ar_archive->dpkg__sub_archive = tar_archive;
[821]46 ar_archive->filter = filter_accept_list_reassign;
47
[2725]48#if ENABLE_FEATURE_SEAMLESS_GZ
49 llist_add_to(&ar_archive->accept, (char*)"data.tar.gz");
[1765]50 llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
[821]51#endif
[2725]52#if ENABLE_FEATURE_SEAMLESS_BZ2
53 llist_add_to(&ar_archive->accept, (char*)"data.tar.bz2");
[1765]54 llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
[821]55#endif
[2725]56#if ENABLE_FEATURE_SEAMLESS_LZMA
57 llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma");
58 llist_add_to(&control_tar_llist, (char*)"control.tar.lzma");
59#endif
[821]60
[2725]61 opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
[1765]62 opt = getopt32(argv, "cefXx");
[2725]63 argv += optind;
64 argc -= optind;
[821]65
66 if (opt & DPKG_DEB_OPT_CONTENTS) {
67 tar_archive->action_header = header_verbose_list;
68 }
[2725]69 extract_dir = NULL;
70 need_args = 1;
[821]71 if (opt & DPKG_DEB_OPT_CONTROL) {
72 ar_archive->accept = control_tar_llist;
73 tar_archive->action_data = data_extract_all;
[2725]74 if (1 == argc) {
[821]75 extract_dir = "./DEBIAN";
76 } else {
[2725]77 need_args++;
[821]78 }
79 }
80 if (opt & DPKG_DEB_OPT_FIELD) {
81 /* Print the entire control file
82 * it should accept a second argument which specifies a
83 * specific field to print */
84 ar_archive->accept = control_tar_llist;
[1765]85 llist_add_to(&(tar_archive->accept), (char*)"./control");
[821]86 tar_archive->filter = filter_accept_list;
87 tar_archive->action_data = data_extract_to_stdout;
88 }
89 if (opt & DPKG_DEB_OPT_EXTRACT) {
90 tar_archive->action_header = header_list;
91 }
92 if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
93 tar_archive->action_data = data_extract_all;
[2725]94 need_args = 2;
[821]95 }
96
[2725]97 if (need_args != argc) {
[821]98 bb_show_usage();
99 }
100
[2725]101 tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY);
[821]102
[2725]103 /* Work out where to extract the files */
[821]104 /* 2nd argument is a dir name */
[2725]105 if (argv[1]) {
106 extract_dir = argv[1];
[821]107 }
108 if (extract_dir) {
109 mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
[1765]110 xchdir(extract_dir);
[821]111 }
[2725]112
113 /* Do it */
[821]114 unpack_ar_archive(ar_archive);
115
116 /* Cleanup */
[2725]117 if (ENABLE_FEATURE_CLEAN_UP)
118 close(ar_archive->src_fd);
[821]119
[1765]120 return EXIT_SUCCESS;
[821]121}
Note: See TracBrowser for help on using the repository browser.