diff options
Diffstat (limited to 'archival/libunarchive')
-rw-r--r-- | archival/libunarchive/data_extract_all.c | 96 | ||||
-rw-r--r-- | archival/libunarchive/get_header_cpio.c | 6 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar.c | 13 | ||||
-rw-r--r-- | archival/libunarchive/init_handle.c | 8 |
4 files changed, 70 insertions, 53 deletions
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c index b1c66a4a2..67f8f3534 100644 --- a/archival/libunarchive/data_extract_all.c +++ b/archival/libunarchive/data_extract_all.c @@ -14,15 +14,18 @@ void data_extract_all(archive_handle_t *archive_handle) if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) { char *name = xstrdup(file_header->name); - bb_make_directory (dirname(name), -1, FILEUTILS_RECUR); + bb_make_directory(dirname(name), -1, FILEUTILS_RECUR); free(name); } /* Check if the file already exists */ if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) { /* Remove the existing entry if it exists */ - if (((file_header->mode & S_IFMT) != S_IFDIR) && (unlink(file_header->name) == -1) && (errno != ENOENT)) { - bb_perror_msg_and_die("Couldnt remove old file"); + if (((file_header->mode & S_IFMT) != S_IFDIR) + && (unlink(file_header->name) == -1) + && (errno != ENOENT) + ) { + bb_perror_msg_and_die("cannot remove old file"); } } else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) { @@ -30,64 +33,77 @@ void data_extract_all(archive_handle_t *archive_handle) struct stat statbuf; if (lstat(file_header->name, &statbuf) == -1) { if (errno != ENOENT) { - bb_perror_msg_and_die("Couldnt stat old file"); + bb_perror_msg_and_die("cannot stat old file"); } } else if (statbuf.st_mtime <= file_header->mtime) { if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { - bb_error_msg("%s not created: newer or same age file exists", file_header->name); + bb_error_msg("%s not created: newer or " + "same age file exists", file_header->name); } data_skip(archive_handle); return; } else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) { - bb_perror_msg_and_die("Couldnt remove old file %s", file_header->name); + bb_perror_msg_and_die("cannot remove old file %s", + file_header->name); } } /* Handle hard links separately * We identified hard links as regular files of size 0 with a symlink */ - if (S_ISREG(file_header->mode) && (file_header->link_name) && (file_header->size == 0)) { + if (S_ISREG(file_header->mode) && (file_header->link_name) + && (file_header->size == 0) + ) { /* hard link */ res = link(file_header->link_name, file_header->name); if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { - bb_perror_msg("Couldnt create hard link"); + bb_perror_msg("cannot create hard link"); } } else { /* Create the filesystem entry */ switch (file_header->mode & S_IFMT) { - case S_IFREG: { - /* Regular file */ - dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL, - file_header->mode); - bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size); - close(dst_fd); - break; - } - case S_IFDIR: - res = mkdir(file_header->name, file_header->mode); - if ((errno != EISDIR) && (res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { - bb_perror_msg("extract_archive: %s", file_header->name); - } - break; - case S_IFLNK: - /* Symlink */ - res = symlink(file_header->link_name, file_header->name); - if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { - bb_perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name); - } - break; - case S_IFSOCK: - case S_IFBLK: - case S_IFCHR: - case S_IFIFO: - res = mknod(file_header->name, file_header->mode, file_header->device); - if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { - bb_perror_msg("Cannot create node %s", file_header->name); - } - break; - default: - bb_error_msg_and_die("Unrecognised file type"); + case S_IFREG: { + /* Regular file */ + dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL, + file_header->mode); + bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size); + close(dst_fd); + break; + } + case S_IFDIR: + res = mkdir(file_header->name, file_header->mode); + if ((errno != EISDIR) && (res == -1) + && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) + ) { + bb_perror_msg("extract_archive: %s", file_header->name); + } + break; + case S_IFLNK: + /* Symlink */ + res = symlink(file_header->link_name, file_header->name); + if ((res == -1) + && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) + ) { + bb_perror_msg("cannot create symlink " + "from %s to '%s'", + file_header->name, + file_header->link_name); + } + break; + case S_IFSOCK: + case S_IFBLK: + case S_IFCHR: + case S_IFIFO: + res = mknod(file_header->name, file_header->mode, file_header->device); + if ((res == -1) + && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) + ) { + bb_perror_msg("cannot create node %s", file_header->name); + } + break; + default: + bb_error_msg_and_die("unrecognized file type"); } } diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c index bc766c6aa..56862f137 100644 --- a/archival/libunarchive/get_header_cpio.c +++ b/archival/libunarchive/get_header_cpio.c @@ -61,13 +61,13 @@ char get_header_cpio(archive_handle_t *archive_handle) } { - unsigned long tmpsize; - sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c", + unsigned long tmpsize; + sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c", dummy, &inode, (unsigned int*)&file_header->mode, (unsigned int*)&file_header->uid, (unsigned int*)&file_header->gid, &nlink, &file_header->mtime, &tmpsize, dummy, &major, &minor, &namesize, dummy); - file_header->size = tmpsize; + file_header->size = tmpsize; } file_header->name = (char *) xzalloc(namesize + 1); diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index d3cd96d0c..f78377e28 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c @@ -74,12 +74,12 @@ char get_header_tar(archive_handle_t *archive_handle) */ if (strncmp(tar.formatted.magic, "ustar", 5) != 0) { #ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY - if (strncmp(tar.formatted.magic, "\0\0\0\0\0", 5) != 0) + if (memcmp(tar.formatted.magic, "\0\0\0\0", 5) != 0) #endif bb_error_msg_and_die("invalid tar magic"); } /* Do checksum on headers */ - for (i = 0; i < 148 ; i++) { + for (i = 0; i < 148 ; i++) { sum += tar.raw[i]; } sum += ' ' * 8; @@ -111,13 +111,14 @@ char get_header_tar(archive_handle_t *archive_handle) file_header->uid = xstrtoul(tar.formatted.uid, 8); file_header->gid = xstrtoul(tar.formatted.gid, 8); - // TODO: LFS support - file_header->size = xstrtoul(tar.formatted.size, 8); + file_header->size = XSTRTOUOFF(tar.formatted.size, 8); file_header->mtime = xstrtoul(tar.formatted.mtime, 8); file_header->link_name = tar.formatted.linkname[0] ? xstrdup(tar.formatted.linkname) : NULL; - file_header->device = makedev(xstrtoul(tar.formatted.devmajor, 8), - xstrtoul(tar.formatted.devminor, 8)); + if (tar.formatted.devmajor[0]) { + file_header->device = makedev(xstrtoul(tar.formatted.devmajor, 8), + xstrtoul(tar.formatted.devminor, 8)); + } /* Set bits 0-11 of the files mode */ file_header->mode = 07777 & xstrtoul(tar.formatted.mode, 8); diff --git a/archival/libunarchive/init_handle.c b/archival/libunarchive/init_handle.c index 96bb1dbc9..beda1b462 100644 --- a/archival/libunarchive/init_handle.c +++ b/archival/libunarchive/init_handle.c @@ -3,8 +3,8 @@ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ -#include <unistd.h> -#include <string.h> +//#include <unistd.h> +//#include <string.h> #include "libbb.h" #include "unarchive.h" @@ -12,7 +12,7 @@ archive_handle_t *init_handle(void) { archive_handle_t *archive_handle; - /* Initialise default values */ + /* Initialize default values */ archive_handle = xzalloc(sizeof(archive_handle_t)); archive_handle->file_header = xmalloc(sizeof(file_header_t)); archive_handle->action_header = header_skip; @@ -20,5 +20,5 @@ archive_handle_t *init_handle(void) archive_handle->filter = filter_accept_all; archive_handle->seek = seek_by_jump; - return(archive_handle); + return archive_handle; } |