diff options
Diffstat (limited to 'archival')
-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) | |||
14 | 14 | ||
15 | if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) { | 15 | if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) { |
16 | char *name = xstrdup(file_header->name); | 16 | char *name = xstrdup(file_header->name); |
17 | bb_make_directory (dirname(name), -1, FILEUTILS_RECUR); | 17 | bb_make_directory(dirname(name), -1, FILEUTILS_RECUR); |
18 | free(name); | 18 | free(name); |
19 | } | 19 | } |
20 | 20 | ||
21 | /* Check if the file already exists */ | 21 | /* Check if the file already exists */ |
22 | if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) { | 22 | if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) { |
23 | /* Remove the existing entry if it exists */ | 23 | /* Remove the existing entry if it exists */ |
24 | if (((file_header->mode & S_IFMT) != S_IFDIR) && (unlink(file_header->name) == -1) && (errno != ENOENT)) { | 24 | if (((file_header->mode & S_IFMT) != S_IFDIR) |
25 | bb_perror_msg_and_die("Couldnt remove old file"); | 25 | && (unlink(file_header->name) == -1) |
26 | && (errno != ENOENT) | ||
27 | ) { | ||
28 | bb_perror_msg_and_die("cannot remove old file"); | ||
26 | } | 29 | } |
27 | } | 30 | } |
28 | else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) { | 31 | else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) { |
@@ -30,64 +33,77 @@ void data_extract_all(archive_handle_t *archive_handle) | |||
30 | struct stat statbuf; | 33 | struct stat statbuf; |
31 | if (lstat(file_header->name, &statbuf) == -1) { | 34 | if (lstat(file_header->name, &statbuf) == -1) { |
32 | if (errno != ENOENT) { | 35 | if (errno != ENOENT) { |
33 | bb_perror_msg_and_die("Couldnt stat old file"); | 36 | bb_perror_msg_and_die("cannot stat old file"); |
34 | } | 37 | } |
35 | } | 38 | } |
36 | else if (statbuf.st_mtime <= file_header->mtime) { | 39 | else if (statbuf.st_mtime <= file_header->mtime) { |
37 | if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { | 40 | if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { |
38 | bb_error_msg("%s not created: newer or same age file exists", file_header->name); | 41 | bb_error_msg("%s not created: newer or " |
42 | "same age file exists", file_header->name); | ||
39 | } | 43 | } |
40 | data_skip(archive_handle); | 44 | data_skip(archive_handle); |
41 | return; | 45 | return; |
42 | } | 46 | } |
43 | else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) { | 47 | else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) { |
44 | bb_perror_msg_and_die("Couldnt remove old file %s", file_header->name); | 48 | bb_perror_msg_and_die("cannot remove old file %s", |
49 | file_header->name); | ||
45 | } | 50 | } |
46 | } | 51 | } |
47 | 52 | ||
48 | /* Handle hard links separately | 53 | /* Handle hard links separately |
49 | * We identified hard links as regular files of size 0 with a symlink */ | 54 | * We identified hard links as regular files of size 0 with a symlink */ |
50 | if (S_ISREG(file_header->mode) && (file_header->link_name) && (file_header->size == 0)) { | 55 | if (S_ISREG(file_header->mode) && (file_header->link_name) |
56 | && (file_header->size == 0) | ||
57 | ) { | ||
51 | /* hard link */ | 58 | /* hard link */ |
52 | res = link(file_header->link_name, file_header->name); | 59 | res = link(file_header->link_name, file_header->name); |
53 | if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { | 60 | if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { |
54 | bb_perror_msg("Couldnt create hard link"); | 61 | bb_perror_msg("cannot create hard link"); |
55 | } | 62 | } |
56 | } else { | 63 | } else { |
57 | /* Create the filesystem entry */ | 64 | /* Create the filesystem entry */ |
58 | switch (file_header->mode & S_IFMT) { | 65 | switch (file_header->mode & S_IFMT) { |
59 | case S_IFREG: { | 66 | case S_IFREG: { |
60 | /* Regular file */ | 67 | /* Regular file */ |
61 | dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL, | 68 | dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL, |
62 | file_header->mode); | 69 | file_header->mode); |
63 | bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size); | 70 | bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size); |
64 | close(dst_fd); | 71 | close(dst_fd); |
65 | break; | 72 | break; |
66 | } | 73 | } |
67 | case S_IFDIR: | 74 | case S_IFDIR: |
68 | res = mkdir(file_header->name, file_header->mode); | 75 | res = mkdir(file_header->name, file_header->mode); |
69 | if ((errno != EISDIR) && (res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { | 76 | if ((errno != EISDIR) && (res == -1) |
70 | bb_perror_msg("extract_archive: %s", file_header->name); | 77 | && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) |
71 | } | 78 | ) { |
72 | break; | 79 | bb_perror_msg("extract_archive: %s", file_header->name); |
73 | case S_IFLNK: | 80 | } |
74 | /* Symlink */ | 81 | break; |
75 | res = symlink(file_header->link_name, file_header->name); | 82 | case S_IFLNK: |
76 | if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { | 83 | /* Symlink */ |
77 | bb_perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name); | 84 | res = symlink(file_header->link_name, file_header->name); |
78 | } | 85 | if ((res == -1) |
79 | break; | 86 | && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) |
80 | case S_IFSOCK: | 87 | ) { |
81 | case S_IFBLK: | 88 | bb_perror_msg("cannot create symlink " |
82 | case S_IFCHR: | 89 | "from %s to '%s'", |
83 | case S_IFIFO: | 90 | file_header->name, |
84 | res = mknod(file_header->name, file_header->mode, file_header->device); | 91 | file_header->link_name); |
85 | if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { | 92 | } |
86 | bb_perror_msg("Cannot create node %s", file_header->name); | 93 | break; |
87 | } | 94 | case S_IFSOCK: |
88 | break; | 95 | case S_IFBLK: |
89 | default: | 96 | case S_IFCHR: |
90 | bb_error_msg_and_die("Unrecognised file type"); | 97 | case S_IFIFO: |
98 | res = mknod(file_header->name, file_header->mode, file_header->device); | ||
99 | if ((res == -1) | ||
100 | && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) | ||
101 | ) { | ||
102 | bb_perror_msg("cannot create node %s", file_header->name); | ||
103 | } | ||
104 | break; | ||
105 | default: | ||
106 | bb_error_msg_and_die("unrecognized file type"); | ||
91 | } | 107 | } |
92 | } | 108 | } |
93 | 109 | ||
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) | |||
61 | } | 61 | } |
62 | 62 | ||
63 | { | 63 | { |
64 | unsigned long tmpsize; | 64 | unsigned long tmpsize; |
65 | sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c", | 65 | sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c", |
66 | dummy, &inode, (unsigned int*)&file_header->mode, | 66 | dummy, &inode, (unsigned int*)&file_header->mode, |
67 | (unsigned int*)&file_header->uid, (unsigned int*)&file_header->gid, | 67 | (unsigned int*)&file_header->uid, (unsigned int*)&file_header->gid, |
68 | &nlink, &file_header->mtime, &tmpsize, | 68 | &nlink, &file_header->mtime, &tmpsize, |
69 | dummy, &major, &minor, &namesize, dummy); | 69 | dummy, &major, &minor, &namesize, dummy); |
70 | file_header->size = tmpsize; | 70 | file_header->size = tmpsize; |
71 | } | 71 | } |
72 | 72 | ||
73 | file_header->name = (char *) xzalloc(namesize + 1); | 73 | 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) | |||
74 | */ | 74 | */ |
75 | if (strncmp(tar.formatted.magic, "ustar", 5) != 0) { | 75 | if (strncmp(tar.formatted.magic, "ustar", 5) != 0) { |
76 | #ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY | 76 | #ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY |
77 | if (strncmp(tar.formatted.magic, "\0\0\0\0\0", 5) != 0) | 77 | if (memcmp(tar.formatted.magic, "\0\0\0\0", 5) != 0) |
78 | #endif | 78 | #endif |
79 | bb_error_msg_and_die("invalid tar magic"); | 79 | bb_error_msg_and_die("invalid tar magic"); |
80 | } | 80 | } |
81 | /* Do checksum on headers */ | 81 | /* Do checksum on headers */ |
82 | for (i = 0; i < 148 ; i++) { | 82 | for (i = 0; i < 148 ; i++) { |
83 | sum += tar.raw[i]; | 83 | sum += tar.raw[i]; |
84 | } | 84 | } |
85 | sum += ' ' * 8; | 85 | sum += ' ' * 8; |
@@ -111,13 +111,14 @@ char get_header_tar(archive_handle_t *archive_handle) | |||
111 | 111 | ||
112 | file_header->uid = xstrtoul(tar.formatted.uid, 8); | 112 | file_header->uid = xstrtoul(tar.formatted.uid, 8); |
113 | file_header->gid = xstrtoul(tar.formatted.gid, 8); | 113 | file_header->gid = xstrtoul(tar.formatted.gid, 8); |
114 | // TODO: LFS support | 114 | file_header->size = XSTRTOUOFF(tar.formatted.size, 8); |
115 | file_header->size = xstrtoul(tar.formatted.size, 8); | ||
116 | file_header->mtime = xstrtoul(tar.formatted.mtime, 8); | 115 | file_header->mtime = xstrtoul(tar.formatted.mtime, 8); |
117 | file_header->link_name = tar.formatted.linkname[0] ? | 116 | file_header->link_name = tar.formatted.linkname[0] ? |
118 | xstrdup(tar.formatted.linkname) : NULL; | 117 | xstrdup(tar.formatted.linkname) : NULL; |
119 | file_header->device = makedev(xstrtoul(tar.formatted.devmajor, 8), | 118 | if (tar.formatted.devmajor[0]) { |
120 | xstrtoul(tar.formatted.devminor, 8)); | 119 | file_header->device = makedev(xstrtoul(tar.formatted.devmajor, 8), |
120 | xstrtoul(tar.formatted.devminor, 8)); | ||
121 | } | ||
121 | 122 | ||
122 | /* Set bits 0-11 of the files mode */ | 123 | /* Set bits 0-11 of the files mode */ |
123 | file_header->mode = 07777 & xstrtoul(tar.formatted.mode, 8); | 124 | 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 @@ | |||
3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <unistd.h> | 6 | //#include <unistd.h> |
7 | #include <string.h> | 7 | //#include <string.h> |
8 | #include "libbb.h" | 8 | #include "libbb.h" |
9 | #include "unarchive.h" | 9 | #include "unarchive.h" |
10 | 10 | ||
@@ -12,7 +12,7 @@ archive_handle_t *init_handle(void) | |||
12 | { | 12 | { |
13 | archive_handle_t *archive_handle; | 13 | archive_handle_t *archive_handle; |
14 | 14 | ||
15 | /* Initialise default values */ | 15 | /* Initialize default values */ |
16 | archive_handle = xzalloc(sizeof(archive_handle_t)); | 16 | archive_handle = xzalloc(sizeof(archive_handle_t)); |
17 | archive_handle->file_header = xmalloc(sizeof(file_header_t)); | 17 | archive_handle->file_header = xmalloc(sizeof(file_header_t)); |
18 | archive_handle->action_header = header_skip; | 18 | archive_handle->action_header = header_skip; |
@@ -20,5 +20,5 @@ archive_handle_t *init_handle(void) | |||
20 | archive_handle->filter = filter_accept_all; | 20 | archive_handle->filter = filter_accept_all; |
21 | archive_handle->seek = seek_by_jump; | 21 | archive_handle->seek = seek_by_jump; |
22 | 22 | ||
23 | return(archive_handle); | 23 | return archive_handle; |
24 | } | 24 | } |