diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-12 16:40:21 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-12 16:40:21 +0000 |
commit | 5a65413c042e2538eda94b2efebd1bf4680ca986 (patch) | |
tree | 21295b2a49dd8d1f3a1f7348f2536d1eefe4c3a4 | |
parent | 47fd219c956d1963fca0ba73ff7b21b1273977a7 (diff) | |
download | busybox-w32-5a65413c042e2538eda94b2efebd1bf4680ca986.tar.gz busybox-w32-5a65413c042e2538eda94b2efebd1bf4680ca986.tar.bz2 busybox-w32-5a65413c042e2538eda94b2efebd1bf4680ca986.zip |
Updates, fixes for handling contents, verbose extract.
More updates to come
-rw-r--r-- | libbb/untar.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/libbb/untar.c b/libbb/untar.c index 11c55df7c..d3e424e25 100644 --- a/libbb/untar.c +++ b/libbb/untar.c | |||
@@ -57,6 +57,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
57 | char *dir = NULL; | 57 | char *dir = NULL; |
58 | 58 | ||
59 | if (ferror(src_tar_file) || feof(src_tar_file)) { | 59 | if (ferror(src_tar_file) || feof(src_tar_file)) { |
60 | perror_msg("untar: "); | ||
60 | break; | 61 | break; |
61 | } | 62 | } |
62 | 63 | ||
@@ -100,7 +101,6 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
100 | if (size % 512 != 0) { | 101 | if (size % 512 != 0) { |
101 | next_header_offset += (512 - size % 512); | 102 | next_header_offset += (512 - size % 512); |
102 | } | 103 | } |
103 | |||
104 | /* | 104 | /* |
105 | * seek to start of control file, return length | 105 | * seek to start of control file, return length |
106 | * | 106 | * |
@@ -139,25 +139,24 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
139 | * supposed to be a directory, and fall through | 139 | * supposed to be a directory, and fall through |
140 | */ | 140 | */ |
141 | if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') { | 141 | if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') { |
142 | switch (untar_function) { | 142 | if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) { |
143 | case (extract_extract): { | 143 | FILE *dst_file = wfopen(dir, "w"); |
144 | FILE *dst_file = wfopen(dir, "w"); | 144 | copy_file_chunk(src_tar_file, dst_file, (unsigned long long) size); |
145 | copy_file_chunk(src_tar_file, dst_file, size); | 145 | uncompressed_count += size; |
146 | fclose(dst_file); | 146 | fclose(dst_file); |
147 | } | 147 | } |
148 | while (uncompressed_count < next_header_offset) { | ||
149 | if (fgetc(src_tar_file) == EOF) { | ||
150 | perror_msg("untar"); | ||
148 | break; | 151 | break; |
149 | default: { | 152 | } |
150 | int remaining = size; | 153 | uncompressed_count++; |
151 | while (remaining-- > 0) { | ||
152 | fgetc(src_tar_file); | ||
153 | } | ||
154 | } | ||
155 | } | 154 | } |
156 | uncompressed_count += size; | 155 | uncompressed_count += size; |
157 | break; | 156 | break; |
158 | } | 157 | } |
159 | case '5': | 158 | case '5': |
160 | if (untar_function & extract_extract) { | 159 | if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) { |
161 | if (create_path(dir, mode) != TRUE) { | 160 | if (create_path(dir, mode) != TRUE) { |
162 | free(dir); | 161 | free(dir); |
163 | perror_msg("%s: Cannot mkdir", raw_tar_header.name); | 162 | perror_msg("%s: Cannot mkdir", raw_tar_header.name); |
@@ -166,7 +165,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
166 | } | 165 | } |
167 | break; | 166 | break; |
168 | case '1': | 167 | case '1': |
169 | if (untar_function & extract_extract) { | 168 | if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) { |
170 | if (link(raw_tar_header.linkname, raw_tar_header.name) < 0) { | 169 | if (link(raw_tar_header.linkname, raw_tar_header.name) < 0) { |
171 | free(dir); | 170 | free(dir); |
172 | perror_msg("%s: Cannot create hard link to '%s'", raw_tar_header.name, raw_tar_header.linkname); | 171 | perror_msg("%s: Cannot create hard link to '%s'", raw_tar_header.name, raw_tar_header.linkname); |
@@ -175,7 +174,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
175 | } | 174 | } |
176 | break; | 175 | break; |
177 | case '2': | 176 | case '2': |
178 | if (untar_function & extract_extract) { | 177 | if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) { |
179 | if (symlink(raw_tar_header.linkname, raw_tar_header.name) < 0) { | 178 | if (symlink(raw_tar_header.linkname, raw_tar_header.name) < 0) { |
180 | free(dir); | 179 | free(dir); |
181 | perror_msg("%s: Cannot create symlink to '%s'", raw_tar_header.name, raw_tar_header.linkname); | 180 | perror_msg("%s: Cannot create symlink to '%s'", raw_tar_header.name, raw_tar_header.linkname); |