X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Ftar.c;h=acc58671222ec3e74d785d86ee6cd68506741ef2;hb=435edb824e6d6271ed6b2d5c9f0e5b81f989a8f6;hp=e859f49b2573f67b149596a0f538f9a8d16fa565;hpb=f2bf9f2ffa06c0a89a799e64672f58a8e7d0efc7;p=chaz%2Ftar diff --git a/src/tar.c b/src/tar.c index e859f49..acc5867 100644 --- a/src/tar.c +++ b/src/tar.c @@ -249,7 +249,6 @@ enum ATIME_PRESERVE_OPTION, BACKUP_OPTION, CHECKPOINT_OPTION, - CHECK_LINKS_OPTION, DELAY_DIRECTORY_RESTORE_OPTION, DELETE_OPTION, EXCLUDE_CACHES_OPTION, @@ -298,12 +297,13 @@ enum SAME_OWNER_OPTION, SHOW_DEFAULTS_OPTION, SHOW_OMITTED_DIRS_OPTION, - SHOW_STORED_NAMES_OPTION, + SHOW_TRANSFORMED_NAMES_OPTION, STRIP_COMPONENTS_OPTION, SUFFIX_OPTION, TEST_LABEL_OPTION, TOTALS_OPTION, TO_COMMAND_OPTION, + TRANSFORM_OPTION, UNQUOTE_OPTION, USAGE_OPTION, USE_COMPRESS_PROGRAM_OPTION, @@ -370,7 +370,7 @@ static struct argp_option options[] = { {"delete", DELETE_OPTION, 0, 0, N_("delete from the archive (not on mag tapes!)"), GRID+1 }, {"test-label", TEST_LABEL_OPTION, NULL, 0, - N_("Test archive volume label and exit"), GRID+1 }, + N_("test the archive volume label and exit"), GRID+1 }, #undef GRID #define GRID 20 @@ -386,7 +386,11 @@ static struct argp_option options[] = { {"ignore-failed-read", IGNORE_FAILED_READ_OPTION, 0, 0, N_("do not exit with nonzero on unreadable files"), GRID+1 }, {"occurrence", OCCURRENCE_OPTION, N_("NUMBER"), OPTION_ARG_OPTIONAL, - N_("process only the NUMBERth occurrence of each file in the archive. This option is valid only in conjunction with one of the subcommands --delete, --diff, --extract or --list and when a list of files is given either on the command line or via -T option. NUMBER defaults to 1."), GRID+1 }, + N_("process only the NUMBERth occurrence of each file in the archive;" + " this option is valid only in conjunction with one of the subcommands" + " --delete, --diff, --extract or --list and when a list of files" + " is given either on the command line or via the -T option;" + " NUMBER defaults to 1"), GRID+1 }, {"seek", 'n', NULL, 0, N_("archive is seekable"), GRID+1 }, #undef GRID @@ -462,9 +466,10 @@ static struct argp_option options[] = { {"preserve", PRESERVE_OPTION, 0, 0, N_("same as both -p and -s"), GRID+1 }, {"delay-directory-restore", DELAY_DIRECTORY_RESTORE_OPTION, 0, 0, - N_("Delay setting modification times and permissions of extracted directories until the end of extraction."), GRID+1 }, + N_("delay setting modification times and permissions of extracted" + " directories until the end of extraction"), GRID+1 }, {"no-delay-directory-restore", NO_DELAY_DIRECTORY_RESTORE_OPTION, 0, 0, - N_("Cancel the effect of --delay-directory-restore option."), GRID+1 }, + N_("cancel the effect of --delay-directory-restore option"), GRID+1 }, #undef GRID #define GRID 60 @@ -525,7 +530,7 @@ static struct argp_option options[] = { N_("Archive format selection:"), GRID }, {"format", 'H', N_("FORMAT"), 0, - N_("create archive of the given format."), GRID+1 }, + N_("create archive of the given format"), GRID+1 }, {NULL, 0, NULL, 0, N_("FORMAT is one of the following:"), GRID+2 }, {" v7", 0, NULL, OPTION_DOC|OPTION_NO_TRANS, N_("old V7 tar format"), @@ -545,10 +550,10 @@ static struct argp_option options[] = { {"portability", 0, 0, OPTION_ALIAS, NULL, GRID+8 }, {"posix", POSIX_OPTION, 0, 0, N_("same as --format=posix"), GRID+8 }, - {"pax-option", PAX_OPTION, N_("keyword[[:]=value][,keyword[[:]=value], ...]"), 0, + {"pax-option", PAX_OPTION, N_("keyword[[:]=value][,keyword[[:]=value]]..."), 0, N_("control pax keywords"), GRID+8 }, {"label", 'V', N_("TEXT"), 0, - N_("create archive with volume name TEXT. At list/extract time, use TEXT as a globbing pattern for volume name"), GRID+8 }, + N_("create archive with volume name TEXT; at list/extract time, use TEXT as a globbing pattern for volume name"), GRID+8 }, {"bzip2", 'j', 0, 0, N_("filter the archive through bzip2"), GRID+8 }, {"gzip", 'z', 0, 0, @@ -584,23 +589,10 @@ static struct argp_option options[] = { N_("exclude patterns listed in FILE"), GRID+1 }, {"exclude-caches", EXCLUDE_CACHES_OPTION, 0, 0, N_("exclude directories containing a cache tag"), GRID+1 }, - {"ignore-case", IGNORE_CASE_OPTION, 0, 0, - N_("exclusion ignores case"), GRID+1 }, - {"anchored", ANCHORED_OPTION, 0, 0, - N_("exclude patterns match file name start"), GRID+1 }, - {"no-anchored", NO_ANCHORED_OPTION, 0, 0, - N_("exclude patterns match after any `/' (default)"), GRID+1 }, - {"no-ignore-case", NO_IGNORE_CASE_OPTION, 0, 0, - N_("exclusion is case sensitive (default)"), GRID+1 }, - {"no-wildcards", NO_WILDCARDS_OPTION, 0, 0, - N_("exclude patterns are plain strings"), GRID+1 }, - {"no-wildcards-match-slash", NO_WILDCARDS_MATCH_SLASH_OPTION, 0, 0, - N_("exclude pattern wildcards do not match `/'"), GRID+1 }, {"no-recursion", NO_RECURSION_OPTION, 0, 0, N_("avoid descending automatically in directories"), GRID+1 }, {"one-file-system", ONE_FILE_SYSTEM_OPTION, 0, 0, N_("stay in local file system when creating archive"), GRID+1 }, - {NULL, 'l', 0, OPTION_HIDDEN, "", GRID+1 }, {"recursion", RECURSION_OPTION, 0, 0, N_("recurse into directories (default)"), GRID+1 }, {"absolute-names", 'P', 0, 0, @@ -609,8 +601,6 @@ static struct argp_option options[] = { N_("follow symlinks; archive and dump the files they point to"), GRID+1 }, {"starting-file", 'K', N_("MEMBER-NAME"), 0, N_("begin at member MEMBER-NAME in the archive"), GRID+1 }, - {"strip-components", STRIP_COMPONENTS_OPTION, N_("NUMBER"), 0, - N_("strip NUMBER leading components from file names"), GRID+1 }, {"newer", 'N', N_("DATE-OR-FILE"), 0, N_("only store files newer than DATE-OR-FILE"), GRID+1 }, {"newer-mtime", NEWER_MTIME_OPTION, N_("DATE"), 0, @@ -621,12 +611,40 @@ static struct argp_option options[] = { N_("backup before removal, choose version CONTROL"), GRID+1 }, {"suffix", SUFFIX_OPTION, N_("STRING"), 0, N_("backup before removal, override usual suffix ('~' unless overridden by environment variable SIMPLE_BACKUP_SUFFIX)"), GRID+1 }, +#undef GRID + +#define GRID 92 + {NULL, 0, NULL, 0, + N_("File name transformations:"), GRID }, + {"strip-components", STRIP_COMPONENTS_OPTION, N_("NUMBER"), 0, + N_("strip NUMBER leading components from file names on extraction"), + GRID+1 }, + {"transform", TRANSFORM_OPTION, N_("EXPRESSION"), 0, + N_("Use sed replace EXPRESSION to transform file names"), GRID+1 }, +#undef GRID + +#define GRID 95 + {NULL, 0, NULL, 0, + N_("File name matching options (affect both exclude and include patterns):"), + GRID }, + {"ignore-case", IGNORE_CASE_OPTION, 0, 0, + N_("ignore case"), GRID+1 }, + {"anchored", ANCHORED_OPTION, 0, 0, + N_("patterns match file name start"), GRID+1 }, + {"no-anchored", NO_ANCHORED_OPTION, 0, 0, + N_("patterns match after any `/' (default for exclusion)"), GRID+1 }, + {"no-ignore-case", NO_IGNORE_CASE_OPTION, 0, 0, + N_("case sensitive matching (default)"), GRID+1 }, {"wildcards", WILDCARDS_OPTION, 0, 0, - N_("exclude patterns use wildcards (default)"), GRID+1 }, + N_("use wildcards (default for exclusion)"), GRID+1 }, + {"no-wildcards", NO_WILDCARDS_OPTION, 0, 0, + N_("verbatim string matching"), GRID+1 }, + {"no-wildcards-match-slash", NO_WILDCARDS_MATCH_SLASH_OPTION, 0, 0, + N_("wildcards do not match `/'"), GRID+1 }, {"wildcards-match-slash", WILDCARDS_MATCH_SLASH_OPTION, 0, 0, - N_("exclude pattern wildcards match `/' (default)"), GRID+1 }, + N_("wildcards match `/' (default for exclusion)"), GRID+1 }, #undef GRID - + #define GRID 100 {NULL, 0, NULL, 0, N_("Informative output:"), GRID }, @@ -635,7 +653,7 @@ static struct argp_option options[] = { N_("verbosely list files processed"), GRID+1 }, {"checkpoint", CHECKPOINT_OPTION, 0, 0, N_("display progress messages every 10th record"), GRID+1 }, - {"check-links", CHECK_LINKS_OPTION, 0, 0, + {"check-links", 'l', 0, 0, N_("print a message if not all links are dumped"), GRID+1 }, {"totals", TOTALS_OPTION, 0, 0, N_("print total bytes written while creating archive"), GRID+1 }, @@ -649,18 +667,19 @@ static struct argp_option options[] = { N_("ask for confirmation for every action"), GRID+1 }, {"confirmation", 0, 0, OPTION_ALIAS, NULL, GRID+1 }, {"show-defaults", SHOW_DEFAULTS_OPTION, 0, 0, - N_("Show tar defaults"), GRID+1 }, + N_("show tar defaults"), GRID+1 }, {"show-omitted-dirs", SHOW_OMITTED_DIRS_OPTION, 0, 0, - N_("When listing or extracting, list each directory that does not match search criteria"), GRID+1 }, - {"show-stored-names", SHOW_STORED_NAMES_OPTION, 0, 0, - N_("When creating archive in verbose mode, list member names as stored in the archive"), + N_("when listing or extracting, list each directory that does not match search criteria"), GRID+1 }, + {"show-transformed-names", SHOW_TRANSFORMED_NAMES_OPTION, 0, 0, + N_("show file or archive names after transformation"), GRID+1 }, + {"show-stored-names", 0, 0, OPTION_ALIAS, NULL, GRID+1 }, {"quoting-style", QUOTING_STYLE_OPTION, N_("STYLE"), 0, - N_("Set name quoting style. See below for valid STYLE values."), GRID+1 }, + N_("set name quoting style; see below for valid STYLE values"), GRID+1 }, {"quote-chars", QUOTE_CHARS_OPTION, N_("STRING"), 0, - N_("Additionally quote characters from STRING"), GRID+1 }, + N_("additionally quote characters from STRING"), GRID+1 }, {"no-quote-chars", NO_QUOTE_CHARS_OPTION, N_("STRING"), 0, - N_("Disable quoting for characters from STRING"), GRID+1 }, + N_("disable quoting for characters from STRING"), GRID+1 }, #undef GRID #define GRID 110 @@ -668,7 +687,7 @@ static struct argp_option options[] = { N_("Compatibility options:"), GRID }, {NULL, 'o', 0, 0, - N_("when creating, same as --old-archive. When extracting, same as --no-same-owner"), GRID+1 }, + N_("when creating, same as --old-archive; when extracting, same as --no-same-owner"), GRID+1 }, #undef GRID #define GRID 120 @@ -676,15 +695,15 @@ static struct argp_option options[] = { N_("Other options:"), GRID }, {"restrict", RESTRICT_OPTION, 0, 0, - N_("Restrict use of some potentially harmful options"), -1 }, + N_("disable use of some potentially harmful options"), -1 }, - {"help", '?', 0, 0, N_("Give this help list"), -1}, - {"usage", USAGE_OPTION, 0, 0, N_("Give a short usage message"), -1}, - {"version", VERSION_OPTION, 0, 0, N_("Print program version"), -1}, + {"help", '?', 0, 0, N_("give this help list"), -1}, + {"usage", USAGE_OPTION, 0, 0, N_("give a short usage message"), -1}, + {"version", VERSION_OPTION, 0, 0, N_("print program version"), -1}, /* FIXME -V (--label) conflicts with the default short option for --version */ {"HANG", HANG_OPTION, "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN, - N_("Hang for SECS seconds (default 3600)"), 0}, + N_("hang for SECS seconds (default 3600)"), 0}, #undef GRID {0, 0, 0, 0, 0, 0} @@ -694,23 +713,50 @@ static char const *const atime_preserve_args[] = { "replace", "system", NULL }; + static enum atime_preserve const atime_preserve_types[] = { replace_atime_preserve, system_atime_preserve }; + ARGMATCH_VERIFY (atime_preserve_args, atime_preserve_types); +/* Wildcard matching settings */ +enum wildcards + { + default_wildcards, /* For exclusion == enable_wildcards, + for inclusion == disable_wildcards */ + disable_wildcards, + enable_wildcards + }; -struct tar_args { - char const *textual_date_option; - int exclude_options; - bool o_option; - int pax_option; - char const *backup_suffix_string; - char const *version_control_string; - int input_files; +struct tar_args /* Variables used during option parsing */ +{ + char const *textual_date_option; /* Keeps the argument to --newer-mtime + option if it represents a textual date */ + enum wildcards wildcards; /* Wildcard settings (--wildcards/ + --no-wildcards) */ + int matching_flags; /* exclude_fnmatch options */ + int include_anchored; /* Pattern anchoring options used for + file inclusion */ + bool o_option; /* True if -o option was given */ + bool pax_option; /* True if --pax-option was given */ + char const *backup_suffix_string; /* --suffix option argument */ + char const *version_control_string; /* --backup option argument */ + bool input_files; /* True if some input files where given */ }; +#define MAKE_EXCL_OPTIONS(args) \ + ((((args)->wildcards != disable_wildcards) ? EXCLUDE_WILDCARDS : 0) \ + | (args)->matching_flags \ + | recursion_option) + +#define MAKE_INCL_OPTIONS(args) \ + ((((args)->wildcards == enable_wildcards) ? EXCLUDE_WILDCARDS : 0) \ + | (args)->include_anchored \ + | (args)->matching_flags \ + | recursion_option) + static void show_default_settings (FILE *stream) { @@ -925,8 +971,8 @@ parse_opt (int key, char *arg, struct argp_state *state) { case ARGP_KEY_ARG: /* File name or non-parsed option, because of ARGP_IN_ORDER */ - name_add (arg); - args->input_files++; + name_add_name (arg, MAKE_INCL_OPTIONS (args)); + args->input_files = true; break; case 'A': @@ -961,8 +1007,7 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case 'C': - name_add ("-C"); - name_add (arg); + name_add_dir (arg); break; case 'd': @@ -971,12 +1016,10 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'f': if (archive_names == allocated_archive_names) - { - allocated_archive_names *= 2; - archive_name_array = - xrealloc (archive_name_array, - sizeof (const char *) * allocated_archive_names); - } + archive_name_array = x2nrealloc (archive_name_array, + &allocated_archive_names, + sizeof (archive_name_array[0])); + archive_name_array[archive_names++] = arg; break; @@ -1034,23 +1077,16 @@ parse_opt (int key, char *arg, struct argp_state *state) addname (arg, 0); break; - case 'l': - /* Historically equivalent to --one-file-system. This usage is - incompatible with UNIX98 and POSIX specs and therefore is - deprecated. The semantics of -l option will be changed in - future versions. See TODO. - */ - WARN ((0, 0, - _("Semantics of -l option will change in the future releases."))); - WARN ((0, 0, - _("Please use --one-file-system option instead."))); - /* FALL THROUGH */ case ONE_FILE_SYSTEM_OPTION: /* When dumping directories, don't dump files/subdirectories that are on other filesystems. */ one_file_system_option = true; break; + case 'l': + check_links_option = 1; + break; + case 'L': { uintmax_t u; @@ -1204,7 +1240,7 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'X': if (add_exclude_file (add_exclude, excluded, arg, - args->exclude_options | recursion_option, '\n') + MAKE_EXCL_OPTIONS (args), '\n') != 0) { int e = errno; @@ -1221,7 +1257,7 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case ANCHORED_OPTION: - args->exclude_options |= EXCLUDE_ANCHORED; + args->matching_flags |= EXCLUDE_ANCHORED; break; case ATIME_PRESERVE_OPTION: @@ -1259,7 +1295,7 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case EXCLUDE_OPTION: - add_exclude (excluded, arg, args->exclude_options | recursion_option); + add_exclude (excluded, arg, MAKE_EXCL_OPTIONS (args)); break; case EXCLUDE_CACHES_OPTION: @@ -1279,7 +1315,7 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case IGNORE_CASE_OPTION: - args->exclude_options |= FNM_CASEFOLD; + args->matching_flags |= FNM_CASEFOLD; break; case IGNORE_COMMAND_ERROR_OPTION: @@ -1317,11 +1353,12 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case NO_ANCHORED_OPTION: - args->exclude_options &= ~ EXCLUDE_ANCHORED; + args->include_anchored = 0; /* Clear the default for comman line args */ + args->matching_flags &= ~ EXCLUDE_ANCHORED; break; case NO_IGNORE_CASE_OPTION: - args->exclude_options &= ~ FNM_CASEFOLD; + args->matching_flags &= ~ FNM_CASEFOLD; break; case NO_IGNORE_COMMAND_ERROR_OPTION: @@ -1338,11 +1375,11 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case NO_WILDCARDS_OPTION: - args->exclude_options &= ~ EXCLUDE_WILDCARDS; + args->wildcards = disable_wildcards; break; case NO_WILDCARDS_MATCH_SLASH_OPTION: - args->exclude_options |= FNM_FILE_NAME; + args->matching_flags |= FNM_FILE_NAME; break; case NULL_OPTION: @@ -1395,7 +1432,7 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case PAX_OPTION: - args->pax_option++; + args->pax_option = true; xheader_set_option (arg); break; @@ -1404,6 +1441,7 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case PRESERVE_OPTION: + /* FIXME: What it is good for? */ same_permissions_option = true; same_order_option = true; break; @@ -1463,8 +1501,8 @@ parse_opt (int key, char *arg, struct argp_state *state) show_omitted_dirs_option = true; break; - case SHOW_STORED_NAMES_OPTION: - show_stored_names_option = true; + case SHOW_TRANSFORMED_NAMES_OPTION: + show_transformed_names_option = true; break; case SUFFIX_OPTION: @@ -1482,6 +1520,10 @@ parse_opt (int key, char *arg, struct argp_state *state) totals_option = true; break; + case TRANSFORM_OPTION: + set_transform_expr (arg); + break; + case USE_COMPRESS_PROGRAM_OPTION: set_use_compress_program_option (arg); break; @@ -1491,15 +1533,11 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case WILDCARDS_OPTION: - args->exclude_options |= EXCLUDE_WILDCARDS; + args->wildcards = enable_wildcards; break; case WILDCARDS_MATCH_SLASH_OPTION: - args->exclude_options &= ~ FNM_FILE_NAME; - break; - - case CHECK_LINKS_OPTION: - check_links_option = 1; + args->matching_flags &= ~ FNM_FILE_NAME; break; case NO_RECURSION_OPTION: @@ -1580,12 +1618,9 @@ parse_opt (int key, char *arg, struct argp_state *state) #endif /* not DENSITY_LETTER */ if (archive_names == allocated_archive_names) - { - allocated_archive_names *= 2; - archive_name_array = - xrealloc (archive_name_array, - sizeof (const char *) * allocated_archive_names); - } + archive_name_array = x2nrealloc (archive_name_array, + &allocated_archive_names, + sizeof (archive_name_array[0])); archive_name_array[archive_names++] = xstrdup (buf); } break; @@ -1678,12 +1713,14 @@ decode_options (int argc, char **argv) /* Set some default option values. */ args.textual_date_option = NULL; - args.exclude_options = EXCLUDE_WILDCARDS; - args.o_option = 0; - args.pax_option = 0; + args.wildcards = default_wildcards; + args.matching_flags = 0; + args.include_anchored = EXCLUDE_ANCHORED; + args.o_option = false; + args.pax_option = false; args.backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX"); args.version_control_string = 0; - args.input_files = 0; + args.input_files = false; subcommand_option = UNKNOWN_SUBCOMMAND; archive_format = DEFAULT_FORMAT; @@ -1790,10 +1827,14 @@ decode_options (int argc, char **argv) /* Handle operands after any "--" argument. */ for (; index < argc; index++) { - name_add (argv[index]); - args.input_files++; + name_add_name (argv[index], MAKE_INCL_OPTIONS (&args)); + args.input_files = true; } + /* Warn about implicit use of the wildcards in command line arguments. + See TODO */ + warn_regex_usage = args.wildcards == default_wildcards; + /* Derive option values and check option consistency. */ if (archive_format == DEFAULT_FORMAT) @@ -1931,7 +1972,7 @@ decode_options (int argc, char **argv) { /* --test-label is silent if the user has specified the label name to compare against. */ - if (args.input_files == 0) + if (!args.input_files) verbose_option++; } else if (utc_option) @@ -1943,7 +1984,7 @@ decode_options (int argc, char **argv) switch (subcommand_option) { case CREATE_SUBCOMMAND: - if (args.input_files == 0 && !files_from_option) + if (!args.input_files && !files_from_option) USAGE_ERROR ((0, 0, _("Cowardly refusing to create an empty archive"))); break; @@ -2033,8 +2074,6 @@ main (int argc, char **argv) signal (SIGCHLD, SIG_DFL); #endif - init_names (); - /* Decode options. */ decode_options (argc, argv);