Fix long filename support
[oweals/busybox.git] / archival / dpkg_deb.c
1 /*
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.
6  *
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.
11  *
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.
15  */
16 #include <fcntl.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <unistd.h>
20 #include <getopt.h>
21 #include "unarchive.h"
22 #include "busybox.h"
23
24 extern int dpkg_deb_main(int argc, char **argv)
25 {
26         archive_handle_t *ar_archive;
27         archive_handle_t *tar_archive;
28         int opt = 0;
29 #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
30         const llist_t *control_tar_llist = NULL;
31 #endif
32         
33         /* Setup the tar archive handle */
34         tar_archive = init_handle();
35
36         /* Setup an ar archive handle that refers to the gzip sub archive */    
37         ar_archive = init_handle();
38         ar_archive->sub_archive = tar_archive;
39         ar_archive->filter = filter_accept_list_reassign;
40
41 #ifdef CONFIG_FEATURE_DEB_TAR_GZ
42         ar_archive->accept = add_to_list(NULL, "data.tar.gz");
43 # ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
44         control_tar_llist = add_to_list(NULL, "control.tar.gz");
45 # endif
46 #endif
47
48 #ifdef CONFIG_FEATURE_DEB_TAR_BZ2
49         ar_archive->accept = add_to_list(ar_archive->accept, "data.tar.bz2");
50 # ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
51         control_tar_llist = add_to_list(control_tar_llist, "control.tar.bz2");
52 # endif
53 #endif
54
55 #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
56         while ((opt = getopt(argc, argv, "cefXx")) != -1) {
57 #else
58         while ((opt = getopt(argc, argv, "x")) != -1) {
59 #endif
60                 switch (opt) {
61 #ifndef CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
62                         case 'c':
63                                 tar_archive->action_header = header_verbose_list;
64                                 break;
65                         case 'e':
66                                 ar_archive->accept = control_tar_llist;
67                                 tar_archive->action_data = data_extract_all;
68                                 break;
69                         case 'f':
70                                 /* Print the entire control file
71                                  * it should accept a second argument which specifies a 
72                                  * specific field to print */
73                                 ar_archive->accept = control_tar_llist;
74                                 tar_archive->accept = add_to_list(NULL, "./control");;
75                                 tar_archive->filter = filter_accept_list;
76                                 tar_archive->action_data = data_extract_to_stdout;
77                                 break;
78                         case 'X':
79                                 tar_archive->action_header = header_list;
80 #endif
81                         case 'x':
82                                 tar_archive->action_data = data_extract_all;
83                                 break;
84                         default:
85                                 show_usage();
86                 }
87         }
88
89         if (optind + 2 < argc)  {
90                 show_usage();
91         }
92
93         tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
94
95         /* Workout where to extract the files */
96         /* 2nd argument is a dir name */
97         mkdir(argv[optind], 0777);
98         chdir(argv[optind]);
99
100         unpack_ar_archive(ar_archive);
101
102         /* Cleanup */
103         close (ar_archive->src_fd);
104
105         return(EXIT_SUCCESS);
106 }
107