From 2e6d3cfa82eb64fffe53ccb5669aa7146228cf8f Mon Sep 17 00:00:00 2001 From: Glenn L McGrath Date: Sun, 24 Jun 2001 12:36:54 +0000 Subject: Nore unarchive (and doc) fixes from Laurence Anderson --- libbb/libbb.h | 2 +- libbb/unarchive.c | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'libbb') diff --git a/libbb/libbb.h b/libbb/libbb.h index a547953..102596c 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h @@ -227,7 +227,7 @@ enum extract_functions_e { extract_control_tar_gz = 128, extract_unzip_only = 256, extract_unconditional = 512, - extract_create_dirs = 1024 + extract_create_leading_dirs = 1024 }; char *unarchive(FILE *src_stream, void *(*get_header)(FILE *), const int extract_function, const char *prefix, char **extract_names); diff --git a/libbb/unarchive.c b/libbb/unarchive.c index 20609de..4847aab 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 } } else { error_msg("%s not created: newer or same age file exists", file_entry->name); - if (S_ISREG(file_entry->mode)) { seek_sub_file(src_stream, file_entry->size); - } return (NULL); } } + if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */ + char *parent = dirname(full_name); + if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) { + error_msg("couldn't create leading directories"); + } + free (parent); + } switch(file_entry->mode & S_IFMT) { case S_IFREG: 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 } break; case S_IFDIR: - if ((function & extract_create_dirs) && (stat_res != 0)) { - /* Make sure the prefix component of full_name was create - * in applet before getting here*/ + if (stat_res != 0) { if (mkdir(full_name, file_entry->mode) < 0) { perror_msg("extract_archive: "); } @@ -239,9 +242,6 @@ char *unarchive(FILE *src_stream, void *(*get_headers)(FILE *), } if (!found) { /* seek past the data entry */ - if (!S_ISLNK(file_entry->mode) && file_entry->link_name && file_entry->size == 0) { - error_msg("You should extract %s as other files are hardlinked to it", file_entry->name); - } seek_sub_file(src_stream, file_entry->size); continue; } @@ -271,6 +271,7 @@ void *get_header_ar(FILE *src_stream) static char *ar_long_names; if (fread(ar.raw, 1, 60, src_stream) != 60) { + free (ar_long_names); return(NULL); } archive_offset += 60; @@ -308,7 +309,11 @@ void *get_header_ar(FILE *src_stream) archive_offset += typed->size; /* This ar entries data section only contained filenames for other records * they are stored in the static ar_long_names for future reference */ - return(NULL); + return (get_header_ar(src_stream)); /* Return next header */ + } else if (ar.formated.name[1] == ' ') { + /* This is the index of symbols in the file for compilers */ + seek_sub_file(src_stream, typed->size); + return (get_header_ar(src_stream)); /* Return next header */ } else { /* The number after the '/' indicates the offset in the ar data section (saved in variable long_name) that conatains the real filename */ @@ -413,6 +418,7 @@ void *get_header_cpio(FILE *src_stream) cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1); fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream); archive_offset += cpio_entry->size; + cpio_entry->size = 0; /* Stop possiable seeks in future */ } if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) { if (cpio_entry->size == 0) { /* Put file on a linked list for later */ -- cgit v1.1