Add --no-same-owner and --no-same-permissions options to tar.

This commit is contained in:
Rob Landley 2005-10-27 22:49:08 +00:00
parent 47ea7b7f96
commit f3d6c94c7f
3 changed files with 64 additions and 41 deletions

View File

@ -111,8 +111,12 @@ extern void data_extract_all(archive_handle_t *archive_handle)
}
}
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) {
lchown(file_header->name, file_header->uid, file_header->gid);
if ((file_header->mode & S_IFMT) != S_IFLNK) {
}
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_PERM) &&
(file_header->mode & S_IFMT) != S_IFLNK)
{
chmod(file_header->name, file_header->mode);
}

View File

@ -587,57 +587,67 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
#define TAR_OPT_VERBOSE (1 << 6)
#define TAR_OPT_KEEP_OLD (1 << 7)
# define CTX_CREATE (1 << 8)
# define TAR_OPT_DEREFERNCE (1 << 9)
#define TAR_OPT_AFTER_START 8
#define CTX_CREATE (1 << (TAR_OPT_AFTER_START))
#define TAR_OPT_DEREFERNCE (1 << (TAR_OPT_AFTER_START + 1))
#ifdef CONFIG_FEATURE_TAR_CREATE
# define TAR_OPT_STR_CREATE "ch"
# define TAR_OPT_FLAG_CREATE 2
# define TAR_OPT_AFTER_CREATE TAR_OPT_AFTER_START + 2
#else
# define TAR_OPT_STR_CREATE ""
# define TAR_OPT_FLAG_CREATE 0
# define TAR_OPT_AFTER_CREATE TAR_OPT_AFTER_START
#endif
# define TAR_OPT_BZIP2 (1 << (8 + TAR_OPT_FLAG_CREATE))
#define TAR_OPT_BZIP2 (1 << (TAR_OPT_AFTER_CREATE))
#ifdef CONFIG_FEATURE_TAR_BZIP2
# define TAR_OPT_STR_BZIP2 "j"
# define TAR_OPT_FLAG_BZIP2 1
# define TAR_OPT_AFTER_BZIP2 TAR_OPT_AFTER_CREATE + 1
#else
# define TAR_OPT_STR_BZIP2 ""
# define TAR_OPT_FLAG_BZIP2 0
# define TAR_OPT_AFTER_BZIP2 TAR_OPT_AFTER_CREATE
#endif
# define TAR_OPT_INCLUDE_FROM (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2))
# define TAR_OPT_EXCLUDE_FROM (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2 + 1))
#define TAR_OPT_INCLUDE_FROM (1 << (TAR_OPT_AFTER_BZIP2))
#define TAR_OPT_EXCLUDE_FROM (1 << (TAR_OPT_AFTER_BZIP2 + 1))
#ifdef CONFIG_FEATURE_TAR_FROM
# define TAR_OPT_STR_FROM "T:X:"
# define TAR_OPT_FLAG_FROM 2
# define TAR_OPT_AFTER_FROM TAR_OPT_AFTER_BZIP2 + 2
#else
# define TAR_OPT_STR_FROM ""
# define TAR_OPT_FLAG_FROM 0
# define TAR_OPT_AFTER_FROM TAR_OPT_AFTER_BZIP2
#endif
# define TAR_OPT_GZIP (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2 + TAR_OPT_FLAG_FROM))
#define TAR_OPT_GZIP (1 << (TAR_OPT_AFTER_FROM))
#ifdef CONFIG_FEATURE_TAR_GZIP
# define TAR_OPT_STR_GZIP "z"
# define TAR_OPT_FLAG_GZIP 1
# define TAR_OPT_AFTER_GZIP TAR_OPT_AFTER_FROM + 1
#else
# define TAR_OPT_STR_GZIP ""
# define TAR_OPT_FLAG_GZIP 0
# define TAR_OPT_AFTER_GZIP TAR_OPT_AFTER_FROM
#endif
# define TAR_OPT_UNCOMPRESS (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2 + TAR_OPT_FLAG_FROM + TAR_OPT_FLAG_GZIP))
#define TAR_OPT_UNCOMPRESS (1 << (TAR_OPT_AFTER_GZIP))
#ifdef CONFIG_FEATURE_TAR_COMPRESS
# define TAR_OPT_STR_COMPRESS "Z"
# define TAR_OPT_AFTER_COMPRESS TAR_OPT_AFTER_GZIP + 1
#else
# define TAR_OPT_STR_COMPRESS ""
# define TAR_OPT_AFTER_COMPRESS TAR_OPT_AFTER_GZIP
#endif
#define TAR_OPT_NOPRESERVE_OWN (1 << (TAR_OPT_AFTER_COMPRESS))
#define TAR_OPT_NOPRESERVE_PERM (1 << (TAR_OPT_AFTER_COMPRESS + 1))
#define TAR_OPT_STR_NOPRESERVE "\203\213"
#define TAR_OPT_AFTER_NOPRESERVE TAR_OPT_AFTER_COMPRESS + 2
static const char tar_options[]="txC:f:Opvk" \
TAR_OPT_STR_CREATE \
TAR_OPT_STR_BZIP2 \
TAR_OPT_STR_FROM \
TAR_OPT_STR_GZIP \
TAR_OPT_STR_COMPRESS;
TAR_OPT_STR_COMPRESS \
TAR_OPT_STR_NOPRESERVE;
#ifdef CONFIG_FEATURE_TAR_LONG_OPTIONS
static const struct option tar_long_options[] = {
@ -649,6 +659,8 @@ static const struct option tar_long_options[] = {
{ "same-permissions", 0, NULL, 'p' },
{ "verbose", 0, NULL, 'v' },
{ "keep-old", 0, NULL, 'k' },
{ "no-same-owner", 0, NULL, '\203' },
{ "no-same-permissions",0, NULL, '\213' },
# ifdef CONFIG_FEATURE_TAR_CREATE
{ "create", 0, NULL, 'c' },
{ "dereference", 0, NULL, 'h' },
@ -726,6 +738,11 @@ int tar_main(int argc, char **argv)
if (opt & TAR_OPT_KEEP_OLD)
tar_handle->flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL;
if (opt & TAR_OPT_NOPRESERVE_OWN)
tar_handle->flags |= ARCHIVE_NOPRESERVE_OWN;
if (opt & TAR_OPT_NOPRESERVE_PERM)
tar_handle->flags |= ARCHIVE_NOPRESERVE_PERM;
if (ENABLE_FEATURE_TAR_GZIP && (opt & TAR_OPT_GZIP))
get_header_ptr = get_header_tar_gz;

View File

@ -6,6 +6,8 @@
#define ARCHIVE_EXTRACT_UNCONDITIONAL 4
#define ARCHIVE_EXTRACT_QUIET 8
#define ARCHIVE_EXTRACT_NEWER 16
#define ARCHIVE_NOPRESERVE_OWN 32
#define ARCHIVE_NOPRESERVE_PERM 64
#include <sys/types.h>
#include <stdio.h>