diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-16 04:52:19 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-16 04:52:19 +0000 |
commit | 33431ebb9ace3fba76138198596f8155c2e14354 (patch) | |
tree | 514459eccbc4927b00c0493badb7f12575c9147d /libbb | |
parent | 3136904ff69b3f67096dbaf2afd9ac77256c4bae (diff) | |
download | busybox-w32-33431ebb9ace3fba76138198596f8155c2e14354.tar.gz busybox-w32-33431ebb9ace3fba76138198596f8155c2e14354.tar.bz2 busybox-w32-33431ebb9ace3fba76138198596f8155c2e14354.zip |
dpkg improvements, use full package struct, avoid extracting to tmp dir, rename variable.
deb_extract, untar and dpkg_deb modified to make the above possible
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/deb_extract.c | 33 | ||||
-rw-r--r-- | libbb/libbb.h | 9 | ||||
-rw-r--r-- | libbb/untar.c | 42 |
3 files changed, 59 insertions, 25 deletions
diff --git a/libbb/deb_extract.c b/libbb/deb_extract.c index b95dfa4d4..36cebfa51 100644 --- a/libbb/deb_extract.c +++ b/libbb/deb_extract.c | |||
@@ -34,12 +34,13 @@ | |||
34 | * The contents of argument depend on the value of function. | 34 | * The contents of argument depend on the value of function. |
35 | * It is either a dir name or a control file or field name(see dpkg_deb.c) | 35 | * It is either a dir name or a control file or field name(see dpkg_deb.c) |
36 | */ | 36 | */ |
37 | extern int deb_extract(const char *package_filename, int function, char *argument) | 37 | extern char *deb_extract(const char *package_filename, const int function, const char *argument, const char *argument2) |
38 | { | 38 | { |
39 | 39 | ||
40 | FILE *deb_file, *uncompressed_file; | 40 | FILE *deb_file, *uncompressed_file; |
41 | ar_headers_t *headers = NULL; | 41 | ar_headers_t *headers = NULL; |
42 | char *ared_file = NULL; | 42 | char *ared_file = NULL; |
43 | char *output_buffer = NULL; | ||
43 | int gunzip_pid; | 44 | int gunzip_pid; |
44 | 45 | ||
45 | switch (function) { | 46 | switch (function) { |
@@ -61,7 +62,7 @@ extern int deb_extract(const char *package_filename, int function, char *argumen | |||
61 | /* get a linked list of all ar entries */ | 62 | /* get a linked list of all ar entries */ |
62 | if ((headers = get_ar_headers(deb_file)) == NULL) { | 63 | if ((headers = get_ar_headers(deb_file)) == NULL) { |
63 | error_msg("Couldnt get ar headers\n"); | 64 | error_msg("Couldnt get ar headers\n"); |
64 | return(EXIT_FAILURE); | 65 | return(NULL); |
65 | } | 66 | } |
66 | 67 | ||
67 | /* seek to the start of the .tar.gz file within the ar file*/ | 68 | /* seek to the start of the .tar.gz file within the ar file*/ |
@@ -75,27 +76,23 @@ extern int deb_extract(const char *package_filename, int function, char *argumen | |||
75 | if (function & extract_fsys_tarfile) { | 76 | if (function & extract_fsys_tarfile) { |
76 | copy_file_chunk(uncompressed_file, stdout, -1); | 77 | copy_file_chunk(uncompressed_file, stdout, -1); |
77 | } else { | 78 | } else { |
78 | char *output_buffer = NULL; | 79 | FILE *output; |
79 | output_buffer = untar(uncompressed_file, stdout, function, argument); | 80 | |
80 | if (function & extract_field) { | 81 | if (function & extract_contents_to_file) { |
81 | char *field = NULL; | 82 | output = wfopen(argument, "w"); |
82 | int field_length = 0; | 83 | } else { |
83 | int field_start = 0; | 84 | output = stdout; |
84 | while ((field = read_package_field(&output_buffer[field_start])) != NULL) { | ||
85 | field_length = strlen(field); | ||
86 | field_start += (field_length + 1); | ||
87 | if (strstr(field, argument) == field) { | ||
88 | printf("%s\n", field + strlen(argument) + 2); | ||
89 | } | ||
90 | free(field); | ||
91 | } | ||
92 | } | 85 | } |
93 | } | ||
94 | 86 | ||
87 | output_buffer = untar(uncompressed_file, output, function, argument, argument2); | ||
88 | if (output != stdout) { | ||
89 | fclose(output); | ||
90 | } | ||
91 | } | ||
95 | gz_close(gunzip_pid); | 92 | gz_close(gunzip_pid); |
96 | fclose(deb_file); | 93 | fclose(deb_file); |
97 | fclose(uncompressed_file); | 94 | fclose(uncompressed_file); |
98 | free(ared_file); | 95 | free(ared_file); |
99 | 96 | ||
100 | return(EXIT_SUCCESS); | 97 | return(output_buffer); |
101 | } \ No newline at end of file | 98 | } \ No newline at end of file |
diff --git a/libbb/libbb.h b/libbb/libbb.h index 569ed9397..4b06ad12c 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h | |||
@@ -236,10 +236,13 @@ typedef enum extract_function_e { | |||
236 | extract_verbose_extract = 16, | 236 | extract_verbose_extract = 16, |
237 | extract_list = 32, | 237 | extract_list = 32, |
238 | extract_fsys_tarfile = 64, | 238 | extract_fsys_tarfile = 64, |
239 | extract_field = 128 | 239 | extract_field = 128, |
240 | extract_contents_to_file = 256 | ||
240 | } extract_function_t; | 241 | } extract_function_t; |
241 | extern int deb_extract(const char *package_filename, int function, char *target_dir); | 242 | extern char *deb_extract(const char *package_filename, const int function, |
242 | extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, const char *argument); | 243 | const char *argument, const char *argument2); |
244 | extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, | ||
245 | const char *argument, const char *file_prefix); | ||
243 | extern char *read_text_file_to_buffer(FILE *src_file); | 246 | extern char *read_text_file_to_buffer(FILE *src_file); |
244 | extern char *read_package_field(const char *package_buffer); | 247 | extern char *read_package_field(const char *package_buffer); |
245 | 248 | ||
diff --git a/libbb/untar.c b/libbb/untar.c index e70032c60..a77d94f61 100644 --- a/libbb/untar.c +++ b/libbb/untar.c | |||
@@ -22,7 +22,8 @@ | |||
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | #include "libbb.h" | 23 | #include "libbb.h" |
24 | 24 | ||
25 | extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, const char *argument) | 25 | extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, |
26 | const char *argument, const char *file_prefix) | ||
26 | { | 27 | { |
27 | typedef struct raw_tar_header { | 28 | typedef struct raw_tar_header { |
28 | char name[100]; /* 0-99 */ | 29 | char name[100]; /* 0-99 */ |
@@ -102,7 +103,21 @@ extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, c | |||
102 | next_header_offset += (512 - size % 512); | 103 | next_header_offset += (512 - size % 512); |
103 | } | 104 | } |
104 | 105 | ||
105 | if (untar_function & (extract_contents | extract_verbose_extract)) { | 106 | /* If an exclude list is specified check current file against list |
107 | if (*exclude_list != NULL) { | ||
108 | i = 0; | ||
109 | while (exclude_list[i] != 0) { | ||
110 | if (strncmp(exclude_list[i], raw_tar_header.name, strlen(raw_tar_header.name)) == 0) { | ||
111 | break; | ||
112 | } | ||
113 | i++; | ||
114 | } | ||
115 | if (exclude_list[i] != 0) { | ||
116 | continue; | ||
117 | } | ||
118 | } */ | ||
119 | |||
120 | if (untar_function & (extract_contents | extract_verbose_extract | extract_contents_to_file)) { | ||
106 | fprintf(output, "%s\n", raw_tar_header.name); | 121 | fprintf(output, "%s\n", raw_tar_header.name); |
107 | } | 122 | } |
108 | 123 | ||
@@ -123,10 +138,29 @@ extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, c | |||
123 | case (extract_extract): | 138 | case (extract_extract): |
124 | case (extract_verbose_extract): | 139 | case (extract_verbose_extract): |
125 | case (extract_control): { | 140 | case (extract_control): { |
126 | FILE *dst_file = wfopen(dir, "w"); | 141 | FILE *dst_file = NULL; |
142 | char *full_name; | ||
143 | |||
144 | if (file_prefix != NULL) { | ||
145 | char *file_name = NULL, *file_extension = NULL; | ||
146 | |||
147 | file_extension = xmalloc(strlen(raw_tar_header.name) + 1); | ||
148 | file_extension = strrchr(raw_tar_header.name, '/'); | ||
149 | file_extension++; | ||
150 | file_name = xmalloc(strlen(file_prefix) + strlen(file_extension) + 2); | ||
151 | strcpy(file_name, file_prefix); | ||
152 | strcat(file_name, "."); | ||
153 | strcat(file_name, file_extension); | ||
154 | |||
155 | full_name = concat_path_file(strndup(dir, strlen(dir) - strlen(strrchr(dir, '/'))), file_name); | ||
156 | } else { | ||
157 | full_name = xstrdup(dir); | ||
158 | } | ||
159 | dst_file = wfopen(full_name, "w"); | ||
127 | copy_file_chunk(src_tar_file, dst_file, (unsigned long long) size); | 160 | copy_file_chunk(src_tar_file, dst_file, (unsigned long long) size); |
128 | uncompressed_count += size; | 161 | uncompressed_count += size; |
129 | fclose(dst_file); | 162 | fclose(dst_file); |
163 | chmod(full_name, mode); | ||
130 | } | 164 | } |
131 | break; | 165 | break; |
132 | case (extract_info): | 166 | case (extract_info): |
@@ -136,7 +170,7 @@ extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, c | |||
136 | } | 170 | } |
137 | break; | 171 | break; |
138 | case (extract_field): | 172 | case (extract_field): |
139 | if (strstr(raw_tar_header.name, "control") != NULL) { | 173 | if (strstr(raw_tar_header.name, "./control") != NULL) { |
140 | return(read_text_file_to_buffer(src_tar_file)); | 174 | return(read_text_file_to_buffer(src_tar_file)); |
141 | } | 175 | } |
142 | break; | 176 | break; |