diff options
author | Ron Yorston <rmy@pobox.com> | 2015-10-31 17:13:47 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2015-10-31 17:13:47 +0000 |
commit | 4432dbba6559d3d88e18ecf2c33d9e5a39e82074 (patch) | |
tree | f6db886523a04e0b45926336223ff8c32761dc43 /archival/tar.c | |
parent | bc09f29f78547856e2152dc47051aeed548f28e8 (diff) | |
parent | 6bd3fff51aa74e2ee2d87887b12182a3b09792ef (diff) | |
download | busybox-w32-4432dbba6559d3d88e18ecf2c33d9e5a39e82074.tar.gz busybox-w32-4432dbba6559d3d88e18ecf2c33d9e5a39e82074.tar.bz2 busybox-w32-4432dbba6559d3d88e18ecf2c33d9e5a39e82074.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'archival/tar.c')
-rw-r--r-- | archival/tar.c | 89 |
1 files changed, 75 insertions, 14 deletions
diff --git a/archival/tar.c b/archival/tar.c index 0dd675f64..adb0b934f 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 |
@@ -884,6 +887,7 @@ enum { | |||
884 | IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) | 887 | IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) |
885 | IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,) | 888 | IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,) |
886 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS | 889 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS |
890 | OPTBIT_STRIP_COMPONENTS, | ||
887 | OPTBIT_NORECURSION, | 891 | OPTBIT_NORECURSION, |
888 | IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,) | 892 | IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,) |
889 | OPTBIT_NUMERIC_OWNER, | 893 | OPTBIT_NUMERIC_OWNER, |
@@ -908,12 +912,13 @@ enum { | |||
908 | OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z | 912 | OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z |
909 | OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J | 913 | OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J |
910 | OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z | 914 | OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z |
911 | OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m | 915 | OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m |
912 | OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion | 916 | OPT_STRIP_COMPONENTS = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_STRIP_COMPONENTS)) + 0, // strip-components |
913 | OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command | 917 | OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion |
914 | OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner | 918 | OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command |
915 | OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions | 919 | OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner |
916 | OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite | 920 | OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions |
921 | OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite | ||
917 | 922 | ||
918 | OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS), | 923 | OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS), |
919 | }; | 924 | }; |
@@ -957,6 +962,7 @@ static const char tar_longopts[] ALIGN1 = | |||
957 | # if ENABLE_FEATURE_TAR_NOPRESERVE_TIME | 962 | # if ENABLE_FEATURE_TAR_NOPRESERVE_TIME |
958 | "touch\0" No_argument "m" | 963 | "touch\0" No_argument "m" |
959 | # endif | 964 | # endif |
965 | "strip-components\0" Required_argument "\xf9" | ||
960 | "no-recursion\0" No_argument "\xfa" | 966 | "no-recursion\0" No_argument "\xfa" |
961 | # if ENABLE_FEATURE_TAR_TO_COMMAND | 967 | # if ENABLE_FEATURE_TAR_TO_COMMAND |
962 | "to-command\0" Required_argument "\xfb" | 968 | "to-command\0" Required_argument "\xfb" |
@@ -1002,15 +1008,28 @@ int tar_main(int argc UNUSED_PARAM, char **argv) | |||
1002 | "tt:vv:" // count -t,-v | 1008 | "tt:vv:" // count -t,-v |
1003 | IF_FEATURE_TAR_FROM("X::T::") // cumulative lists | 1009 | IF_FEATURE_TAR_FROM("X::T::") // cumulative lists |
1004 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM | 1010 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM |
1005 | "\xff::" // cumulative lists for --exclude | 1011 | "\xff::" // --exclude=PATTERN is a list |
1006 | #endif | 1012 | #endif |
1007 | IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd | 1013 | IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd |
1008 | IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive | 1014 | IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive |
1009 | IF_NOT_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive | 1015 | IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive |
1016 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS | ||
1017 | ":\xf9+" // --strip-components=NUM | ||
1018 | #endif | ||
1019 | ; | ||
1010 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS | 1020 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS |
1011 | applet_long_options = tar_longopts; | 1021 | applet_long_options = tar_longopts; |
1012 | #endif | 1022 | #endif |
1013 | #if ENABLE_DESKTOP | 1023 | #if ENABLE_DESKTOP |
1024 | /* Lie to buildroot when it starts asking stupid questions. */ | ||
1025 | if (argv[1] && strcmp(argv[1], "--version") == 0) { | ||
1026 | // Output of 'tar --version' examples: | ||
1027 | // tar (GNU tar) 1.15.1 | ||
1028 | // tar (GNU tar) 1.25 | ||
1029 | // bsdtar 2.8.3 - libarchive 2.8.3 | ||
1030 | puts("tar (busybox) " BB_VER); | ||
1031 | return 0; | ||
1032 | } | ||
1014 | if (argv[1] && argv[1][0] != '-') { | 1033 | if (argv[1] && argv[1][0] != '-') { |
1015 | /* Compat: | 1034 | /* Compat: |
1016 | * 1st argument without dash handles options with parameters | 1035 | * 1st argument without dash handles options with parameters |
@@ -1047,10 +1066,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv) | |||
1047 | IF_FEATURE_SEAMLESS_XZ( "J" ) | 1066 | IF_FEATURE_SEAMLESS_XZ( "J" ) |
1048 | IF_FEATURE_SEAMLESS_Z( "Z" ) | 1067 | IF_FEATURE_SEAMLESS_Z( "Z" ) |
1049 | IF_FEATURE_TAR_NOPRESERVE_TIME("m") | 1068 | IF_FEATURE_TAR_NOPRESERVE_TIME("m") |
1069 | IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components | ||
1050 | , &base_dir // -C dir | 1070 | , &base_dir // -C dir |
1051 | , &tar_filename // -f filename | 1071 | , &tar_filename // -f filename |
1052 | IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T | 1072 | IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T |
1053 | IF_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X | 1073 | IF_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X |
1074 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS | ||
1075 | , &tar_handle->tar__strip_components // --strip-components | ||
1076 | #endif | ||
1054 | IF_FEATURE_TAR_TO_COMMAND(, &(tar_handle->tar__to_command)) // --to-command | 1077 | IF_FEATURE_TAR_TO_COMMAND(, &(tar_handle->tar__to_command)) // --to-command |
1055 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM | 1078 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM |
1056 | , &excludes // --exclude | 1079 | , &excludes // --exclude |
@@ -1058,11 +1081,49 @@ int tar_main(int argc UNUSED_PARAM, char **argv) | |||
1058 | , &verboseFlag // combined count for -t and -v | 1081 | , &verboseFlag // combined count for -t and -v |
1059 | , &verboseFlag // combined count for -t and -v | 1082 | , &verboseFlag // combined count for -t and -v |
1060 | ); | 1083 | ); |
1061 | //bb_error_msg("opt:%08x", opt); | 1084 | #if DBG_OPTION_PARSING |
1085 | bb_error_msg("opt: 0x%08x", opt); | ||
1086 | # define showopt(o) bb_error_msg("opt & %s(%x): %x", #o, o, opt & o); | ||
1087 | showopt(OPT_TEST ); | ||
1088 | showopt(OPT_EXTRACT ); | ||
1089 | showopt(OPT_BASEDIR ); | ||
1090 | showopt(OPT_TARNAME ); | ||
1091 | showopt(OPT_2STDOUT ); | ||
1092 | showopt(OPT_NOPRESERVE_OWNER); | ||
1093 | showopt(OPT_P ); | ||
1094 | showopt(OPT_VERBOSE ); | ||
1095 | showopt(OPT_KEEP_OLD ); | ||
1096 | showopt(OPT_CREATE ); | ||
1097 | showopt(OPT_DEREFERENCE ); | ||
1098 | showopt(OPT_BZIP2 ); | ||
1099 | showopt(OPT_LZMA ); | ||
1100 | showopt(OPT_INCLUDE_FROM ); | ||
1101 | showopt(OPT_EXCLUDE_FROM ); | ||
1102 | showopt(OPT_GZIP ); | ||
1103 | showopt(OPT_XZ ); | ||
1104 | showopt(OPT_COMPRESS ); | ||
1105 | showopt(OPT_NOPRESERVE_TIME ); | ||
1106 | showopt(OPT_STRIP_COMPONENTS); | ||
1107 | showopt(OPT_NORECURSION ); | ||
1108 | showopt(OPT_2COMMAND ); | ||
1109 | showopt(OPT_NUMERIC_OWNER ); | ||
1110 | showopt(OPT_NOPRESERVE_PERM ); | ||
1111 | showopt(OPT_OVERWRITE ); | ||
1112 | showopt(OPT_ANY_COMPRESS ); | ||
1113 | bb_error_msg("base_dir:'%s'", base_dir); | ||
1114 | bb_error_msg("tar_filename:'%s'", tar_filename); | ||
1115 | bb_error_msg("verboseFlag:%d", verboseFlag); | ||
1116 | bb_error_msg("tar_handle->tar__to_command:'%s'", tar_handle->tar__to_command); | ||
1117 | bb_error_msg("tar_handle->tar__strip_components:%u", tar_handle->tar__strip_components); | ||
1118 | return 0; | ||
1119 | # undef showopt | ||
1120 | #endif | ||
1062 | argv += optind; | 1121 | argv += optind; |
1063 | 1122 | ||
1064 | if (verboseFlag) tar_handle->action_header = header_verbose_list; | 1123 | if (verboseFlag) |
1065 | if (verboseFlag == 1) tar_handle->action_header = header_list; | 1124 | tar_handle->action_header = header_verbose_list; |
1125 | if (verboseFlag == 1) | ||
1126 | tar_handle->action_header = header_list; | ||
1066 | 1127 | ||
1067 | if (opt & OPT_EXTRACT) | 1128 | if (opt & OPT_EXTRACT) |
1068 | tar_handle->action_data = data_extract_all; | 1129 | tar_handle->action_data = data_extract_all; |