aboutsummaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-10-22 01:07:13 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-10-22 01:07:13 +0200
commit6c563e370d0f2f3cf36f3b274e8fe1392ca7125f (patch)
tree8e9a7cd2e979bc6c956b863128086a342dd1a676 /archival/tar.c
parentc47917865d5f40f9044dd8845814c591d801318d (diff)
downloadbusybox-w32-6c563e370d0f2f3cf36f3b274e8fe1392ca7125f.tar.gz
busybox-w32-6c563e370d0f2f3cf36f3b274e8fe1392ca7125f.tar.bz2
busybox-w32-6c563e370d0f2f3cf36f3b274e8fe1392ca7125f.zip
tar: add support for --strip-components=N
function old new delta data_extract_all 882 995 +113 tar_longopts 290 309 +19 tar_main 938 942 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 136/0) Total: 136 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival/tar.c')
-rw-r--r--archival/tar.c80
1 files changed, 66 insertions, 14 deletions
diff --git a/archival/tar.c b/archival/tar.c
index aa03ba990..566ba34f6 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -152,9 +152,12 @@
152# define FNM_LEADING_DIR 0 152# define FNM_LEADING_DIR 0
153#endif 153#endif
154 154
155 155#if 0
156//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__) 156# define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
157#define DBG(...) ((void)0) 157#else
158# define DBG(...) ((void)0)
159#endif
160#define DBG_OPTION_PARSING 0
158 161
159 162
160#define block_buf bb_common_bufsiz1 163#define block_buf bb_common_bufsiz1
@@ -855,6 +858,7 @@ enum {
855 IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) 858 IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
856 IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,) 859 IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
857#if ENABLE_FEATURE_TAR_LONG_OPTIONS 860#if ENABLE_FEATURE_TAR_LONG_OPTIONS
861 OPTBIT_STRIP_COMPONENTS,
858 OPTBIT_NORECURSION, 862 OPTBIT_NORECURSION,
859 IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,) 863 IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,)
860 OPTBIT_NUMERIC_OWNER, 864 OPTBIT_NUMERIC_OWNER,
@@ -879,12 +883,13 @@ enum {
879 OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z 883 OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
880 OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J 884 OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J
881 OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z 885 OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
882 OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m 886 OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
883 OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion 887 OPT_STRIP_COMPONENTS = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_STRIP_COMPONENTS)) + 0, // strip-components
884 OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command 888 OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion
885 OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner 889 OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command
886 OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions 890 OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
887 OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite 891 OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
892 OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
888 893
889 OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS), 894 OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS),
890}; 895};
@@ -928,6 +933,7 @@ static const char tar_longopts[] ALIGN1 =
928# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME 933# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME
929 "touch\0" No_argument "m" 934 "touch\0" No_argument "m"
930# endif 935# endif
936 "strip-components\0" Required_argument "\xf9"
931 "no-recursion\0" No_argument "\xfa" 937 "no-recursion\0" No_argument "\xfa"
932# if ENABLE_FEATURE_TAR_TO_COMMAND 938# if ENABLE_FEATURE_TAR_TO_COMMAND
933 "to-command\0" Required_argument "\xfb" 939 "to-command\0" Required_argument "\xfb"
@@ -973,11 +979,15 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
973 "tt:vv:" // count -t,-v 979 "tt:vv:" // count -t,-v
974 IF_FEATURE_TAR_FROM("X::T::") // cumulative lists 980 IF_FEATURE_TAR_FROM("X::T::") // cumulative lists
975#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM 981#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
976 "\xff::" // cumulative lists for --exclude 982 "\xff::" // --exclude=PATTERN is a list
977#endif 983#endif
978 IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd 984 IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
979 IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive 985 IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
980 IF_NOT_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive 986 IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive
987#if ENABLE_FEATURE_TAR_LONG_OPTIONS
988 ":\xf9+" // --strip-components=NUM
989#endif
990 ;
981#if ENABLE_FEATURE_TAR_LONG_OPTIONS 991#if ENABLE_FEATURE_TAR_LONG_OPTIONS
982 applet_long_options = tar_longopts; 992 applet_long_options = tar_longopts;
983#endif 993#endif
@@ -1018,10 +1028,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1018 IF_FEATURE_SEAMLESS_XZ( "J" ) 1028 IF_FEATURE_SEAMLESS_XZ( "J" )
1019 IF_FEATURE_SEAMLESS_Z( "Z" ) 1029 IF_FEATURE_SEAMLESS_Z( "Z" )
1020 IF_FEATURE_TAR_NOPRESERVE_TIME("m") 1030 IF_FEATURE_TAR_NOPRESERVE_TIME("m")
1031 IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
1021 , &base_dir // -C dir 1032 , &base_dir // -C dir
1022 , &tar_filename // -f filename 1033 , &tar_filename // -f filename
1023 IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T 1034 IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
1024 IF_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X 1035 IF_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
1036#if ENABLE_FEATURE_TAR_LONG_OPTIONS
1037 , &tar_handle->tar__strip_components // --strip-components
1038#endif
1025 IF_FEATURE_TAR_TO_COMMAND(, &(tar_handle->tar__to_command)) // --to-command 1039 IF_FEATURE_TAR_TO_COMMAND(, &(tar_handle->tar__to_command)) // --to-command
1026#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM 1040#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
1027 , &excludes // --exclude 1041 , &excludes // --exclude
@@ -1029,11 +1043,49 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1029 , &verboseFlag // combined count for -t and -v 1043 , &verboseFlag // combined count for -t and -v
1030 , &verboseFlag // combined count for -t and -v 1044 , &verboseFlag // combined count for -t and -v
1031 ); 1045 );
1032 //bb_error_msg("opt:%08x", opt); 1046#if DBG_OPTION_PARSING
1047 bb_error_msg("opt: 0x%08x", opt);
1048# define showopt(o) bb_error_msg("opt & %s(%x): %x", #o, o, opt & o);
1049 showopt(OPT_TEST );
1050 showopt(OPT_EXTRACT );
1051 showopt(OPT_BASEDIR );
1052 showopt(OPT_TARNAME );
1053 showopt(OPT_2STDOUT );
1054 showopt(OPT_NOPRESERVE_OWNER);
1055 showopt(OPT_P );
1056 showopt(OPT_VERBOSE );
1057 showopt(OPT_KEEP_OLD );
1058 showopt(OPT_CREATE );
1059 showopt(OPT_DEREFERENCE );
1060 showopt(OPT_BZIP2 );
1061 showopt(OPT_LZMA );
1062 showopt(OPT_INCLUDE_FROM );
1063 showopt(OPT_EXCLUDE_FROM );
1064 showopt(OPT_GZIP );
1065 showopt(OPT_XZ );
1066 showopt(OPT_COMPRESS );
1067 showopt(OPT_NOPRESERVE_TIME );
1068 showopt(OPT_STRIP_COMPONENTS);
1069 showopt(OPT_NORECURSION );
1070 showopt(OPT_2COMMAND );
1071 showopt(OPT_NUMERIC_OWNER );
1072 showopt(OPT_NOPRESERVE_PERM );
1073 showopt(OPT_OVERWRITE );
1074 showopt(OPT_ANY_COMPRESS );
1075 bb_error_msg("base_dir:'%s'", base_dir);
1076 bb_error_msg("tar_filename:'%s'", tar_filename);
1077 bb_error_msg("verboseFlag:%d", verboseFlag);
1078 bb_error_msg("tar_handle->tar__to_command:'%s'", tar_handle->tar__to_command);
1079 bb_error_msg("tar_handle->tar__strip_components:%u", tar_handle->tar__strip_components);
1080 return 0;
1081# undef showopt
1082#endif
1033 argv += optind; 1083 argv += optind;
1034 1084
1035 if (verboseFlag) tar_handle->action_header = header_verbose_list; 1085 if (verboseFlag)
1036 if (verboseFlag == 1) tar_handle->action_header = header_list; 1086 tar_handle->action_header = header_verbose_list;
1087 if (verboseFlag == 1)
1088 tar_handle->action_header = header_list;
1037 1089
1038 if (opt & OPT_EXTRACT) 1090 if (opt & OPT_EXTRACT)
1039 tar_handle->action_data = data_extract_all; 1091 tar_handle->action_data = data_extract_all;