aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-08-28 19:12:23 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-08-28 19:12:23 +0000
commit4cee66d5a8a49f6bd6342923aff94262812fba73 (patch)
tree8523978e8159ce2569e02557fa2b6ced3030b39b
parent444566837c4b98f364fa486f9f288b0775ed3ed6 (diff)
downloadbusybox-w32-4cee66d5a8a49f6bd6342923aff94262812fba73.tar.gz
busybox-w32-4cee66d5a8a49f6bd6342923aff94262812fba73.tar.bz2
busybox-w32-4cee66d5a8a49f6bd6342923aff94262812fba73.zip
Dont unlink when testing !
Always preserve creation date Disable the -p option its for modification date Remove some cpio header debugging noise Syncronise file listing behaviour with upstream.
-rw-r--r--archival/cpio.c20
-rw-r--r--archival/libunarchive/data_extract_all.c25
-rw-r--r--archival/libunarchive/get_header_cpio.c42
-rw-r--r--include/unarchive.h1
4 files changed, 45 insertions, 43 deletions
diff --git a/archival/cpio.c b/archival/cpio.c
index 111807c43..beee83d31 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -40,8 +40,8 @@ extern int cpio_main(int argc, char **argv)
40 archive_handle = init_handle(); 40 archive_handle = init_handle();
41 archive_handle->src_fd = fileno(stdin); 41 archive_handle->src_fd = fileno(stdin);
42 archive_handle->seek = seek_by_char; 42 archive_handle->seek = seek_by_char;
43 archive_handle->action_header = header_list; 43 archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
44 44
45 while ((opt = getopt(argc, argv, "idmuvtF:")) != -1) { 45 while ((opt = getopt(argc, argv, "idmuvtF:")) != -1) {
46 switch (opt) { 46 switch (opt) {
47 case 'i': /* extract */ 47 case 'i': /* extract */
@@ -50,17 +50,28 @@ extern int cpio_main(int argc, char **argv)
50 case 'd': /* create _leading_ directories */ 50 case 'd': /* create _leading_ directories */
51 archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS; 51 archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
52 break; 52 break;
53#if 0
53 case 'm': /* preserve modification time */ 54 case 'm': /* preserve modification time */
54 archive_handle->flags |= ARCHIVE_PRESERVE_DATE; 55 archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
55 break; 56 break;
57#endif
56 case 'v': /* verbosly list files */ 58 case 'v': /* verbosly list files */
57 archive_handle->action_header = header_verbose_list; 59 if (archive_handle->action_header == header_list) {
60 archive_handle->action_header = header_verbose_list;
61 } else {
62 archive_handle->action_header = header_list;
63 }
58 break; 64 break;
59 case 'u': /* unconditional */ 65 case 'u': /* unconditional */
60 archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; 66 archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
67 archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
61 break; 68 break;
62 case 't': /* list files */ 69 case 't': /* list files */
63 archive_handle->action_header = header_list; 70 if (archive_handle->action_header == header_list) {
71 archive_handle->action_header = header_verbose_list;
72 } else {
73 archive_handle->action_header = header_list;
74 }
64 break; 75 break;
65 case 'F': 76 case 'F':
66 archive_handle->src_fd = bb_xopen(optarg, O_RDONLY); 77 archive_handle->src_fd = bb_xopen(optarg, O_RDONLY);
@@ -81,4 +92,3 @@ extern int cpio_main(int argc, char **argv)
81 92
82 return(EXIT_SUCCESS); 93 return(EXIT_SUCCESS);
83} 94}
84
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c
index c6ace2c33..05bd2f03b 100644
--- a/archival/libunarchive/data_extract_all.c
+++ b/archival/libunarchive/data_extract_all.c
@@ -39,6 +39,31 @@ extern void data_extract_all(archive_handle_t *archive_handle)
39 free(name); 39 free(name);
40 } 40 }
41 41
42 /* Check if the file already exists */
43 if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
44 /* Remove the existing entry if it exists */
45 if ((unlink(file_header->name) == -1) && (errno != ENOENT)) {
46 bb_perror_msg_and_die("Couldnt remove old file");
47 }
48 }
49 else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) {
50 /* Remove the existing entry if its older than the extracted entry */
51 struct stat statbuf;
52 if ((lstat(file_header->name, &statbuf) == -1) && (errno != ENOENT)) {
53 bb_perror_msg_and_die("Couldnt stat old file");
54 }
55 if (statbuf.st_mtime <= file_header->mtime) {
56 if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
57 bb_error_msg("%s not created: newer or same age file exists", file_header->name);
58 }
59 data_skip(archive_handle);
60 return;
61 }
62 if ((unlink(file_header->name) == -1) && (errno != ENOENT)) {
63 bb_perror_msg_and_die("Couldnt remove old file");
64 }
65 }
66
42 /* Handle hard links seperately */ 67 /* Handle hard links seperately */
43 if (!S_ISLNK(file_header->mode) && (file_header->link_name) && (file_header->size == 0)) { 68 if (!S_ISLNK(file_header->mode) && (file_header->link_name) && (file_header->size == 0)) {
44 /* hard link */ 69 /* hard link */
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c
index 975e2a4bd..25fdc0600 100644
--- a/archival/libunarchive/get_header_cpio.c
+++ b/archival/libunarchive/get_header_cpio.c
@@ -36,7 +36,6 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
36 int namesize; 36 int namesize;
37 char dummy[16]; 37 char dummy[16];
38 int major, minor, nlink, inode; 38 int major, minor, nlink, inode;
39 char extract_flag;
40 39
41 if (pending_hardlinks) { /* Deal with any pending hardlinks */ 40 if (pending_hardlinks) { /* Deal with any pending hardlinks */
42 hardlinks_t *tmp; 41 hardlinks_t *tmp;
@@ -71,17 +70,7 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
71 } 70 }
72 archive_handle->offset += 110; 71 archive_handle->offset += 110;
73 72
74 if (strncmp(&cpio_header[0], "07070", 5) != 0) { 73 if ((strncmp(&cpio_header[0], "07070", 5) != 0) || ((cpio_header[5] != '1') && (cpio_header[5] != '2'))) {
75 printf("cpio header is %x-%x-%x-%x-%x\n",
76 cpio_header[0],
77 cpio_header[1],
78 cpio_header[2],
79 cpio_header[3],
80 cpio_header[4]);
81 bb_error_msg_and_die("Unsupported cpio format");
82 }
83
84 if ((cpio_header[5] != '1') && (cpio_header[5] != '2')) {
85 bb_error_msg_and_die("Unsupported cpio format, use newc or crc"); 74 bb_error_msg_and_die("Unsupported cpio format, use newc or crc");
86 } 75 }
87 76
@@ -154,36 +143,13 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
154 } 143 }
155 file_header->device = (major << 8) | minor; 144 file_header->device = (major << 8) | minor;
156 145
157 extract_flag = FALSE;
158 if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { 146 if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
159 struct stat statbuf;
160
161 extract_flag = TRUE;
162
163 /* Check if the file already exists */
164 if (lstat (file_header->name, &statbuf) == 0) {
165 if ((archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) || (statbuf.st_mtime < file_header->mtime)) {
166 /* Remove file if flag set or its older than the file to be extracted */
167 if (unlink(file_header->name) == -1) {
168 bb_perror_msg_and_die("Couldnt remove old file");
169 }
170 } else {
171 if (! archive_handle->flags & ARCHIVE_EXTRACT_QUIET) {
172 bb_error_msg("%s not created: newer or same age file exists", file_header->name);
173 }
174 extract_flag = FALSE;
175 }
176 }
177 archive_handle->action_header(file_header);
178 }
179
180 archive_handle->action_header(file_header);
181 if (extract_flag) {
182 archive_handle->action_data(archive_handle); 147 archive_handle->action_data(archive_handle);
148 archive_handle->action_header(archive_handle->file_header);
183 } else { 149 } else {
184 data_skip(archive_handle); 150 data_skip(archive_handle);
185 } 151 }
152
186 archive_handle->offset += file_header->size; 153 archive_handle->offset += file_header->size;
187 return (EXIT_SUCCESS); 154 return (EXIT_SUCCESS);
188} 155}
189
diff --git a/include/unarchive.h b/include/unarchive.h
index 8396f878c..1c4e851ab 100644
--- a/include/unarchive.h
+++ b/include/unarchive.h
@@ -5,6 +5,7 @@
5#define ARCHIVE_CREATE_LEADING_DIRS 2 5#define ARCHIVE_CREATE_LEADING_DIRS 2
6#define ARCHIVE_EXTRACT_UNCONDITIONAL 4 6#define ARCHIVE_EXTRACT_UNCONDITIONAL 4
7#define ARCHIVE_EXTRACT_QUIET 8 7#define ARCHIVE_EXTRACT_QUIET 8
8#define ARCHIVE_EXTRACT_NEWER 16
8 9
9#include <sys/types.h> 10#include <sys/types.h>
10#include <stdio.h> 11#include <stdio.h>