2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "unarchive.h"
24 extern int dpkg_deb_main(int argc, char **argv)
26 archive_handle_t *ar_archive;
27 archive_handle_t *tar_archive;
29 #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
30 const llist_t *control_tar_llist = NULL;
36 /* a .deb file is an ar archive that contain three files,
37 * data.tar.gz, control.tar.gz and debian
40 /* Setup the tar archive handle */
41 tar_archive = init_handle();
43 /* Setup an ar archive handle that refers to the gzip sub archive */
44 ar_archive = init_handle();
45 ar_archive->sub_archive = tar_archive;
46 ar_archive->filter = filter_accept_list_reassign;
48 #ifdef CONFIG_FEATURE_DEB_TAR_GZ
49 ar_archive->accept = add_to_list(NULL, "data.tar.gz");
50 # ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
51 control_tar_llist = add_to_list(NULL, "control.tar.gz");
55 #ifdef CONFIG_FEATURE_DEB_TAR_BZ2
56 ar_archive->accept = add_to_list(ar_archive->accept, "data.tar.bz2");
57 # ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
58 control_tar_llist = add_to_list(control_tar_llist, "control.tar.bz2");
62 #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
63 while ((opt = getopt(argc, argv, "cefXx")) != -1) {
65 while ((opt = getopt(argc, argv, "x")) != -1) {
68 #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
70 tar_archive->action_header = header_verbose_list;
73 ar_archive->accept = control_tar_llist;
74 tar_archive->action_data = data_extract_all;
77 /* Print the entire control file
78 * it should accept a second argument which specifies a
79 * specific field to print */
80 ar_archive->accept = control_tar_llist;
81 tar_archive->accept = add_to_list(NULL, "./control");;
82 tar_archive->filter = filter_accept_list;
83 tar_archive->action_data = data_extract_to_stdout;
86 tar_archive->action_header = header_list;
89 tar_archive->action_data = data_extract_all;
96 if (optind + 2 < argc) {
100 tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
102 /* Workout where to extract the files */
103 /* 2nd argument is a dir name */
104 mkdir(argv[optind], 0777);
108 unpack_ar_archive(ar_archive);
110 xread_all(ar_archive->src_fd, magic, 7);
111 if (strncmp(magic, "!<arch>", 7) != 0) {
112 error_msg_and_die("Invalid ar magic");
114 ar_archive->offset += 7;
116 while (get_header_ar(ar_archive) == EXIT_SUCCESS);
120 close (ar_archive->src_fd);
122 return(EXIT_SUCCESS);