diff options
author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-06-24 12:36:54 +0000 |
---|---|---|
committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-06-24 12:36:54 +0000 |
commit | 222e53d87d310a6eb886387908b6a8a8f764ddde (patch) | |
tree | 78fb21d71f9d8680422f85a00bc3045cd6185a99 /libbb | |
parent | 3f112d9577b556de7e29e6dc007772972f0e96bf (diff) | |
download | busybox-w32-222e53d87d310a6eb886387908b6a8a8f764ddde.tar.gz busybox-w32-222e53d87d310a6eb886387908b6a8a8f764ddde.tar.bz2 busybox-w32-222e53d87d310a6eb886387908b6a8a8f764ddde.zip |
Nore unarchive (and doc) fixes from Laurence Anderson
git-svn-id: svn://busybox.net/trunk/busybox@2894 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/libbb.h | 2 | ||||
-rw-r--r-- | libbb/unarchive.c | 24 |
2 files changed, 16 insertions, 10 deletions
diff --git a/libbb/libbb.h b/libbb/libbb.h index a547953a1..102596c1f 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h | |||
@@ -227,7 +227,7 @@ enum extract_functions_e { | |||
227 | extract_control_tar_gz = 128, | 227 | extract_control_tar_gz = 128, |
228 | extract_unzip_only = 256, | 228 | extract_unzip_only = 256, |
229 | extract_unconditional = 512, | 229 | extract_unconditional = 512, |
230 | extract_create_dirs = 1024 | 230 | extract_create_leading_dirs = 1024 |
231 | }; | 231 | }; |
232 | char *unarchive(FILE *src_stream, void *(*get_header)(FILE *), | 232 | char *unarchive(FILE *src_stream, void *(*get_header)(FILE *), |
233 | const int extract_function, const char *prefix, char **extract_names); | 233 | const int extract_function, const char *prefix, char **extract_names); |
diff --git a/libbb/unarchive.c b/libbb/unarchive.c index 20609ded7..4847aab6b 100644 --- a/libbb/unarchive.c +++ b/libbb/unarchive.c | |||
@@ -129,12 +129,17 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f | |||
129 | } | 129 | } |
130 | } else { | 130 | } else { |
131 | error_msg("%s not created: newer or same age file exists", file_entry->name); | 131 | error_msg("%s not created: newer or same age file exists", file_entry->name); |
132 | if (S_ISREG(file_entry->mode)) { | ||
133 | seek_sub_file(src_stream, file_entry->size); | 132 | seek_sub_file(src_stream, file_entry->size); |
134 | } | ||
135 | return (NULL); | 133 | return (NULL); |
136 | } | 134 | } |
137 | } | 135 | } |
136 | if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */ | ||
137 | char *parent = dirname(full_name); | ||
138 | if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) { | ||
139 | error_msg("couldn't create leading directories"); | ||
140 | } | ||
141 | free (parent); | ||
142 | } | ||
138 | switch(file_entry->mode & S_IFMT) { | 143 | switch(file_entry->mode & S_IFMT) { |
139 | case S_IFREG: | 144 | case S_IFREG: |
140 | if (file_entry->link_name) { /* Found a cpio hard link */ | 145 | if (file_entry->link_name) { /* Found a cpio hard link */ |
@@ -153,9 +158,7 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f | |||
153 | } | 158 | } |
154 | break; | 159 | break; |
155 | case S_IFDIR: | 160 | case S_IFDIR: |
156 | if ((function & extract_create_dirs) && (stat_res != 0)) { | 161 | if (stat_res != 0) { |
157 | /* Make sure the prefix component of full_name was create | ||
158 | * in applet before getting here*/ | ||
159 | if (mkdir(full_name, file_entry->mode) < 0) { | 162 | if (mkdir(full_name, file_entry->mode) < 0) { |
160 | perror_msg("extract_archive: "); | 163 | perror_msg("extract_archive: "); |
161 | } | 164 | } |
@@ -239,9 +242,6 @@ char *unarchive(FILE *src_stream, void *(*get_headers)(FILE *), | |||
239 | } | 242 | } |
240 | if (!found) { | 243 | if (!found) { |
241 | /* seek past the data entry */ | 244 | /* seek past the data entry */ |
242 | if (!S_ISLNK(file_entry->mode) && file_entry->link_name && file_entry->size == 0) { | ||
243 | error_msg("You should extract %s as other files are hardlinked to it", file_entry->name); | ||
244 | } | ||
245 | seek_sub_file(src_stream, file_entry->size); | 245 | seek_sub_file(src_stream, file_entry->size); |
246 | continue; | 246 | continue; |
247 | } | 247 | } |
@@ -271,6 +271,7 @@ void *get_header_ar(FILE *src_stream) | |||
271 | static char *ar_long_names; | 271 | static char *ar_long_names; |
272 | 272 | ||
273 | if (fread(ar.raw, 1, 60, src_stream) != 60) { | 273 | if (fread(ar.raw, 1, 60, src_stream) != 60) { |
274 | free (ar_long_names); | ||
274 | return(NULL); | 275 | return(NULL); |
275 | } | 276 | } |
276 | archive_offset += 60; | 277 | archive_offset += 60; |
@@ -308,7 +309,11 @@ void *get_header_ar(FILE *src_stream) | |||
308 | archive_offset += typed->size; | 309 | archive_offset += typed->size; |
309 | /* This ar entries data section only contained filenames for other records | 310 | /* This ar entries data section only contained filenames for other records |
310 | * they are stored in the static ar_long_names for future reference */ | 311 | * they are stored in the static ar_long_names for future reference */ |
311 | return(NULL); | 312 | return (get_header_ar(src_stream)); /* Return next header */ |
313 | } else if (ar.formated.name[1] == ' ') { | ||
314 | /* This is the index of symbols in the file for compilers */ | ||
315 | seek_sub_file(src_stream, typed->size); | ||
316 | return (get_header_ar(src_stream)); /* Return next header */ | ||
312 | } else { | 317 | } else { |
313 | /* The number after the '/' indicates the offset in the ar data section | 318 | /* The number after the '/' indicates the offset in the ar data section |
314 | (saved in variable long_name) that conatains the real filename */ | 319 | (saved in variable long_name) that conatains the real filename */ |
@@ -413,6 +418,7 @@ void *get_header_cpio(FILE *src_stream) | |||
413 | cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1); | 418 | cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1); |
414 | fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream); | 419 | fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream); |
415 | archive_offset += cpio_entry->size; | 420 | archive_offset += cpio_entry->size; |
421 | cpio_entry->size = 0; /* Stop possiable seeks in future */ | ||
416 | } | 422 | } |
417 | if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) { | 423 | if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) { |
418 | if (cpio_entry->size == 0) { /* Put file on a linked list for later */ | 424 | if (cpio_entry->size == 0) { /* Put file on a linked list for later */ |