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.
18 * Merge this applet into dpkg when dpkg becomes more stable
30 extern int gz_open(FILE *compressed_file, int *pid);
31 extern void gz_close(int gunzip_pid);
33 typedef struct ar_headers_s {
41 struct ar_headers_s *next;
44 extern ar_headers_t get_ar_headers(int srcFd);
45 extern int tar_unzip_init(int tarFd);
46 extern int readTarFile(int tarFd, int extractFlag, int listFlag,
47 int tostdoutFlag, int verboseFlag, char** extractList, char** excludeList);
49 static const int dpkg_deb_contents = 1;
50 static const int dpkg_deb_control = 2;
51 // const int dpkg_deb_info = 4;
52 static const int dpkg_deb_extract = 8;
53 static const int dpkg_deb_verbose_extract = 16;
54 static const int dpkg_deb_list = 32;
56 extern int deb_extract(int optflags, const char *dir_name, const char *deb_filename)
58 char **extract_list = NULL;
59 ar_headers_t *ar_headers = NULL;
61 int extract_flag = FALSE;
62 int list_flag = FALSE;
63 int verbose_flag = FALSE;
64 int extract_to_stdout = FALSE;
68 FILE *comp_file = NULL;
70 if (dpkg_deb_contents == (dpkg_deb_contents & optflags)) {
71 strcpy(ar_filename, "data.tar.gz");
75 if (dpkg_deb_list == (dpkg_deb_list & optflags)) {
76 strcpy(ar_filename, "data.tar.gz");
79 if (dpkg_deb_control == (dpkg_deb_control & optflags)) {
80 strcpy(ar_filename, "control.tar.gz");
83 if (dpkg_deb_extract == (dpkg_deb_extract & optflags)) {
84 strcpy(ar_filename, "data.tar.gz");
87 if (dpkg_deb_verbose_extract == (dpkg_deb_verbose_extract & optflags)) {
88 strcpy(ar_filename, "data.tar.gz");
93 ar_headers = (ar_headers_t *) xmalloc(sizeof(ar_headers_t));
94 srcFd = open(deb_filename, O_RDONLY);
96 *ar_headers = get_ar_headers(srcFd);
97 if (ar_headers->next == NULL) {
98 error_msg_and_die("Couldnt find %s in %s", ar_filename, deb_filename);
101 while (ar_headers->next != NULL) {
102 if (strcmp(ar_headers->name, ar_filename) == 0) {
105 ar_headers = ar_headers->next;
107 lseek(srcFd, ar_headers->offset, SEEK_SET);
108 /* Uncompress the file */
109 comp_file = fdopen(srcFd, "r");
110 if ((srcFd = gz_open(comp_file, &pid)) == EXIT_FAILURE) {
111 error_msg_and_die("Couldnt unzip file");
113 if ( dir_name != NULL) {
114 if (is_directory(dir_name, TRUE, NULL)==FALSE) {
115 mkdir(dir_name, 0755);
117 if (chdir(dir_name)==-1) {
118 error_msg_and_die("Cannot change to dir %s", dir_name);
121 status = readTarFile(srcFd, extract_flag, list_flag,
122 extract_to_stdout, verbose_flag, NULL, extract_list);
130 extern int dpkg_deb_main(int argc, char **argv)
132 char *target_dir = NULL;
136 while ((opt = getopt(argc, argv, "cexXl")) != -1) {
139 optflag |= dpkg_deb_contents;
142 optflag |= dpkg_deb_control;
145 optflag |= dpkg_deb_verbose_extract;
148 optflag |= dpkg_deb_extract;
151 optflag |= dpkg_deb_list;
154 optflag |= dpkg_deb_info;
162 if (((optind + 1 ) > argc) || (optflag == 0)) {
165 if ((optflag & dpkg_deb_control) || (optflag & dpkg_deb_extract) || (optflag & dpkg_deb_verbose_extract)) {
166 if ( (optind + 1) == argc ) {
167 target_dir = (char *) xmalloc(7);
168 strcpy(target_dir, "DEBIAN");
170 target_dir = (char *) xmalloc(strlen(argv[optind + 1]));
171 strcpy(target_dir, argv[optind + 1]);
174 deb_extract(optflag, target_dir, argv[optind]);
175 /* else if (optflag & dpkg_deb_info) {
177 extract_to_stdout = TRUE;
178 strcpy(ar_filename, "control.tar.gz");
179 extract_list = argv+optind+1;
180 printf("list one is [%s]\n",extract_list[0]);
183 return(EXIT_SUCCESS);