aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-08-14 02:55:15 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-08-14 02:55:15 +0000
commit3d5828fb6da7376eb220817376f22fac4da2815a (patch)
tree95b3ba1423159a87678f3caad26a99f8797faf45
parent062913f66288b93aaefe052cb15b4115f4b1a839 (diff)
downloadbusybox-w32-3d5828fb6da7376eb220817376f22fac4da2815a.tar.gz
busybox-w32-3d5828fb6da7376eb220817376f22fac4da2815a.tar.bz2
busybox-w32-3d5828fb6da7376eb220817376f22fac4da2815a.zip
Change hardlink handling for tar to work the same way as cpio
-rw-r--r--archival/libunarchive/data_extract_all.c82
-rw-r--r--archival/libunarchive/get_header_tar.c8
2 files changed, 46 insertions, 44 deletions
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c
index bd264dd74..c6ace2c33 100644
--- a/archival/libunarchive/data_extract_all.c
+++ b/archival/libunarchive/data_extract_all.c
@@ -39,54 +39,52 @@ extern void data_extract_all(archive_handle_t *archive_handle)
39 free(name); 39 free(name);
40 } 40 }
41 41
42 /* Create the filesystem entry */ 42 /* Handle hard links seperately */
43 switch(file_header->mode & S_IFMT) { 43 if (!S_ISLNK(file_header->mode) && (file_header->link_name) && (file_header->size == 0)) {
44 case S_IFREG: { 44 /* hard link */
45#ifdef CONFIG_CPIO 45 res = link(file_header->link_name, file_header->name);
46 if (file_header->link_name && file_header->size == 0) { 46 if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
47 /* hard link */ 47 bb_perror_msg("Couldnt create hard link");
48 res = link(file_header->link_name, file_header->name); 48 }
49 if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { 49 } else {
50 bb_perror_msg("Couldnt create hard link"); 50 /* Create the filesystem entry */
51 } 51 switch(file_header->mode & S_IFMT) {
52 } else 52 case S_IFREG: {
53#endif
54 {
55 /* Regular file */ 53 /* Regular file */
56 unlink(file_header->name); 54 unlink(file_header->name);
57 dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL); 55 dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
58 archive_copy_file(archive_handle, dst_fd); 56 archive_copy_file(archive_handle, dst_fd);
59 close(dst_fd); 57 close(dst_fd);
60 } 58 break;
61 break; 59 }
60 case S_IFDIR:
61 unlink(file_header->name);
62 res = mkdir(file_header->name, file_header->mode);
63 if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
64 bb_perror_msg("extract_archive: %s", file_header->name);
65 }
66 break;
67 case S_IFLNK:
68 /* Symlink */
69 unlink(file_header->name);
70 res = symlink(file_header->link_name, file_header->name);
71 if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
72 bb_perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name);
73 }
74 break;
75 case S_IFSOCK:
76 case S_IFBLK:
77 case S_IFCHR:
78 case S_IFIFO:
79 unlink(file_header->name);
80 res = mknod(file_header->name, file_header->mode, file_header->device);
81 if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
82 bb_perror_msg("Cannot create node %s", file_header->name);
83 }
84 break;
85 default:
86 bb_error_msg_and_die("Unrecognised file type");
62 } 87 }
63 case S_IFDIR:
64 unlink(file_header->name);
65 res = mkdir(file_header->name, file_header->mode);
66 if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
67 bb_perror_msg("extract_archive: %s", file_header->name);
68 }
69 break;
70 case S_IFLNK:
71 /* Symlink */
72 unlink(file_header->name);
73 res = symlink(file_header->link_name, file_header->name);
74 if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
75 bb_perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name);
76 }
77 break;
78 case S_IFSOCK:
79 case S_IFBLK:
80 case S_IFCHR:
81 case S_IFIFO:
82 unlink(file_header->name);
83 res = mknod(file_header->name, file_header->mode, file_header->device);
84 if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
85 bb_perror_msg("Cannot create node %s", file_header->name);
86 }
87 break;
88 default:
89 bb_error_msg_and_die("Unrecognised file type");
90 } 88 }
91 89
92 chmod(file_header->name, file_header->mode); 90 chmod(file_header->name, file_header->mode);
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index 33cb75dfd..3bbe15d36 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -128,8 +128,12 @@ extern char get_header_tar(archive_handle_t *archive_handle)
128 case '0': 128 case '0':
129 file_header->mode |= S_IFREG; 129 file_header->mode |= S_IFREG;
130 break; 130 break;
131#if 0
132 /* hard links are detected as entries with 0 size, a link name,
133 * and not being a symlink, hence we have nothing to do here */
131 case '1': 134 case '1':
132 bb_error_msg("WARNING: Converting hard link to symlink"); 135 break;
136#endif
133 case '2': 137 case '2':
134 file_header->mode |= S_IFLNK; 138 file_header->mode |= S_IFLNK;
135 break; 139 break;
@@ -173,6 +177,7 @@ extern char get_header_tar(archive_handle_t *archive_handle)
173# endif 177# endif
174 } 178 }
175#endif 179#endif
180
176 if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { 181 if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
177 archive_handle->action_header(archive_handle->file_header); 182 archive_handle->action_header(archive_handle->file_header);
178 archive_handle->flags |= ARCHIVE_EXTRACT_QUIET; 183 archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
@@ -185,4 +190,3 @@ extern char get_header_tar(archive_handle_t *archive_handle)
185 190
186 return(EXIT_SUCCESS); 191 return(EXIT_SUCCESS);
187} 192}
188