aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/libunarchive/data_extract_all.c50
-rw-r--r--archival/libunarchive/get_header_cpio.c12
-rw-r--r--archival/libunarchive/get_header_tar.c12
-rw-r--r--archival/libunarchive/header_verbose_list.c4
-rw-r--r--include/unarchive.h22
-rw-r--r--libbb/copy_file.c10
6 files changed, 56 insertions, 54 deletions
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c
index 0bb5bfe33..76e7edf24 100644
--- a/archival/libunarchive/data_extract_all.c
+++ b/archival/libunarchive/data_extract_all.c
@@ -25,7 +25,8 @@ void data_extract_all(archive_handle_t *archive_handle)
25 && (unlink(file_header->name) == -1) 25 && (unlink(file_header->name) == -1)
26 && (errno != ENOENT) 26 && (errno != ENOENT)
27 ) { 27 ) {
28 bb_perror_msg_and_die("cannot remove old file"); 28 bb_perror_msg_and_die("cannot remove old file %s",
29 file_header->name);
29 } 30 }
30 } 31 }
31 else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) { 32 else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) {
@@ -52,13 +53,16 @@ void data_extract_all(archive_handle_t *archive_handle)
52 53
53 /* Handle hard links separately 54 /* Handle hard links separately
54 * We identified hard links as regular files of size 0 with a symlink */ 55 * We identified hard links as regular files of size 0 with a symlink */
55 if (S_ISREG(file_header->mode) && (file_header->link_name) 56 if (S_ISREG(file_header->mode) && (file_header->link_target)
56 && (file_header->size == 0) 57 && (file_header->size == 0)
57 ) { 58 ) {
58 /* hard link */ 59 /* hard link */
59 res = link(file_header->link_name, file_header->name); 60 res = link(file_header->link_target, file_header->name);
60 if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { 61 if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
61 bb_perror_msg("cannot create hard link"); 62 bb_perror_msg("cannot create %slink "
63 "from %s to %s", "hard",
64 file_header->name,
65 file_header->link_target);
62 } 66 }
63 } else { 67 } else {
64 /* Create the filesystem entry */ 68 /* Create the filesystem entry */
@@ -73,22 +77,22 @@ void data_extract_all(archive_handle_t *archive_handle)
73 } 77 }
74 case S_IFDIR: 78 case S_IFDIR:
75 res = mkdir(file_header->name, file_header->mode); 79 res = mkdir(file_header->name, file_header->mode);
76 if ((errno != EISDIR) && (res == -1) 80 if ((res == -1) && (errno != EISDIR)
77 && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) 81 && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
78 ) { 82 ) {
79 bb_perror_msg("extract_archive: %s", file_header->name); 83 bb_perror_msg("cannot make dir %s", file_header->name);
80 } 84 }
81 break; 85 break;
82 case S_IFLNK: 86 case S_IFLNK:
83 /* Symlink */ 87 /* Symlink */
84 res = symlink(file_header->link_name, file_header->name); 88 res = symlink(file_header->link_target, file_header->name);
85 if ((res == -1) 89 if ((res == -1)
86 && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) 90 && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
87 ) { 91 ) {
88 bb_perror_msg("cannot create symlink " 92 bb_perror_msg("cannot create %slink "
89 "from %s to '%s'", 93 "from %s to %s", "sym",
90 file_header->name, 94 file_header->name,
91 file_header->link_name); 95 file_header->link_target);
92 } 96 }
93 break; 97 break;
94 case S_IFSOCK: 98 case S_IFSOCK:
@@ -110,18 +114,18 @@ void data_extract_all(archive_handle_t *archive_handle)
110 if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) { 114 if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) {
111 lchown(file_header->name, file_header->uid, file_header->gid); 115 lchown(file_header->name, file_header->uid, file_header->gid);
112 } 116 }
113 /* uclibc has no lchmod, glibc is even stranger - 117 if ((file_header->mode & S_IFMT) != S_IFLNK) {
114 * it has lchmod which seems to do nothing! 118 /* uclibc has no lchmod, glibc is even stranger -
115 * so we use chmod... */ 119 * it has lchmod which seems to do nothing!
116 if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_PERM) 120 * so we use chmod... */
117 && (file_header->mode & S_IFMT) != S_IFLNK 121 if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_PERM)) {
118 ) { 122 chmod(file_header->name, file_header->mode);
119 chmod(file_header->name, file_header->mode); 123 }
120 } 124 /* same for utime */
121 125 if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
122 if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) { 126 struct utimbuf t;
123 struct utimbuf t; 127 t.actime = t.modtime = file_header->mtime;
124 t.actime = t.modtime = file_header->mtime; 128 utime(file_header->name, &t);
125 utime(file_header->name, &t); 129 }
126 } 130 }
127} 131}
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c
index 6fd134018..724368be2 100644
--- a/archival/libunarchive/get_header_cpio.c
+++ b/archival/libunarchive/get_header_cpio.c
@@ -30,7 +30,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
30 tmp = saved_hardlinks; 30 tmp = saved_hardlinks;
31 oldtmp = NULL; 31 oldtmp = NULL;
32 32
33 file_header->link_name = file_header->name; 33 file_header->link_target = file_header->name;
34 file_header->size = 0; 34 file_header->size = 0;
35 35
36 while (tmp) { 36 while (tmp) {
@@ -56,7 +56,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
56 saved_hardlinks = tmp; 56 saved_hardlinks = tmp;
57 } 57 }
58 58
59 file_header->name = file_header->link_name; 59 file_header->name = file_header->link_target;
60 60
61 if (pending_hardlinks > 1) { 61 if (pending_hardlinks > 1) {
62 bb_error_msg("error resolving hardlink: archive made by GNU cpio 2.0-2.2?"); 62 bb_error_msg("error resolving hardlink: archive made by GNU cpio 2.0-2.2?");
@@ -122,12 +122,12 @@ char get_header_cpio(archive_handle_t *archive_handle)
122 } 122 }
123 123
124 if (S_ISLNK(file_header->mode)) { 124 if (S_ISLNK(file_header->mode)) {
125 file_header->link_name = xzalloc(file_header->size + 1); 125 file_header->link_target = xzalloc(file_header->size + 1);
126 xread(archive_handle->src_fd, file_header->link_name, file_header->size); 126 xread(archive_handle->src_fd, file_header->link_target, file_header->size);
127 archive_handle->offset += file_header->size; 127 archive_handle->offset += file_header->size;
128 file_header->size = 0; /* Stop possible seeks in future */ 128 file_header->size = 0; /* Stop possible seeks in future */
129 } else { 129 } else {
130 file_header->link_name = NULL; 130 file_header->link_target = NULL;
131 } 131 }
132 if (nlink > 1 && !S_ISDIR(file_header->mode)) { 132 if (nlink > 1 && !S_ISDIR(file_header->mode)) {
133 if (file_header->size == 0) { /* Put file on a linked list for later */ 133 if (file_header->size == 0) { /* Put file on a linked list for later */
@@ -154,7 +154,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
154 154
155 archive_handle->offset += file_header->size; 155 archive_handle->offset += file_header->size;
156 156
157 free(file_header->link_name); 157 free(file_header->link_target);
158 158
159 return EXIT_SUCCESS; 159 return EXIT_SUCCESS;
160} 160}
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index b3efdec94..d42f4c276 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -141,13 +141,13 @@ char get_header_tar(archive_handle_t *archive_handle)
141 unsigned major = GET_OCTAL(tar.devmajor); 141 unsigned major = GET_OCTAL(tar.devmajor);
142 file_header->device = makedev(major, minor); 142 file_header->device = makedev(major, minor);
143 } 143 }
144 file_header->link_name = NULL; 144 file_header->link_target = NULL;
145 if (!linkname && parse_names && tar.linkname[0]) { 145 if (!linkname && parse_names && tar.linkname[0]) {
146 /* we trash magic[0] here, it's ok */ 146 /* we trash magic[0] here, it's ok */
147 tar.linkname[sizeof(tar.linkname)] = '\0'; 147 tar.linkname[sizeof(tar.linkname)] = '\0';
148 file_header->link_name = xstrdup(tar.linkname); 148 file_header->link_target = xstrdup(tar.linkname);
149 /* FIXME: what if we have non-link object with link_name? */ 149 /* FIXME: what if we have non-link object with link_target? */
150 /* Will link_name be free()ed? */ 150 /* Will link_target be free()ed? */
151 } 151 }
152 file_header->mtime = GET_OCTAL(tar.mtime); 152 file_header->mtime = GET_OCTAL(tar.mtime);
153 file_header->size = GET_OCTAL(tar.size); 153 file_header->size = GET_OCTAL(tar.size);
@@ -248,7 +248,7 @@ char get_header_tar(archive_handle_t *archive_handle)
248 longname = NULL; 248 longname = NULL;
249 } 249 }
250 if (linkname) { 250 if (linkname) {
251 file_header->link_name = linkname; 251 file_header->link_target = linkname;
252 linkname = NULL; 252 linkname = NULL;
253 } 253 }
254#endif 254#endif
@@ -277,7 +277,7 @@ char get_header_tar(archive_handle_t *archive_handle)
277 } 277 }
278 archive_handle->offset += file_header->size; 278 archive_handle->offset += file_header->size;
279 279
280 free(file_header->link_name); 280 free(file_header->link_target);
281 /* Do not free(file_header->name)! */ 281 /* Do not free(file_header->name)! */
282 282
283 return EXIT_SUCCESS; 283 return EXIT_SUCCESS;
diff --git a/archival/libunarchive/header_verbose_list.c b/archival/libunarchive/header_verbose_list.c
index 7b97e524c..f3b0d8c5c 100644
--- a/archival/libunarchive/header_verbose_list.c
+++ b/archival/libunarchive/header_verbose_list.c
@@ -23,8 +23,8 @@ void header_verbose_list(const file_header_t *file_header)
23 mtime->tm_sec, 23 mtime->tm_sec,
24 file_header->name); 24 file_header->name);
25 25
26 if (file_header->link_name) { 26 if (file_header->link_target) {
27 printf(" -> %s", file_header->link_name); 27 printf(" -> %s", file_header->link_target);
28 } 28 }
29 /* putchar isnt used anywhere else i dont think */ 29 /* putchar isnt used anywhere else i dont think */
30 puts(""); 30 puts("");
diff --git a/include/unarchive.h b/include/unarchive.h
index c4e875f39..bea055852 100644
--- a/include/unarchive.h
+++ b/include/unarchive.h
@@ -10,11 +10,9 @@
10#define ARCHIVE_NOPRESERVE_OWN 32 10#define ARCHIVE_NOPRESERVE_OWN 32
11#define ARCHIVE_NOPRESERVE_PERM 64 11#define ARCHIVE_NOPRESERVE_PERM 64
12 12
13//#include "libbb.h" 13typedef struct file_header_t {
14
15typedef struct file_headers_s {
16 char *name; 14 char *name;
17 char *link_name; 15 char *link_target;
18 off_t size; 16 off_t size;
19 uid_t uid; 17 uid_t uid;
20 gid_t gid; 18 gid_t gid;
@@ -23,9 +21,9 @@ typedef struct file_headers_s {
23 dev_t device; 21 dev_t device;
24} file_header_t; 22} file_header_t;
25 23
26typedef struct archive_handle_s { 24typedef struct archive_handle_t {
27 /* define if the header and data component should be processed */ 25 /* define if the header and data component should be processed */
28 char (*filter)(struct archive_handle_s *); 26 char (*filter)(struct archive_handle_t *);
29 llist_t *accept; 27 llist_t *accept;
30 /* List of files that have been rejected */ 28 /* List of files that have been rejected */
31 llist_t *reject; 29 llist_t *reject;
@@ -39,13 +37,13 @@ typedef struct archive_handle_s {
39 void (*action_header)(const file_header_t *); 37 void (*action_header)(const file_header_t *);
40 38
41 /* process the data component, e.g. extract to filesystem */ 39 /* process the data component, e.g. extract to filesystem */
42 void (*action_data)(struct archive_handle_s *); 40 void (*action_data)(struct archive_handle_t *);
43 41
44 /* How to process any sub archive, e.g. get_header_tar_gz */ 42 /* How to process any sub archive, e.g. get_header_tar_gz */
45 char (*action_data_subarchive)(struct archive_handle_s *); 43 char (*action_data_subarchive)(struct archive_handle_t *);
46 44
47 /* Contains the handle to a sub archive */ 45 /* Contains the handle to a sub archive */
48 struct archive_handle_s *sub_archive; 46 struct archive_handle_t *sub_archive;
49 47
50 /* The raw stream as read from disk or stdin */ 48 /* The raw stream as read from disk or stdin */
51 int src_fd; 49 int src_fd;
@@ -54,7 +52,7 @@ typedef struct archive_handle_s {
54 off_t offset; 52 off_t offset;
55 53
56 /* Function that skips data: read_by_char or read_by_skip */ 54 /* Function that skips data: read_by_char or read_by_skip */
57 void (*seek)(const struct archive_handle_s *archive_handle, const unsigned int amount); 55 void (*seek)(const struct archive_handle_t *archive_handle, const unsigned amount);
58 56
59 /* Temporary storage */ 57 /* Temporary storage */
60 char *buffer; 58 char *buffer;
@@ -92,8 +90,8 @@ extern char get_header_tar_bz2(archive_handle_t *archive_handle);
92extern char get_header_tar_lzma(archive_handle_t *archive_handle); 90extern char get_header_tar_lzma(archive_handle_t *archive_handle);
93extern char get_header_tar_gz(archive_handle_t *archive_handle); 91extern char get_header_tar_gz(archive_handle_t *archive_handle);
94 92
95extern void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount); 93extern void seek_by_jump(const archive_handle_t *archive_handle, const unsigned amount);
96extern void seek_by_read(const archive_handle_t *archive_handle, const unsigned int amount); 94extern void seek_by_read(const archive_handle_t *archive_handle, const unsigned amount);
97 95
98extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count); 96extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count);
99 97
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index a6cfe122d..b68a257b5 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -197,16 +197,16 @@ int copy_file(const char *source, const char *dest, int flags)
197 int src_fd; 197 int src_fd;
198 int dst_fd; 198 int dst_fd;
199 if (ENABLE_FEATURE_PRESERVE_HARDLINKS) { 199 if (ENABLE_FEATURE_PRESERVE_HARDLINKS) {
200 char *link_name; 200 char *link_target;
201 201
202 if (!FLAGS_DEREF) { 202 if (!FLAGS_DEREF) {
203 link_name = is_in_ino_dev_hashtable(&source_stat); 203 link_target = is_in_ino_dev_hashtable(&source_stat);
204 if (link_name) { 204 if (link_target) {
205 if (link(link_name, dest) < 0) { 205 if (link(link_target, dest) < 0) {
206 ovr = ask_and_unlink(dest, flags); 206 ovr = ask_and_unlink(dest, flags);
207 if (ovr <= 0) 207 if (ovr <= 0)
208 return ovr; 208 return ovr;
209 if (link(link_name, dest) < 0) { 209 if (link(link_target, dest) < 0) {
210 bb_perror_msg("cannot create link '%s'", dest); 210 bb_perror_msg("cannot create link '%s'", dest);
211 return -1; 211 return -1;
212 } 212 }