diff options
| author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-15 12:51:59 +0000 |
|---|---|---|
| committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-15 12:51:59 +0000 |
| commit | 245319d30ac97165c4dfd3e481f040d358a54e51 (patch) | |
| tree | 1afa19b480add8d7c3a582b93b31971c23d5594f | |
| parent | f5ae171d86fedf0e1d45cfc57cfc891834dda221 (diff) | |
| download | busybox-w32-245319d30ac97165c4dfd3e481f040d358a54e51.tar.gz busybox-w32-245319d30ac97165c4dfd3e481f040d358a54e51.tar.bz2 busybox-w32-245319d30ac97165c4dfd3e481f040d358a54e51.zip | |
untar changed to allow deb_extract to extract to memory, allows better operation of dpkg-deb -f
git-svn-id: svn://busybox.net/trunk/busybox@2348 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | include/libbb.h | 4 | ||||
| -rw-r--r-- | libbb/deb_extract.c | 19 | ||||
| -rw-r--r-- | libbb/libbb.h | 4 | ||||
| -rw-r--r-- | libbb/untar.c | 65 |
4 files changed, 51 insertions, 41 deletions
diff --git a/include/libbb.h b/include/libbb.h index 515bf2760..569ed9397 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -239,7 +239,9 @@ typedef enum extract_function_e { | |||
| 239 | extract_field = 128 | 239 | extract_field = 128 |
| 240 | } extract_function_t; | 240 | } extract_function_t; |
| 241 | extern int deb_extract(const char *package_filename, int function, char *target_dir); | 241 | extern int deb_extract(const char *package_filename, int function, char *target_dir); |
| 242 | extern int untar(FILE *src_tar_file, const int untar_function, const char *argument); | 242 | extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, const char *argument); |
| 243 | extern char *read_text_file_to_buffer(FILE *src_file); | ||
| 244 | extern char *read_package_field(const char *package_buffer); | ||
| 243 | 245 | ||
| 244 | extern int unzip(FILE *l_in_file, FILE *l_out_file); | 246 | extern int unzip(FILE *l_in_file, FILE *l_out_file); |
| 245 | extern void gz_close(int gunzip_pid); | 247 | extern void gz_close(int gunzip_pid); |
diff --git a/libbb/deb_extract.c b/libbb/deb_extract.c index 0f5a570b6..b95dfa4d4 100644 --- a/libbb/deb_extract.c +++ b/libbb/deb_extract.c | |||
| @@ -75,11 +75,24 @@ extern int deb_extract(const char *package_filename, int function, char *argumen | |||
| 75 | if (function & extract_fsys_tarfile) { | 75 | if (function & extract_fsys_tarfile) { |
| 76 | copy_file_chunk(uncompressed_file, stdout, -1); | 76 | copy_file_chunk(uncompressed_file, stdout, -1); |
| 77 | } else { | 77 | } else { |
| 78 | untar(uncompressed_file, function, argument); | 78 | char *output_buffer = NULL; |
| 79 | output_buffer = untar(uncompressed_file, stdout, function, argument); | ||
| 80 | if (function & extract_field) { | ||
| 81 | char *field = NULL; | ||
| 82 | int field_length = 0; | ||
| 83 | int field_start = 0; | ||
| 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 | } | ||
| 79 | } | 93 | } |
| 80 | /* we are deliberately terminating the child so we can safely ignore this */ | ||
| 81 | gz_close(gunzip_pid); | ||
| 82 | 94 | ||
| 95 | gz_close(gunzip_pid); | ||
| 83 | fclose(deb_file); | 96 | fclose(deb_file); |
| 84 | fclose(uncompressed_file); | 97 | fclose(uncompressed_file); |
| 85 | free(ared_file); | 98 | free(ared_file); |
diff --git a/libbb/libbb.h b/libbb/libbb.h index 515bf2760..569ed9397 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h | |||
| @@ -239,7 +239,9 @@ typedef enum extract_function_e { | |||
| 239 | extract_field = 128 | 239 | extract_field = 128 |
| 240 | } extract_function_t; | 240 | } extract_function_t; |
| 241 | extern int deb_extract(const char *package_filename, int function, char *target_dir); | 241 | extern int deb_extract(const char *package_filename, int function, char *target_dir); |
| 242 | extern int untar(FILE *src_tar_file, const int untar_function, const char *argument); | 242 | extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, const char *argument); |
| 243 | extern char *read_text_file_to_buffer(FILE *src_file); | ||
| 244 | extern char *read_package_field(const char *package_buffer); | ||
| 243 | 245 | ||
| 244 | extern int unzip(FILE *l_in_file, FILE *l_out_file); | 246 | extern int unzip(FILE *l_in_file, FILE *l_out_file); |
| 245 | extern void gz_close(int gunzip_pid); | 247 | extern void gz_close(int gunzip_pid); |
diff --git a/libbb/untar.c b/libbb/untar.c index b768c0be8..e70032c60 100644 --- a/libbb/untar.c +++ b/libbb/untar.c | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | #include <unistd.h> | 22 | #include <unistd.h> |
| 23 | #include "libbb.h" | 23 | #include "libbb.h" |
| 24 | 24 | ||
| 25 | extern int untar(FILE *src_tar_file, const int untar_function, const char *argument) | 25 | extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, const char *argument) |
| 26 | { | 26 | { |
| 27 | typedef struct raw_tar_header { | 27 | typedef struct raw_tar_header { |
| 28 | char name[100]; /* 0-99 */ | 28 | char name[100]; /* 0-99 */ |
| @@ -103,13 +103,12 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum | |||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | if (untar_function & (extract_contents | extract_verbose_extract)) { | 105 | if (untar_function & (extract_contents | extract_verbose_extract)) { |
| 106 | printf("%s\n", raw_tar_header.name); | 106 | fprintf(output, "%s\n", raw_tar_header.name); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | /* extract files */ | 109 | /* extract files */ |
| 110 | if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) { | 110 | if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) { |
| 111 | dir = xmalloc(strlen(raw_tar_header.name) + strlen(argument) + 2); | 111 | dir = concat_path_file(argument, raw_tar_header.name); |
| 112 | sprintf(dir, "%s/%s", argument, raw_tar_header.name); | ||
| 113 | create_path(dir, 0777); | 112 | create_path(dir, 0777); |
| 114 | } | 113 | } |
| 115 | 114 | ||
| @@ -120,33 +119,27 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum | |||
| 120 | * supposed to be a directory, and fall through | 119 | * supposed to be a directory, and fall through |
| 121 | */ | 120 | */ |
| 122 | if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') { | 121 | if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') { |
| 123 | if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) { | 122 | switch (untar_function) { |
| 124 | FILE *dst_file = wfopen(dir, "w"); | 123 | case (extract_extract): |
| 125 | copy_file_chunk(src_tar_file, dst_file, (unsigned long long) size); | 124 | case (extract_verbose_extract): |
| 126 | uncompressed_count += size; | 125 | case (extract_control): { |
| 127 | fclose(dst_file); | 126 | FILE *dst_file = wfopen(dir, "w"); |
| 128 | } | 127 | copy_file_chunk(src_tar_file, dst_file, (unsigned long long) size); |
| 129 | else if (untar_function & extract_info) { | 128 | uncompressed_count += size; |
| 130 | if (strstr(raw_tar_header.name, argument) != NULL) { | 129 | fclose(dst_file); |
| 131 | copy_file_chunk(src_tar_file, stdout, (unsigned long long) size); | 130 | } |
| 132 | uncompressed_count += size; | 131 | break; |
| 133 | } | 132 | case (extract_info): |
| 134 | } | 133 | if (strstr(raw_tar_header.name, argument) != NULL) { |
| 135 | else if (untar_function & extract_field) { | 134 | copy_file_chunk(src_tar_file, stdout, (unsigned long long) size); |
| 136 | if (strstr(raw_tar_header.name, "./control") != NULL) { | 135 | uncompressed_count += size; |
| 137 | char *line; | 136 | } |
| 138 | while ((line = get_line_from_file(src_tar_file)) != NULL) { | 137 | break; |
| 139 | uncompressed_count += strlen(line); | 138 | case (extract_field): |
| 140 | if (argument == NULL) { | 139 | if (strstr(raw_tar_header.name, "control") != NULL) { |
| 141 | printf("%s",line); | 140 | return(read_text_file_to_buffer(src_tar_file)); |
| 142 | } | 141 | } |
| 143 | else if (strncmp(line, argument, strlen(argument)) == 0) { | 142 | break; |
| 144 | char *file_ptr; | ||
| 145 | file_ptr = strstr(line, ": "); | ||
| 146 | printf("%s", file_ptr + 2); | ||
| 147 | } | ||
| 148 | } | ||
| 149 | } | ||
| 150 | } | 143 | } |
| 151 | break; | 144 | break; |
| 152 | } | 145 | } |
| @@ -155,7 +148,7 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum | |||
| 155 | if (create_path(dir, mode) != TRUE) { | 148 | if (create_path(dir, mode) != TRUE) { |
| 156 | free(dir); | 149 | free(dir); |
| 157 | perror_msg("%s: Cannot mkdir", raw_tar_header.name); | 150 | perror_msg("%s: Cannot mkdir", raw_tar_header.name); |
| 158 | return(EXIT_FAILURE); | 151 | return NULL; |
| 159 | } | 152 | } |
| 160 | } | 153 | } |
| 161 | break; | 154 | break; |
| @@ -164,7 +157,7 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum | |||
| 164 | if (link(raw_tar_header.linkname, raw_tar_header.name) < 0) { | 157 | if (link(raw_tar_header.linkname, raw_tar_header.name) < 0) { |
| 165 | free(dir); | 158 | free(dir); |
| 166 | perror_msg("%s: Cannot create hard link to '%s'", raw_tar_header.name, raw_tar_header.linkname); | 159 | perror_msg("%s: Cannot create hard link to '%s'", raw_tar_header.name, raw_tar_header.linkname); |
| 167 | return(EXIT_FAILURE); | 160 | return NULL; |
| 168 | } | 161 | } |
| 169 | } | 162 | } |
| 170 | break; | 163 | break; |
| @@ -173,7 +166,7 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum | |||
| 173 | if (symlink(raw_tar_header.linkname, raw_tar_header.name) < 0) { | 166 | if (symlink(raw_tar_header.linkname, raw_tar_header.name) < 0) { |
| 174 | free(dir); | 167 | free(dir); |
| 175 | perror_msg("%s: Cannot create symlink to '%s'", raw_tar_header.name, raw_tar_header.linkname); | 168 | perror_msg("%s: Cannot create symlink to '%s'", raw_tar_header.name, raw_tar_header.linkname); |
| 176 | return(EXIT_FAILURE); | 169 | return NULL; |
| 177 | } | 170 | } |
| 178 | } | 171 | } |
| 179 | break; | 172 | break; |
| @@ -186,7 +179,7 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum | |||
| 186 | default: | 179 | default: |
| 187 | error_msg("Unknown file type '%c' in tar file", raw_tar_header.typeflag); | 180 | error_msg("Unknown file type '%c' in tar file", raw_tar_header.typeflag); |
| 188 | free(dir); | 181 | free(dir); |
| 189 | return(EXIT_FAILURE); | 182 | return NULL; |
| 190 | } | 183 | } |
| 191 | 184 | ||
| 192 | /* | 185 | /* |
| @@ -201,5 +194,5 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum | |||
| 201 | 194 | ||
| 202 | // free(dir); | 195 | // free(dir); |
| 203 | } | 196 | } |
| 204 | return(EXIT_SUCCESS); | 197 | return NULL; |
| 205 | } | 198 | } |
