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,54 +39,52 @@ extern void data_extract_all(archive_handle_t *archive_handle)
free(name);
}
/* Create the filesystem entry */
switch(file_header->mode & S_IFMT) {
case S_IFREG: {
#ifdef CONFIG_CPIO
if (file_header->link_name && file_header->size == 0) {
/* hard link */
res = link(file_header->link_name, file_header->name);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("Couldnt create hard link");
}
} else
#endif
{
/* Handle hard links seperately */
if (!S_ISLNK(file_header->mode) && (file_header->link_name) && (file_header->size == 0)) {
/* hard link */
res = link(file_header->link_name, file_header->name);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("Couldnt create hard link");
}
} else {
/* Create the filesystem entry */
switch(file_header->mode & S_IFMT) {
case S_IFREG: {
/* Regular file */
unlink(file_header->name);
dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
archive_copy_file(archive_handle, dst_fd);
close(dst_fd);
}
break;
break;
}
case S_IFDIR:
unlink(file_header->name);
res = mkdir(file_header->name, file_header->mode);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("extract_archive: %s", file_header->name);
}
break;
case S_IFLNK:
/* Symlink */
unlink(file_header->name);
res = symlink(file_header->link_name, file_header->name);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name);
}
break;
case S_IFSOCK:
case S_IFBLK:
case S_IFCHR:
case S_IFIFO:
unlink(file_header->name);
res = mknod(file_header->name, file_header->mode, file_header->device);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("Cannot create node %s", file_header->name);
}
break;
default:
bb_error_msg_and_die("Unrecognised file type");
}
case S_IFDIR:
unlink(file_header->name);
res = mkdir(file_header->name, file_header->mode);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("extract_archive: %s", file_header->name);
}
break;
case S_IFLNK:
/* Symlink */
unlink(file_header->name);
res = symlink(file_header->link_name, file_header->name);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name);
}
break;
case S_IFSOCK:
case S_IFBLK:
case S_IFCHR:
case S_IFIFO:
unlink(file_header->name);
res = mknod(file_header->name, file_header->mode, file_header->device);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("Cannot create node %s", file_header->name);
}
break;
default:
bb_error_msg_and_die("Unrecognised file type");
}
chmod(file_header->name, file_header->mode);

View File

@ -128,8 +128,12 @@ extern char get_header_tar(archive_handle_t *archive_handle)
case '0':
file_header->mode |= S_IFREG;
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':
bb_error_msg("WARNING: Converting hard link to symlink");
break;
#endif
case '2':
file_header->mode |= S_IFLNK;
break;
@ -173,6 +177,7 @@ extern char get_header_tar(archive_handle_t *archive_handle)
# endif
}
#endif
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_header(archive_handle->file_header);
archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
@ -185,4 +190,3 @@ extern char get_header_tar(archive_handle_t *archive_handle)
return(EXIT_SUCCESS);
}