Change hardlink handling for tar to work the same way as cpio

This commit is contained in:
Glenn L McGrath 2003-08-14 02:55:15 +00:00
parent 062913f662
commit 3d5828fb6d
2 changed files with 46 additions and 44 deletions

View File

@ -39,25 +39,22 @@ extern void data_extract_all(archive_handle_t *archive_handle)
free(name); free(name);
} }
/* Create the filesystem entry */ /* Handle hard links seperately */
switch(file_header->mode & S_IFMT) { if (!S_ISLNK(file_header->mode) && (file_header->link_name) && (file_header->size == 0)) {
case S_IFREG: {
#ifdef CONFIG_CPIO
if (file_header->link_name && file_header->size == 0) {
/* hard link */ /* hard link */
res = link(file_header->link_name, file_header->name); res = link(file_header->link_name, file_header->name);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("Couldnt create hard link"); bb_perror_msg("Couldnt create hard link");
} }
} else } else {
#endif /* Create the filesystem entry */
{ switch(file_header->mode & S_IFMT) {
case S_IFREG: {
/* Regular file */ /* Regular file */
unlink(file_header->name); unlink(file_header->name);
dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL); dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
archive_copy_file(archive_handle, dst_fd); archive_copy_file(archive_handle, dst_fd);
close(dst_fd); close(dst_fd);
}
break; break;
} }
case S_IFDIR: case S_IFDIR:
@ -88,6 +85,7 @@ extern void data_extract_all(archive_handle_t *archive_handle)
default: default:
bb_error_msg_and_die("Unrecognised file type"); bb_error_msg_and_die("Unrecognised file type");
} }
}
chmod(file_header->name, file_header->mode); chmod(file_header->name, file_header->mode);
chown(file_header->name, file_header->uid, file_header->gid); chown(file_header->name, file_header->uid, file_header->gid);

View File

@ -128,8 +128,12 @@ extern char get_header_tar(archive_handle_t *archive_handle)
case '0': case '0':
file_header->mode |= S_IFREG; file_header->mode |= S_IFREG;
break; break;
#if 0
/* hard links are detected as entries with 0 size, a link name,
* and not being a symlink, hence we have nothing to do here */
case '1': case '1':
bb_error_msg("WARNING: Converting hard link to symlink"); break;
#endif
case '2': case '2':
file_header->mode |= S_IFLNK; file_header->mode |= S_IFLNK;
break; break;
@ -173,6 +177,7 @@ extern char get_header_tar(archive_handle_t *archive_handle)
# endif # endif
} }
#endif #endif
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_header(archive_handle->file_header); archive_handle->action_header(archive_handle->file_header);
archive_handle->flags |= ARCHIVE_EXTRACT_QUIET; archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
@ -185,4 +190,3 @@ extern char get_header_tar(archive_handle_t *archive_handle)
return(EXIT_SUCCESS); return(EXIT_SUCCESS);
} }