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 /libbb/untar.c | |
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
Diffstat (limited to '')
-rw-r--r-- | libbb/untar.c | 71 |
1 files changed, 31 insertions, 40 deletions
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 | } |