bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-tar] New --exclude-from-null option.


From: David M. Warme
Subject: [Bug-tar] New --exclude-from-null option.
Date: Thu, 19 May 2011 01:26:23 -0400

GNU tar fans and developers,

Here is a small patch to add a simple new option called
--exclude-from-null.  This is like --exclude-from, except that the
patterns listed in the given file are terminated with nulls instead of
newlines.  This permits patterns with newlines in them to be handled
properly.  When combined with --no-wildcards, this permits entirely
transparent specification of path names to exclude.

Note that it is probably a bad idea to simply modify the existing
--exclude-from option to obey the --null/--no-null status, since that
produces a "quiet change" in the behavior of --exclude-from.  Instead I
have introduced a completely new option.

David


David M. Warme, Ph.D.
Principal Computer Scientist
Group W, Inc.
8315 Lee Highway, Suite 400
Fairfax, VA  22031


# The following diffs are relative to the master branch.

 doc/tar.texi       |   45 +++++++++++++++++++++++++++++++++++++++++----
 src/tar.c          |   13 +++++++++++++
 tests/exclude05.at |   10 ++++++++++
 3 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/doc/tar.texi b/doc/tar.texi
index db8f986..21b170a 100644
--- a/doc/tar.texi
+++ b/doc/tar.texi
@@ -2587,6 +2587,13 @@ Exclude backup and lock files.  @xref{exclude,,
exclude-backups}.
 Similar to @option{--exclude}, except @command{tar} will use the list
of
 patterns in the file @var{file}.  @xref{exclude}.
 
address@hidden
address@hidden address@hidden
+
+Similar to @option{--exclude-from}, except that the patterns listed in
+the file @var{file} are terminated by null characters instead of
+newlines.  @xref{exclude}.
+
 @opsummary{exclude-caches}
 @item --exclude-caches
 
@@ -7130,7 +7137,8 @@ to these eventual surplus @option{-T} options as
well.
 @opindex exclude
 @opindex exclude-from
 To avoid operating on files whose names match a particular pattern,
-use the @option{--exclude} or @option{--exclude-from} options.
+use the @option{--exclude}, @option{--exclude-from} or
address@hidden options.
 
 @table @option
 @opindex exclude
@@ -7171,6 +7179,33 @@ which is difficult to catch using text editors.
 However, empty lines are OK.
 
 @table @option
address@hidden exclude-from-null
address@hidden address@hidden
+Causes @command{tar} to ignore files that match the patterns listed in
address@hidden
address@hidden table
+
address@hidden exclude-from-null
+Use the @option{--exclude-from-null} option to read a
+list of null-terminated patterns from @var{file}; @command{tar} will
+ignore files matching those patterns.  This option permits proper
+handling of patterns that contain newline characters, which can match
+filenames that contain newline characters.
+
+This option was introduced because the @option{--exclude-from} option
+has always assumed that patterns are terminated by newlines: it has
+never conformed its behavior to the current state of the
address@hidden and @option{--no-null} options like the
address@hidden option does.  If @option{--exclude-from} were
+suddenly changed to start obeying the @option{--null} and
address@hidden options, then this would result in a ``quiet
+change'' to @command{tar}'s behavior.  The
address@hidden option adds the new functionality while
+avoiding such a quiet change.  Like the @option{--exclude-from}
+option, @option{--exclude-from-null} does obey the current state of
+the @option{--wildcards} and @option{--no-wildcards} options.
+
address@hidden @option
 @cindex version control system, excluding files
 @cindex VCS, excluding files
 @cindex SCCS, excluding files
@@ -7400,7 +7435,8 @@ In earlier versions of @command{tar}, what is now
the
 @option{--exclude-from} option was called @option{--exclude} instead.
 Now, @option{--exclude} applies to patterns listed on the command
 line and @option{--exclude-from} applies to patterns listed in a
-file.
+file.  Likewise, the @option{--exclude-from-null} option applies to
+null-terminated patterns listed in a file.
 
 @end itemize
 
@@ -7466,8 +7502,9 @@ string: thus, excluding a directory also excludes
all the files beneath it.
 @unnumberedsubsec Controlling Pattern-Matching
 
 For the purposes of this section, we call @dfn{exclusion members} all
-member names obtained while processing @option{--exclude} and
address@hidden options, and @dfn{inclusion members} those
+member names obtained while processing @option{--exclude},
address@hidden and @option{--exclude-from-null}
+options, and @dfn{inclusion members} those
 member names that were given in the command line or read from the file
 specified with @option{--files-from} option.
 
diff --git a/src/tar.c b/src/tar.c
index 928cfdd..f2e6a3f 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -269,6 +269,7 @@ enum
   EXCLUDE_CACHES_UNDER_OPTION,
   EXCLUDE_CACHES_ALL_OPTION,
   EXCLUDE_OPTION,
+  EXCLUDE_FROM_NULL_OPTION,
   EXCLUDE_TAG_OPTION,
   EXCLUDE_TAG_UNDER_OPTION,
   EXCLUDE_TAG_ALL_OPTION,
@@ -654,6 +655,8 @@ static struct argp_option options[] = {
    N_("exclude files, given as a PATTERN"), GRID+1 },
   {"exclude-from", 'X', N_("FILE"), 0,
    N_("exclude patterns listed in FILE"), GRID+1 },
+  {"exclude-from-null", EXCLUDE_FROM_NULL_OPTION, N_("FILE"), 0,
+   N_("exclude null-terminate patterns listed in FILE"), GRID+1 },
   {"exclude-caches", EXCLUDE_CACHES_OPTION, 0, 0,
    N_("exclude contents of directories containing CACHEDIR.TAG, "
       "except for the tag file itself"), GRID+1 },
@@ -1695,6 +1698,16 @@ parse_opt (int key, char *arg, struct argp_state
*state)
        }
       break;
 
+    case EXCLUDE_FROM_NULL_OPTION:
+      if (add_exclude_file (add_exclude, excluded, arg,
+                           MAKE_EXCL_OPTIONS (args), '\0')
+         != 0)
+       {
+         int e = errno;
+         FATAL_ERROR ((0, e, "%s", quotearg_colon (arg)));
+       }
+      break;
+
     case 'z':
       set_use_compress_program_option (GZIP_PROGRAM);
       break;
diff --git a/tests/exclude05.at b/tests/exclude05.at
index 30e922e..17ee1c2 100644
--- a/tests/exclude05.at
+++ b/tests/exclude05.at
@@ -41,6 +41,11 @@ tar cf archive --exclude-from=exclfile \
                testdir
 tar tf archive | sort
 
+awk 'BEGIN {for (i=1000; i >= 12; --i ) { print "testdir/file" i }}'
< /dev/null | tr '\n' '\0' > exclfile
+
+echo "NEXT2"
+tar tf archive | sort
+
 rm -rf testdir exclfile
 
 ],
@@ -54,6 +59,11 @@ testdir/
 testdir/file10
 testdir/file11
 testdir/file9
+NEXT2
+testdir/
+testdir/file10
+testdir/file11
+testdir/file9
 ])
 
 AT_CLEANUP





reply via email to

[Prev in Thread] Current Thread [Next in Thread]