diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-12 10:19:08 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-12 10:19:08 +0000 |
commit | 359c1068719c295b25b2d8b81a6aded5aeb6e23d (patch) | |
tree | 680864ee0a5e6782c4fdfa9906ff902a44411524 | |
parent | 46079a1d7792dc3848667ddc875bd2467be1ddc1 (diff) | |
download | busybox-w32-359c1068719c295b25b2d8b81a6aded5aeb6e23d.tar.gz busybox-w32-359c1068719c295b25b2d8b81a6aded5aeb6e23d.tar.bz2 busybox-w32-359c1068719c295b25b2d8b81a6aded5aeb6e23d.zip |
Fix dpkg-deb, enum's are cool
-rw-r--r-- | archival/dpkg_deb.c | 35 | ||||
-rw-r--r-- | dpkg_deb.c | 35 | ||||
-rw-r--r-- | include/libbb.h | 14 | ||||
-rw-r--r-- | libbb/deb_extract.c | 34 | ||||
-rw-r--r-- | libbb/libbb.h | 14 | ||||
-rw-r--r-- | libbb/untar.c | 71 |
6 files changed, 108 insertions, 95 deletions
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index 3cdd4ffae..fbdb14e26 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c | |||
@@ -20,12 +20,6 @@ | |||
20 | 20 | ||
21 | extern int dpkg_deb_main(int argc, char **argv) | 21 | extern int dpkg_deb_main(int argc, char **argv) |
22 | { | 22 | { |
23 | const int dpkg_deb_contents = 1; | ||
24 | const int dpkg_deb_control = 2; | ||
25 | // const int dpkg_deb_info = 4; | ||
26 | const int dpkg_deb_extract = 8; | ||
27 | const int dpkg_deb_verbose_extract = 16; | ||
28 | const int dpkg_deb_list = 32; | ||
29 | char *target_dir = NULL; | 23 | char *target_dir = NULL; |
30 | int opt = 0; | 24 | int opt = 0; |
31 | int optflag = 0; | 25 | int optflag = 0; |
@@ -33,22 +27,22 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
33 | while ((opt = getopt(argc, argv, "cexXl")) != -1) { | 27 | while ((opt = getopt(argc, argv, "cexXl")) != -1) { |
34 | switch (opt) { | 28 | switch (opt) { |
35 | case 'c': | 29 | case 'c': |
36 | optflag |= dpkg_deb_contents; | 30 | optflag |= extract_contents; |
37 | break; | 31 | break; |
38 | case 'e': | 32 | case 'e': |
39 | optflag |= dpkg_deb_control; | 33 | optflag |= extract_control; |
40 | break; | 34 | break; |
41 | case 'X': | 35 | case 'X': |
42 | optflag |= dpkg_deb_verbose_extract; | 36 | optflag |= extract_verbose_extract; |
43 | break; | 37 | break; |
44 | case 'x': | 38 | case 'x': |
45 | optflag |= dpkg_deb_extract; | 39 | optflag |= extract_extract; |
46 | break; | 40 | break; |
47 | case 'l': | 41 | case 'l': |
48 | optflag |= dpkg_deb_list; | 42 | optflag |= extract_list; |
49 | break; | 43 | break; |
50 | /* case 'I': | 44 | /* case 'I': |
51 | optflag |= dpkg_deb_info; | 45 | optflag |= extract_info; |
52 | break; | 46 | break; |
53 | */ | 47 | */ |
54 | default: | 48 | default: |
@@ -59,14 +53,19 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
59 | if (((optind + 1 ) > argc) || (optflag == 0)) { | 53 | if (((optind + 1 ) > argc) || (optflag == 0)) { |
60 | show_usage(); | 54 | show_usage(); |
61 | } | 55 | } |
62 | if ((optflag & dpkg_deb_control) || (optflag & dpkg_deb_extract) || (optflag & dpkg_deb_verbose_extract)) { | 56 | switch (optflag) { |
63 | if ( (optind + 1) == argc ) { | 57 | case (extract_control): |
64 | target_dir = (char *) xmalloc(7); | 58 | case (extract_extract): |
65 | strcpy(target_dir, "DEBIAN"); | 59 | case (extract_verbose_extract): |
66 | } else { | 60 | if ( (optind + 1) == argc ) { |
61 | target_dir = (char *) xmalloc(7); | ||
62 | strcpy(target_dir, "DEBIAN"); | ||
63 | } | ||
64 | break; | ||
65 | default: { | ||
67 | target_dir = (char *) xmalloc(strlen(argv[optind + 1])); | 66 | target_dir = (char *) xmalloc(strlen(argv[optind + 1])); |
68 | strcpy(target_dir, argv[optind + 1]); | 67 | strcpy(target_dir, argv[optind + 1]); |
69 | } | 68 | } |
70 | } | 69 | } |
71 | deb_extract(argv[optind], optflag, target_dir); | 70 | deb_extract(argv[optind], optflag, target_dir); |
72 | /* else if (optflag & dpkg_deb_info) { | 71 | /* else if (optflag & dpkg_deb_info) { |
diff --git a/dpkg_deb.c b/dpkg_deb.c index 3cdd4ffae..fbdb14e26 100644 --- a/dpkg_deb.c +++ b/dpkg_deb.c | |||
@@ -20,12 +20,6 @@ | |||
20 | 20 | ||
21 | extern int dpkg_deb_main(int argc, char **argv) | 21 | extern int dpkg_deb_main(int argc, char **argv) |
22 | { | 22 | { |
23 | const int dpkg_deb_contents = 1; | ||
24 | const int dpkg_deb_control = 2; | ||
25 | // const int dpkg_deb_info = 4; | ||
26 | const int dpkg_deb_extract = 8; | ||
27 | const int dpkg_deb_verbose_extract = 16; | ||
28 | const int dpkg_deb_list = 32; | ||
29 | char *target_dir = NULL; | 23 | char *target_dir = NULL; |
30 | int opt = 0; | 24 | int opt = 0; |
31 | int optflag = 0; | 25 | int optflag = 0; |
@@ -33,22 +27,22 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
33 | while ((opt = getopt(argc, argv, "cexXl")) != -1) { | 27 | while ((opt = getopt(argc, argv, "cexXl")) != -1) { |
34 | switch (opt) { | 28 | switch (opt) { |
35 | case 'c': | 29 | case 'c': |
36 | optflag |= dpkg_deb_contents; | 30 | optflag |= extract_contents; |
37 | break; | 31 | break; |
38 | case 'e': | 32 | case 'e': |
39 | optflag |= dpkg_deb_control; | 33 | optflag |= extract_control; |
40 | break; | 34 | break; |
41 | case 'X': | 35 | case 'X': |
42 | optflag |= dpkg_deb_verbose_extract; | 36 | optflag |= extract_verbose_extract; |
43 | break; | 37 | break; |
44 | case 'x': | 38 | case 'x': |
45 | optflag |= dpkg_deb_extract; | 39 | optflag |= extract_extract; |
46 | break; | 40 | break; |
47 | case 'l': | 41 | case 'l': |
48 | optflag |= dpkg_deb_list; | 42 | optflag |= extract_list; |
49 | break; | 43 | break; |
50 | /* case 'I': | 44 | /* case 'I': |
51 | optflag |= dpkg_deb_info; | 45 | optflag |= extract_info; |
52 | break; | 46 | break; |
53 | */ | 47 | */ |
54 | default: | 48 | default: |
@@ -59,14 +53,19 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
59 | if (((optind + 1 ) > argc) || (optflag == 0)) { | 53 | if (((optind + 1 ) > argc) || (optflag == 0)) { |
60 | show_usage(); | 54 | show_usage(); |
61 | } | 55 | } |
62 | if ((optflag & dpkg_deb_control) || (optflag & dpkg_deb_extract) || (optflag & dpkg_deb_verbose_extract)) { | 56 | switch (optflag) { |
63 | if ( (optind + 1) == argc ) { | 57 | case (extract_control): |
64 | target_dir = (char *) xmalloc(7); | 58 | case (extract_extract): |
65 | strcpy(target_dir, "DEBIAN"); | 59 | case (extract_verbose_extract): |
66 | } else { | 60 | if ( (optind + 1) == argc ) { |
61 | target_dir = (char *) xmalloc(7); | ||
62 | strcpy(target_dir, "DEBIAN"); | ||
63 | } | ||
64 | break; | ||
65 | default: { | ||
67 | target_dir = (char *) xmalloc(strlen(argv[optind + 1])); | 66 | target_dir = (char *) xmalloc(strlen(argv[optind + 1])); |
68 | strcpy(target_dir, argv[optind + 1]); | 67 | strcpy(target_dir, argv[optind + 1]); |
69 | } | 68 | } |
70 | } | 69 | } |
71 | deb_extract(argv[optind], optflag, target_dir); | 70 | deb_extract(argv[optind], optflag, target_dir); |
72 | /* else if (optflag & dpkg_deb_info) { | 71 | /* else if (optflag & dpkg_deb_info) { |
diff --git a/include/libbb.h b/include/libbb.h index 8a5e6756f..46a0682b2 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -227,8 +227,18 @@ typedef struct ar_headers_s { | |||
227 | } ar_headers_t; | 227 | } ar_headers_t; |
228 | extern ar_headers_t *get_ar_headers(FILE *in_file); | 228 | extern ar_headers_t *get_ar_headers(FILE *in_file); |
229 | extern int seek_ared_file(FILE *in_file, ar_headers_t *headers, const char *tar_gz_file); | 229 | extern int seek_ared_file(FILE *in_file, ar_headers_t *headers, const char *tar_gz_file); |
230 | extern int deb_extract(const char *package_filename, const int function, char *target_dir); | 230 | |
231 | extern int untar(FILE *src_tar_file, int untar_function, char *base_path); | 231 | typedef enum extract_function_e { |
232 | extract_contents = 1, | ||
233 | extract_control = 2, | ||
234 | extract_info = 4, | ||
235 | extract_extract = 8, | ||
236 | extract_verbose_extract = 16, | ||
237 | extract_list = 32 | ||
238 | } extract_function_t; | ||
239 | extern int deb_extract(const char *package_filename, int function, char *target_dir); | ||
240 | extern int untar(FILE *src_tar_file, int function, char *base_path); | ||
241 | |||
232 | extern int unzip(FILE *l_in_file, FILE *l_out_file); | 242 | extern int unzip(FILE *l_in_file, FILE *l_out_file); |
233 | extern void gz_close(int gunzip_pid); | 243 | extern void gz_close(int gunzip_pid); |
234 | extern int gz_open(FILE *compressed_file, int *pid); | 244 | extern int gz_open(FILE *compressed_file, int *pid); |
diff --git a/libbb/deb_extract.c b/libbb/deb_extract.c index 35ff99671..e982c14bb 100644 --- a/libbb/deb_extract.c +++ b/libbb/deb_extract.c | |||
@@ -29,25 +29,27 @@ | |||
29 | #include <signal.h> | 29 | #include <signal.h> |
30 | #include "libbb.h" | 30 | #include "libbb.h" |
31 | 31 | ||
32 | const int dpkg_deb_contents = 1; | 32 | extern int deb_extract(const char *package_filename, int function, char *target_dir) |
33 | const int dpkg_deb_control = 2; | ||
34 | const int dpkg_deb_info = 4; | ||
35 | const int dpkg_deb_extract = 8; | ||
36 | const int dpkg_deb_verbose_extract = 16; | ||
37 | const int dpkg_deb_list = 32; | ||
38 | |||
39 | extern int deb_extract(const char *package_filename, const int function, char *target_dir) | ||
40 | { | 33 | { |
41 | 34 | ||
42 | FILE *deb_file, *uncompressed_file; | 35 | FILE *deb_file, *uncompressed_file; |
43 | ar_headers_t *headers = NULL; | 36 | ar_headers_t *headers = NULL; |
44 | char *ared_file; | 37 | char *ared_file = NULL; |
45 | int gunzip_pid; | 38 | int gunzip_pid; |
46 | 39 | ||
47 | if ((function == dpkg_deb_info) || (function == dpkg_deb_control)) { | 40 | switch (function) { |
48 | ared_file = xstrdup("control.tar.gz"); | 41 | case (extract_info): |
49 | } else { | 42 | case (extract_control): |
50 | ared_file = xstrdup("data.tar.gz"); | 43 | ared_file = xstrdup("control.tar.gz"); |
44 | break; | ||
45 | case (extract_contents): | ||
46 | case (extract_extract): | ||
47 | case (extract_verbose_extract): | ||
48 | case (extract_list): | ||
49 | ared_file = xstrdup("data.tar.gz"); | ||
50 | break; | ||
51 | default: | ||
52 | error_msg("Unknown extraction function"); | ||
51 | } | 53 | } |
52 | 54 | ||
53 | /* open the debian package to be worked on */ | 55 | /* open the debian package to be worked on */ |
@@ -70,12 +72,14 @@ extern int deb_extract(const char *package_filename, const int function, char *t | |||
70 | uncompressed_file = fdopen(gz_open(deb_file, &gunzip_pid), "r"); | 72 | uncompressed_file = fdopen(gz_open(deb_file, &gunzip_pid), "r"); |
71 | 73 | ||
72 | /* get a list of all tar headers inside the .gz file */ | 74 | /* get a list of all tar headers inside the .gz file */ |
73 | untar(uncompressed_file, dpkg_deb_extract, target_dir); | 75 | untar(uncompressed_file, function, target_dir); |
74 | 76 | ||
75 | /* we are deliberately terminating the child so we can safely ignore this */ | 77 | /* we are deliberately terminating the child so we can safely ignore this */ |
76 | signal(SIGTERM, SIG_IGN); | ||
77 | gz_close(gunzip_pid); | 78 | gz_close(gunzip_pid); |
79 | |||
78 | fclose(deb_file); | 80 | fclose(deb_file); |
79 | fclose(uncompressed_file); | 81 | fclose(uncompressed_file); |
82 | free(ared_file); | ||
83 | |||
80 | return(EXIT_SUCCESS); | 84 | return(EXIT_SUCCESS); |
81 | } \ No newline at end of file | 85 | } \ No newline at end of file |
diff --git a/libbb/libbb.h b/libbb/libbb.h index 8a5e6756f..46a0682b2 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h | |||
@@ -227,8 +227,18 @@ typedef struct ar_headers_s { | |||
227 | } ar_headers_t; | 227 | } ar_headers_t; |
228 | extern ar_headers_t *get_ar_headers(FILE *in_file); | 228 | extern ar_headers_t *get_ar_headers(FILE *in_file); |
229 | extern int seek_ared_file(FILE *in_file, ar_headers_t *headers, const char *tar_gz_file); | 229 | extern int seek_ared_file(FILE *in_file, ar_headers_t *headers, const char *tar_gz_file); |
230 | extern int deb_extract(const char *package_filename, const int function, char *target_dir); | 230 | |
231 | extern int untar(FILE *src_tar_file, int untar_function, char *base_path); | 231 | typedef enum extract_function_e { |
232 | extract_contents = 1, | ||
233 | extract_control = 2, | ||
234 | extract_info = 4, | ||
235 | extract_extract = 8, | ||
236 | extract_verbose_extract = 16, | ||
237 | extract_list = 32 | ||
238 | } extract_function_t; | ||
239 | extern int deb_extract(const char *package_filename, int function, char *target_dir); | ||
240 | extern int untar(FILE *src_tar_file, int function, char *base_path); | ||
241 | |||
232 | extern int unzip(FILE *l_in_file, FILE *l_out_file); | 242 | extern int unzip(FILE *l_in_file, FILE *l_out_file); |
233 | extern void gz_close(int gunzip_pid); | 243 | extern void gz_close(int gunzip_pid); |
234 | extern int gz_open(FILE *compressed_file, int *pid); | 244 | extern int gz_open(FILE *compressed_file, int *pid); |
diff --git a/libbb/untar.c b/libbb/untar.c index 1542e390d..cb312d597 100644 --- a/libbb/untar.c +++ b/libbb/untar.c | |||
@@ -44,13 +44,6 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
44 | char padding[12]; /* 500-512 */ | 44 | char padding[12]; /* 500-512 */ |
45 | } raw_tar_header_t; | 45 | } raw_tar_header_t; |
46 | 46 | ||
47 | // const int dpkg_deb_contents = 1; | ||
48 | // const int dpkg_deb_control = 2; | ||
49 | // const int dpkg_deb_info = 4; | ||
50 | const int untar_extract = 8; | ||
51 | // const int dpkg_deb_verbose_extract = 16; | ||
52 | // const int dpkg_deb_list = 32; | ||
53 | |||
54 | raw_tar_header_t raw_tar_header; | 47 | raw_tar_header_t raw_tar_header; |
55 | unsigned char *temp = (unsigned char *) &raw_tar_header; | 48 | unsigned char *temp = (unsigned char *) &raw_tar_header; |
56 | long i; | 49 | long i; |
@@ -61,7 +54,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
61 | 54 | ||
62 | // signal(SIGCHLD, child_died); | 55 | // signal(SIGCHLD, child_died); |
63 | 56 | ||
64 | while (fread((char *) &raw_tar_header, 1, 512, src_tar_file)==512) { | 57 | while (fread((char *) &raw_tar_header, 1, 512, src_tar_file) == 512) { |
65 | long sum = 0; | 58 | long sum = 0; |
66 | char *dir; | 59 | char *dir; |
67 | 60 | ||
@@ -130,30 +123,41 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
130 | * supposed to be a directory, and fall through | 123 | * supposed to be a directory, and fall through |
131 | */ | 124 | */ |
132 | if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') { | 125 | if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') { |
133 | if (untar_function & untar_extract) { | 126 | switch (untar_function) { |
134 | int out_count=0; | 127 | case (extract_verbose_extract): |
135 | FILE *dst_file; | 128 | printf("%s\n", raw_tar_header.name); |
136 | 129 | case (extract_extract): { | |
137 | dst_file = wfopen(dir, "w"); | 130 | FILE *dst_file = wfopen(dir, "w"); |
138 | if (copy_file_chunk(src_tar_file, dst_file, size) == FALSE) { | 131 | copy_file_chunk(src_tar_file, dst_file, size); |
139 | error_msg_and_die("Couldnt extract file"); | 132 | fclose(dst_file); |
140 | } | 133 | } |
141 | uncompressed_count += out_count; | 134 | break; |
142 | fclose(dst_file); | 135 | default: { |
143 | break; | 136 | int remaining = size; |
137 | while (remaining-- > 0) { | ||
138 | fgetc(src_tar_file); | ||
139 | } | ||
140 | } | ||
144 | } | 141 | } |
142 | uncompressed_count += size; | ||
143 | break; | ||
145 | } | 144 | } |
146 | case '5': | 145 | case '5': |
147 | if (untar_function & untar_extract) { | 146 | switch (untar_function) { |
148 | if (create_path(dir, mode) != TRUE) { | 147 | case (extract_verbose_extract): |
149 | free(dir); | 148 | printf("%s\n", raw_tar_header.name); |
150 | perror_msg("%s: Cannot mkdir", raw_tar_header.name); | 149 | case (extract_extract): |
151 | return(EXIT_FAILURE); | 150 | if (create_path(dir, mode) != TRUE) { |
152 | } | 151 | free(dir); |
152 | perror_msg("%s: Cannot mkdir", raw_tar_header.name); | ||
153 | return(EXIT_FAILURE); | ||
154 | } | ||
155 | break; | ||
156 | default: | ||
153 | } | 157 | } |
154 | break; | 158 | break; |
155 | case '1': | 159 | case '1': |
156 | if (untar_function & untar_extract) { | 160 | if (untar_function & extract_extract) { |
157 | if (link(raw_tar_header.linkname, raw_tar_header.name) < 0) { | 161 | if (link(raw_tar_header.linkname, raw_tar_header.name) < 0) { |
158 | free(dir); | 162 | free(dir); |
159 | perror_msg("%s: Cannot create hard link to '%s'", raw_tar_header.name, raw_tar_header.linkname); | 163 | perror_msg("%s: Cannot create hard link to '%s'", raw_tar_header.name, raw_tar_header.linkname); |
@@ -162,7 +166,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
162 | } | 166 | } |
163 | break; | 167 | break; |
164 | case '2': | 168 | case '2': |
165 | if (untar_function & untar_extract) { | 169 | if (untar_function & extract_extract) { |
166 | if (symlink(raw_tar_header.linkname, raw_tar_header.name) < 0) { | 170 | if (symlink(raw_tar_header.linkname, raw_tar_header.name) < 0) { |
167 | free(dir); | 171 | free(dir); |
168 | perror_msg("%s: Cannot create symlink to '%s'", raw_tar_header.name, raw_tar_header.linkname); | 172 | perror_msg("%s: Cannot create symlink to '%s'", raw_tar_header.name, raw_tar_header.linkname); |
@@ -183,18 +187,5 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
183 | } | 187 | } |
184 | free(dir); | 188 | free(dir); |
185 | } | 189 | } |
186 | /* skip to start of next header */ | ||
187 | while(uncompressed_count < next_header_offset) { | ||
188 | char ch[2]; | ||
189 | if (fread(ch, 1, 1, src_tar_file) != 1) { | ||
190 | error_msg("read error\n"); | ||
191 | getchar(); | ||
192 | } else { | ||
193 | uncompressed_count++; | ||
194 | } | ||
195 | } | ||
196 | /* | ||
197 | * TODO: Check that gunzip child hasnt finished | ||
198 | */ | ||
199 | return(EXIT_SUCCESS); | 190 | return(EXIT_SUCCESS); |
200 | } | 191 | } |