aboutsummaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-17 02:43:14 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-09-17 02:43:14 +0200
commitd57d62686dac254e83fbc18f851c773ec16013d8 (patch)
tree3e22476c6f2d74208568d5d56a629a81e11589ea /archival/tar.c
parent1166d7b1360285659aa7585e5c5bd4e1321aeeaf (diff)
downloadbusybox-w32-d57d62686dac254e83fbc18f851c773ec16013d8.tar.gz
busybox-w32-d57d62686dac254e83fbc18f851c773ec16013d8.tar.bz2
busybox-w32-d57d62686dac254e83fbc18f851c773ec16013d8.zip
tar: fix --numeric-owner, --no-same-owner, --no-same-permissions bits
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival/tar.c')
-rw-r--r--archival/tar.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 9b7a42a18..bd8e5dc99 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -735,10 +735,10 @@ enum {
735 IF_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,) 735 IF_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
736 IF_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,) 736 IF_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
737 IF_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,) 737 IF_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,)
738 IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) 738 IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) /* 15th bit */
739 OPTBIT_NOPRESERVE_OWN,
740 OPTBIT_NOPRESERVE_PERM,
741 OPTBIT_NUMERIC_OWNER, 739 OPTBIT_NUMERIC_OWNER,
740 OPTBIT_NOPRESERVE_OWNER,
741 OPTBIT_NOPRESERVE_PERM,
742 OPT_TEST = 1 << 0, // t 742 OPT_TEST = 1 << 0, // t
743 OPT_EXTRACT = 1 << 1, // x 743 OPT_EXTRACT = 1 << 1, // x
744 OPT_BASEDIR = 1 << 2, // C 744 OPT_BASEDIR = 1 << 2, // C
@@ -755,9 +755,9 @@ enum {
755 OPT_EXCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X 755 OPT_EXCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
756 OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z 756 OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
757 OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z 757 OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
758 OPT_NOPRESERVE_OWN = 1 << OPTBIT_NOPRESERVE_OWN , // no-same-owner
759 OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions
760 OPT_NUMERIC_OWNER = 1 << OPTBIT_NUMERIC_OWNER, 758 OPT_NUMERIC_OWNER = 1 << OPTBIT_NUMERIC_OWNER,
759 OPT_NOPRESERVE_OWNER = 1 << OPTBIT_NOPRESERVE_OWNER , // no-same-owner
760 OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions
761}; 761};
762#if ENABLE_FEATURE_TAR_LONG_OPTIONS 762#if ENABLE_FEATURE_TAR_LONG_OPTIONS
763static const char tar_longopts[] ALIGN1 = 763static const char tar_longopts[] ALIGN1 =
@@ -789,12 +789,15 @@ static const char tar_longopts[] ALIGN1 =
789# if ENABLE_FEATURE_SEAMLESS_Z 789# if ENABLE_FEATURE_SEAMLESS_Z
790 "compress\0" No_argument "Z" 790 "compress\0" No_argument "Z"
791# endif 791# endif
792 /* use numeric uid/gid from tar header, not textual */
792 "numeric-owner\0" No_argument "\xfc" 793 "numeric-owner\0" No_argument "\xfc"
794 /* do not restore owner */
793 "no-same-owner\0" No_argument "\xfd" 795 "no-same-owner\0" No_argument "\xfd"
796 /* do not restore mode */
794 "no-same-permissions\0" No_argument "\xfe" 797 "no-same-permissions\0" No_argument "\xfe"
795 /* --exclude takes next bit position in option mask, */ 798 /* --exclude takes next bit position in option mask, */
796 /* therefore we have to either put it _after_ --no-same-perm */ 799 /* therefore we have to either put it _after_ --no-same-perm */
797 /* or add OPT[BIT]_EXCLUDE before OPT[BIT]_NOPRESERVE_OWN */ 800 /* or add OPT[BIT]_EXCLUDE before OPT[BIT]_NOPRESERVE_OWNER */
798# if ENABLE_FEATURE_TAR_FROM 801# if ENABLE_FEATURE_TAR_FROM
799 "exclude\0" Required_argument "\xff" 802 "exclude\0" Required_argument "\xff"
800# endif 803# endif
@@ -817,12 +820,12 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
817 /* Initialise default values */ 820 /* Initialise default values */
818 tar_handle = init_handle(); 821 tar_handle = init_handle();
819 tar_handle->ah_flags = ARCHIVE_CREATE_LEADING_DIRS 822 tar_handle->ah_flags = ARCHIVE_CREATE_LEADING_DIRS
820 | ARCHIVE_PRESERVE_DATE 823 | ARCHIVE_RESTORE_DATE
821 | ARCHIVE_EXTRACT_UNCONDITIONAL; 824 | ARCHIVE_UNLINK_OLD;
822 825
823 /* Apparently only root's tar preserves perms (see bug 3844) */ 826 /* Apparently only root's tar preserves perms (see bug 3844) */
824 if (getuid() != 0) 827 if (getuid() != 0)
825 tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_PERM; 828 tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;
826 829
827 /* Prepend '-' to the first argument if required */ 830 /* Prepend '-' to the first argument if required */
828 opt_complementary = "--:" // first arg is options 831 opt_complementary = "--:" // first arg is options
@@ -856,6 +859,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
856 , &verboseFlag // combined count for -t and -v 859 , &verboseFlag // combined count for -t and -v
857 , &verboseFlag // combined count for -t and -v 860 , &verboseFlag // combined count for -t and -v
858 ); 861 );
862 //bb_error_msg("opt:%08x", opt);
859 argv += optind; 863 argv += optind;
860 864
861 if (verboseFlag) tar_handle->action_header = header_verbose_list; 865 if (verboseFlag) tar_handle->action_header = header_verbose_list;
@@ -868,17 +872,17 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
868 tar_handle->action_data = data_extract_to_stdout; 872 tar_handle->action_data = data_extract_to_stdout;
869 873
870 if (opt & OPT_KEEP_OLD) 874 if (opt & OPT_KEEP_OLD)
871 tar_handle->ah_flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL; 875 tar_handle->ah_flags &= ~ARCHIVE_UNLINK_OLD;
872
873 if (opt & OPT_NOPRESERVE_OWN)
874 tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_OWN;
875
876 if (opt & OPT_NOPRESERVE_PERM)
877 tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_PERM;
878 876
879 if (opt & OPT_NUMERIC_OWNER) 877 if (opt & OPT_NUMERIC_OWNER)
880 tar_handle->ah_flags |= ARCHIVE_NUMERIC_OWNER; 878 tar_handle->ah_flags |= ARCHIVE_NUMERIC_OWNER;
881 879
880 if (opt & OPT_NOPRESERVE_OWNER)
881 tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_OWNER;
882
883 if (opt & OPT_NOPRESERVE_PERM)
884 tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;
885
882 if (opt & OPT_GZIP) 886 if (opt & OPT_GZIP)
883 get_header_ptr = get_header_tar_gz; 887 get_header_ptr = get_header_tar_gz;
884 888