From: Sergey Poznyakoff Date: Mon, 3 Aug 2015 13:11:08 +0000 (+0300) Subject: Options to control option handling in file lists. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;ds=sidebyside;p=chaz%2Ftar Options to control option handling in file lists. The --verbatim-files-from option disables option handling in file lists. The --no-verbatim-files-from reverts its effect. The --null option implies --verbatim-files-from. This restores the documented behavior, broken by 26538c9b. * src/common.h (verbatim_files_from_option): New global. * src/names.c (name_elt): New member: file.verbatim (name_add_file): Take 'verbatim' state as its third parameter. (read_next_name): Don't call handle_option if file.verbatim is set. * src/tar.c: New options --verbatim-files-from and --no-verbatim-files-from. * doc/tar.texi: Document --verbatim-files-from and --no-verbatim-files-from options. * NEWS: Update. * configure.ac: Version 1.28.90 * tests/T-null2.at: New testcase. * tests/Makefile.am: Update. * tests/testsuite.at: Update. --- diff --git a/NEWS b/NEWS index c3385f8..aa6d473 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,35 @@ -GNU tar NEWS - User visible changes. 2014-11-07 +GNU tar NEWS - User visible changes. 2015-08-03 Please send GNU tar bug reports to + +version 1.28.90 (Git) + +* New options: --verbatim-files-from, --no-verbatim-files-from + +The --verbatim-files-from option instructs tar to treat each line read +from a file list as a file name, even if it starts with a dash. + +File lists are supplied with the --files-from (-T) option. By +default, each line read from a file list is first stripped off the +leading and trailing whitespace and, if the result begins with a dash, +it is treated as tar command line option. + +Use the --verbatim-files-from option to disable this special handling. +This facilitates the use of tar with file lists created automatically +(e.g. by file(1) command). + +This option affects all --files-from options that occur after it in +the command line. Its effect is reverted by the +--no-verbatim-files-from option. + +* --null option reads file names verbatim + +The --null option implies --verbatim-files-from. I.e. each line +read from null-delimited file lists is treated as a file name. + +This restores the documented behavior, which was broken in version +1.27. + version 1.28, 2014-07-28 @@ -1505,7 +1534,7 @@ Versions 1.07 back to 1.00 by Jay Fenlason. -Copyright 1994-2001, 2003-2010, 2013-2014 Free Software Foundation, Inc. +Copyright 1994-2001, 2003-2010, 2013-2015 Free Software Foundation, Inc. This file is part of GNU tar. diff --git a/configure.ac b/configure.ac index a93c6c0..0df6a21 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # Configure template for GNU tar. -*- autoconf -*- -# Copyright 1991, 1994-2010, 2013-2014 Free Software Foundation, Inc. +# Copyright 1991, 1994-2010, 2013-2015 Free Software Foundation, Inc. # This file is part of GNU tar. @@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -AC_INIT([GNU tar], [1.28], [bug-tar@gnu.org]) +AC_INIT([GNU tar], [1.28.90], [bug-tar@gnu.org]) AC_CONFIG_SRCDIR([src/tar.c]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_HEADERS([config.h]) diff --git a/doc/tar.texi b/doc/tar.texi index fc3d046..96f6aeb 100644 --- a/doc/tar.texi +++ b/doc/tar.texi @@ -3041,6 +3041,21 @@ mechanism. Treat all input file or member names literally, do not interpret escape sequences. @xref{input name quoting}. +@opsummary{no-verbatim-files-from} +@item --no-verbatim-files-from + +Instructs @GNUTAR{} to treat each line read from a file list as if it +were supplied in the command line. I.e., leading and trailing +whitespace is removed and, if the result begins with a dash, it is +treated as a @GNUTAR{} command line option. + +This is default behavior. This option is provided as a way to restore +it after @option{--verbatim-files-from} option. + +It is implied by the @option{--no-null} option. + +@xref{no-verbatim-files-from}. + @opsummary{no-wildcards} @item --no-wildcards Do not use wildcards. @@ -3055,10 +3070,16 @@ Wildcards do not match @samp{/}. @item --null When @command{tar} is using the @option{--files-from} option, this option -instructs @command{tar} to expect file names terminated with @acronym{NUL}, so -@command{tar} can correctly work with file names that contain newlines. +instructs @command{tar} to expect file names terminated with +@acronym{NUL}, and to process file names verbatim. + +This means that @command{tar} correctly works with file names that +contain newlines or begin with a dash. + @xref{nul}. +See also @ref{verbatim-files-from}. + @opsummary{numeric-owner} @item --numeric-owner @@ -3504,6 +3525,29 @@ presumed to be a compression program of some sort. @xref{gzip}. Display file modification dates in @acronym{UTC}. This option implies @option{--verbose}. +@opsummary{verbatim-files-from} +@item --verbatim-files-from + +Instructs @GNUTAR{} to treat each line read from a file list as a file +name, even if it starts with a dash. + +File lists are supplied with the @option{--files-from} (@option{-T}) +option. By default, each line read from a file list is first trimmed +off the leading and trailing whitespace and, if the result begins with +a dash, it is treated as a @GNUTAR{} command line option. + +Use the @option{--verbatim-files-from} option to disable this special +handling. This facilitates the use of @command{tar} with file lists +created by @command{file} command. + +This option affects all @option{--files-from} options that occur after +it in the command line. Its effect is reverted by the +@option{--no-verbatim-files-from} option. + +This option is implied by the @option{--null} option. + +@xref{verbatim-files-from}. + @opsummary{verbose} @item --verbose @itemx -v @@ -3670,7 +3714,7 @@ successfully. For example, @w{@samp{tar --version}} might print: @smallexample tar (GNU tar) @value{VERSION} -Copyright (C) 2013-2014 Free Software Foundation, Inc. +Copyright (C) 2013-2015 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. @@ -7217,7 +7261,7 @@ If you give a single dash as a file name for @option{--files-from}, (i.e., you specify either @code{--files-from=-} or @code{-T -}), then the file names are read from standard input. -Unless you are running @command{tar} with @option{--create}, you can not use +Unless you are running @command{tar} with @option{--create}, you cannot use both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same command. @@ -7237,8 +7281,9 @@ $ @kbd{tar -c -v -z -T small-files -f little.tgz} @end smallexample @noindent -In the file list given by @option{-T} option, any file name beginning -with @samp{-} character is considered a @command{tar} option and is +By default, each line read from the file list is first stripped off +any leading and trailing whitespace. If the resulting string begins +with @samp{-} character, it is considered a @command{tar} option and is processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1 recognized only @option{-C} option in file lists, and only if the option and its argument occupied two consecutive lines.}. For example, @@ -7273,10 +7318,23 @@ libc.a @end group @end smallexample +@anchor{verbatim-files-from} +@opindex verbatim-files-from +If such option handling is undesirable, use the +@option{--verbatim-files-from} option. When this option is in effect, +each line read from the file list is treated as a file name. Notice, +that this means, in particular, that no whitespace trimming is +performed. + +@anchor{no-verbatim-files-from} +@opindex no-verbatim-files-from +The @option{--verbatim-files-from} affects all @option{-T} options +that follow it in the command line. The default behavior can be +restored using @option{--no-verbatim-files-from} option. + @opindex add-file -If you happen to have a file whose name starts with @samp{-}, -precede it with @option{--add-file} option to prevent it from -being recognized as an option. For example: @code{--add-file=--my-file}. +To disable option handling for a single file name, use the +@option{--add-file} option, e.g.: @code{--add-file=--my-file}. @menu * nul:: @@ -7308,7 +7366,8 @@ The @option{--null} option is just like the one in @acronym{GNU} @command{xargs} and @command{cpio}, and is useful with the @option{-print0} predicate of @acronym{GNU} @command{find}. In @command{tar}, @option{--null} also disables special handling for -file names that begin with dash. +file names that begin with dash (similar to +@option{--verbatim-files-from} option). This example shows how to use @command{find} to generate a list of files larger than 800K in length and put that list into a file called @@ -8786,8 +8845,8 @@ To use it, you would invoke @command{tar} as follows: $ @kbd{tar -c -f foo.tar --files-from list} @end smallexample -The interpretation of @option{--directory} is disabled by -@option{--null} option. +The interpretation of options in file lists is disabled by +@option{--verbatim-files-from} and @option{--null} options. @node absolute @subsection Absolute File Names diff --git a/src/common.h b/src/common.h index 2904183..e7911f4 100644 --- a/src/common.h +++ b/src/common.h @@ -1,6 +1,6 @@ /* Common declarations for the tar program. - Copyright 1988, 1992-1994, 1996-1997, 1999-2010, 2012-2014 Free + Copyright 1988, 1992-1994, 1996-1997, 1999-2010, 2012-2015 Free Software Foundation, Inc. This file is part of GNU tar. @@ -386,6 +386,9 @@ GLOBAL dev_t root_device; /* Unquote filenames */ GLOBAL bool unquote_option; +/* Treat file names read from -T input verbatim */ +GLOBAL bool verbatim_files_from_option; + GLOBAL int savedir_sort_order; /* Show file or archive names after transformation. @@ -727,7 +730,8 @@ int uname_to_uid (char const *uname, uid_t *puid); void name_init (void); void name_add_name (const char *name, int matching_flags); void name_add_dir (const char *name); -void name_add_file (const char *name, int term, int matching_flags); +void name_add_file (const char *name, int term, bool verbatim, + int matching_flags); void name_term (void); const char *name_next (int change_dirs); void name_gather (void); diff --git a/src/names.c b/src/names.c index e3e145a..22118b7 100644 --- a/src/names.c +++ b/src/names.c @@ -1,6 +1,6 @@ /* Various processing of names. - Copyright 1988, 1992, 1994, 1996-2001, 2003-2007, 2009, 2013-2014 + Copyright 1988, 1992, 1994, 1996-2001, 2003-2007, 2009, 2013-2015 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it @@ -228,6 +228,8 @@ struct name_elt /* A name_array element. */ { const char *name;/* File name */ int term; /* File name terminator in the list */ + bool verbatim; /* Verbatim handling of file names: no white-space + trimming, no option processing */ FILE *fp; } file; } v; @@ -313,13 +315,14 @@ name_add_dir (const char *name) } void -name_add_file (const char *name, int term, int matflags) +name_add_file (const char *name, int term, bool verbatim, int matflags) { struct name_elt *ep = name_elt_alloc_matflags (matflags); ep->type = NELT_FILE; ep->v.file.name = name; ep->v.file.term = term; + ep->v.file.verbatim = verbatim; ep->v.file.fp = NULL; } @@ -512,7 +515,7 @@ read_next_name (struct name_elt *ent, struct name_elt *ret) case file_list_success: if (unquote_option) unquote_string (name_buffer); - if (handle_option (name_buffer) == 0) + if (!ent->v.file.verbatim && handle_option (name_buffer) == 0) { name_list_adjust (); return 1; diff --git a/src/tar.c b/src/tar.c index f8102e0..7947504 100644 --- a/src/tar.c +++ b/src/tar.c @@ -1,6 +1,6 @@ /* A tar (tape archiver) program. - Copyright 1988, 1992-1997, 1999-2001, 2003-2007, 2012-2014 Free + Copyright 1988, 1992-1997, 1999-2001, 2003-2007, 2012-2015 Free Software Foundation, Inc. Written by John Gilmore, starting 1985-08-25. @@ -323,6 +323,7 @@ enum NO_SEEK_OPTION, NO_SELINUX_CONTEXT_OPTION, NO_UNQUOTE_OPTION, + NO_VERBATIM_FILES_FROM_OPTION, NO_WILDCARDS_MATCH_SLASH_OPTION, NO_WILDCARDS_OPTION, NO_XATTR_OPTION, @@ -364,6 +365,7 @@ enum TRANSFORM_OPTION, UNQUOTE_OPTION, UTC_OPTION, + VERBATIM_FILES_FROM_OPTION, VOLNO_FILE_OPTION, WARNING_OPTION, WILDCARDS_MATCH_SLASH_OPTION, @@ -713,13 +715,19 @@ static struct argp_option options[] = { {"files-from", 'T', N_("FILE"), 0, N_("get names to extract or create from FILE"), GRID+1 }, {"null", NULL_OPTION, 0, 0, - N_("-T reads null-terminated names, disable -C"), GRID+1 }, + N_("-T reads null-terminated names; implies --verbatim-files-from"), + GRID+1 }, {"no-null", NO_NULL_OPTION, 0, 0, N_("disable the effect of the previous --null option"), GRID+1 }, {"unquote", UNQUOTE_OPTION, 0, 0, N_("unquote input file or member names (default)"), GRID+1 }, {"no-unquote", NO_UNQUOTE_OPTION, 0, 0, N_("do not unquote input file or member names"), GRID+1 }, + {"verbatim-files-from", VERBATIM_FILES_FROM_OPTION, 0, 0, + N_("-T reads file names verbatim (no option handling)"), GRID+1 }, + {"no-verbatim-files-from", NO_VERBATIM_FILES_FROM_OPTION, 0, 0, + N_("-T treats file names starting with dash as options (default)"), + GRID+1 }, {"exclude", EXCLUDE_OPTION, N_("PATTERN"), 0, N_("exclude files, given as a PATTERN"), GRID+1 }, {"exclude-from", 'X', N_("FILE"), 0, @@ -1645,7 +1653,8 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case 'T': - name_add_file (arg, filename_terminator, MAKE_INCL_OPTIONS (args)); + name_add_file (arg, filename_terminator, verbatim_files_from_option, + MAKE_INCL_OPTIONS (args)); /* Indicate we've been given -T option. This is for backward compatibility only, so that `tar cfT archive /dev/null will succeed */ @@ -1906,10 +1915,12 @@ parse_opt (int key, char *arg, struct argp_state *state) case NULL_OPTION: filename_terminator = '\0'; + verbatim_files_from_option = true; break; case NO_NULL_OPTION: filename_terminator = '\n'; + verbatim_files_from_option = false; break; case NUMERIC_OWNER_OPTION: @@ -2159,6 +2170,14 @@ parse_opt (int key, char *arg, struct argp_state *state) unquote_option = false; break; + case VERBATIM_FILES_FROM_OPTION: + verbatim_files_from_option = true; + break; + + case NO_VERBATIM_FILES_FROM_OPTION: + verbatim_files_from_option = false; + break; + case WARNING_OPTION: set_warning_option (arg); break; diff --git a/tests/Makefile.am b/tests/Makefile.am index f5b6437..70aa874 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ # Makefile for GNU tar regression tests. -# Copyright 1996-1997, 1999-2001, 2003-2007, 2009, 2012-2013 Free Software +# Copyright 1996-1997, 1999-2001, 2003-2007, 2009, 2012-2015 Free Software # This file is part of GNU tar. @@ -47,6 +47,7 @@ TESTSUITE_AT = \ T-dir01.at\ T-empty.at\ T-null.at\ + T-null2.at\ T-rec.at\ T-zfile.at\ T-nonl.at\ diff --git a/tests/T-null2.at b/tests/T-null2.at new file mode 100644 index 0000000..502bdc0 --- /dev/null +++ b/tests/T-null2.at @@ -0,0 +1,43 @@ +# This file is part of test suite for GNU tar. -*- Autotest -*- +# Copyright 2015 Free Software Foundation, Inc. +# +# GNU tar is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# GNU tar is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +AT_SETUP([--null enables verbatim reading]) +AT_KEYWORDS([files-from null T-null2 T-verbatim]) + +# According to the docs, --null should read each line from the file +# list verbatim. This feature was broken by commit 26538c9b (tar version +# 1.27). + +AT_TAR_CHECK([ +AT_DATA([file-list],[a +-b +--c d +]) + +genfile -f a +genfile -f -b +genfile -f '--c d' + +cat file-list | tr '\n' '\0' | tar -c -f archive -v --null -T - +], +[0], +[a +-b +--c d +], +[],[],[],[ustar]) # Testing one format is enough + +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index f64615a..b1e7d3b 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -1,7 +1,7 @@ # Process this file with autom4te to create testsuite. -*- Autotest -*- # Test suite for GNU tar. -# Copyright 2004-2008, 2010-2014 Free Software Foundation, Inc. +# Copyright 2004-2008, 2010-2015 Free Software Foundation, Inc. # This file is part of GNU tar. @@ -203,6 +203,7 @@ m4_include([T-rec.at]) m4_include([T-cd.at]) m4_include([T-empty.at]) m4_include([T-null.at]) +m4_include([T-null2.at]) m4_include([T-zfile.at]) m4_include([T-nonl.at]) m4_include([T-dir00.at])