Blame SOURCES/tar-1.26-add-skip-old-files-option.patch

b77676
diff --git a/doc/tar.texi b/doc/tar.texi
b77676
index d70d113..a0e3d5f 100644
b77676
--- a/doc/tar.texi
b77676
+++ b/doc/tar.texi
b77676
@@ -1881,6 +1881,7 @@ The other operations of @command{tar} (@option{--list},
b77676
 @option{--extract}, @option{--compare}, and @option{--update})
b77676
 will act on the entire contents of the archive.
b77676
 
b77676
+@anchor{exit status}
b77676
 @cindex exit status
b77676
 @cindex return status
b77676
 Besides successful exits, @GNUTAR{} may fail for
b77676
@@ -2815,7 +2816,10 @@ when extracting files from an archive.
b77676
 @item --keep-old-files
b77676
 @itemx -k
b77676
 
b77676
-Do not overwrite existing files when extracting files from an archive.
b77676
+Do not overwrite existing files when extracting files from an
b77676
+archive.  Return error if such files exist.  See also
b77676
+@ref{--skip-old-files}.
b77676
+
b77676
 @xref{Keep Old Files}.
b77676
 
b77676
 @opsummary{label}
b77676
@@ -3268,6 +3272,20 @@ the archive creation operations it instructs @command{tar} to list the
b77676
 member names stored in the archive, as opposed to the actual file
b77676
 names.  @xref{listing member and file names}.
b77676
 
b77676
+@opsummary{skip-old-files}
b77676
+@item --skip-old-files
b77676
+
b77676
+Do not overwrite existing files when extracting files from an
b77676
+archive.  @xref{Keep Old Files}.
b77676
+
b77676
+This option differs from @option{--keep-old-files} in that it does not
b77676
+treat such files as an error, instead it just silently avoids
b77676
+overwriting them.
b77676
+
b77676
+The @option{--warning=existing-file} option can be used together with
b77676
+this option to produce warning messages about existing old files
b77676
+(@pxref{warnings}).
b77676
+
b77676
 @opsummary{sparse}
b77676
 @item --sparse
b77676
 @itemx -S
b77676
@@ -4443,11 +4461,11 @@ in the archive; the most recently archived members will be extracted
b77676
 last.  Additionally, an extracted member will @emph{replace} a file of
b77676
 the same name which existed in the directory already, and @command{tar}
b77676
 will not prompt you about this@footnote{Unless you give it
b77676
-@option{--keep-old-files} option, or the disk copy is newer than
b77676
-the one in the archive and you invoke @command{tar} with
b77676
-@option{--keep-newer-files} option.}.  Thus, only the most recently archived
b77676
-member will end up being extracted, as it will replace the one
b77676
-extracted before it, and so on.
b77676
+@option{--keep-old-files} (or @option{--skip-old-files}) option, or
b77676
+the disk copy is newer than the one in the archive and you invoke
b77676
+@command{tar} with @option{--keep-newer-files} option.}.  Thus, only
b77676
+the most recently archived member will end up being extracted, as it
b77676
+will replace the one extracted before it, and so on.
b77676
 
b77676
 @cindex extracting @var{n}th copy of the file
b77676
 @xopindex{occurrence, described}
b77676
@@ -5123,10 +5141,25 @@ such a directory, use the @option{--no-overwrite-dir} option.
b77676
 @cindex Overwriting old files, prevention
b77676
 @xopindex{keep-old-files, introduced}
b77676
 To be even more cautious and prevent existing files from being replaced, use
b77676
-the @option{--keep-old-files} (@option{-k}) option.  It causes @command{tar} to refuse
b77676
-to replace or update a file that already exists, i.e., a file with the
b77676
-same name as an archive member prevents extraction of that archive
b77676
-member.  Instead, it reports an error.
b77676
+the @option{--keep-old-files} (@option{-k}) option.  It causes
b77676
+@command{tar} to refuse to replace or update a file that already
b77676
+exists, i.e., a file with the same name as an archive member prevents
b77676
+extraction of that archive member.  Instead, it reports an error.  For
b77676
+example:
b77676
+
b77676
+@example
b77676
+$ @kbd{ls}
b77676
+blues
b77676
+$ @kbd{tar -x -k -f archive.tar}
b77676
+tar: blues: Cannot open: File exists
b77676
+tar: Exiting with failure status due to previous errors
b77676
+@end example
b77676
+
b77676
+@xopindex{skip-old-files, introduced}
b77676
+If you wish to preserve old files untouched, but don't want
b77676
+@command{tar} to treat them as errors, use the
b77676
+@option{--skip-old-files} option.  This option causes @command{tar} to
b77676
+silently skip extracting over existing files.
b77676
 
b77676
 @xopindex{overwrite, introduced}
b77676
 To be more aggressive about altering existing files, use the
b77676
@@ -5192,16 +5225,24 @@ archive, but remove other files before extracting.
b77676
 @node Keep Old Files
b77676
 @unnumberedsubsubsec Keep Old Files
b77676
 
b77676
+@GNUTAR{} provides two options to control its actions in a situation
b77676
+when it is about to extract a file which already exists on disk.
b77676
+
b77676
 @table @option
b77676
 @opindex keep-old-files
b77676
 @item --keep-old-files
b77676
 @itemx -k
b77676
-Do not replace existing files from archive.  The
b77676
-@option{--keep-old-files} (@option{-k}) option prevents @command{tar}
b77676
-from replacing existing files with files with the same name from the
b77676
-archive. The @option{--keep-old-files} option is meaningless with
b77676
-@option{--list} (@option{-t}).  Prevents @command{tar} from replacing
b77676
-files in the file system during extraction.
b77676
+Do not replace existing files from archive.  When such a file is
b77676
+encountered, @command{tar} issues an error message.  Upon end of
b77676
+extraction, @command{tar} exits with code 2 (@pxref{exit status}).
b77676
+
b77676
+@item --skip-old-files
b77676
+Do not replace existing files from archive, but do not treat that
b77676
+as error.  Such files are silently skipped and do not affect
b77676
+@command{tar} exit status.
b77676
+
b77676
+Additional verbosity can be obtained using @option{--warning=existing-file}
b77676
+together with that option (@pxref{warnings}).
b77676
 @end table
b77676
 
b77676
 @node Keep Newer Files
b77676
diff --git a/src/common.h b/src/common.h
b77676
index 0b9bd7a..2409413 100644
b77676
--- a/src/common.h
b77676
+++ b/src/common.h
b77676
@@ -182,6 +182,7 @@ enum old_files
b77676
   OVERWRITE_OLD_FILES,        /* --overwrite */
b77676
   UNLINK_FIRST_OLD_FILES,     /* --unlink-first */
b77676
   KEEP_OLD_FILES,             /* --keep-old-files */
b77676
+  SKIP_OLD_FILES,             /* --skip-old-files */
b77676
   KEEP_NEWER_FILES	      /* --keep-newer-files */
b77676
 };
b77676
 GLOBAL enum old_files old_files_option;
b77676
@@ -807,11 +808,12 @@ void checkpoint_run (bool do_write);
b77676
 #define WARN_UNKNOWN_KEYWORD     0x00020000
b77676
 #define WARN_XDEV                0x00040000
b77676
 #define WARN_DECOMPRESS_PROGRAM  0x00080000
b77676
+#define WARN_EXISTING_FILE       0x00100000
b77676
 
b77676
 /* The warnings composing WARN_VERBOSE_WARNINGS are enabled by default
b77676
    in verbose mode */
b77676
 #define WARN_VERBOSE_WARNINGS    (WARN_RENAME_DIRECTORY|WARN_NEW_DIRECTORY|\
b77676
-				  WARN_DECOMPRESS_PROGRAM)
b77676
+				  WARN_DECOMPRESS_PROGRAM|WARN_EXISTING_FILE)
b77676
 #define WARN_ALL                 (~WARN_VERBOSE_WARNINGS)
b77676
 
b77676
 void set_warning_option (const char *arg);
b77676
diff --git a/src/extract.c b/src/extract.c
b77676
index aaea56e..662ea0b 100644
b77676
--- a/src/extract.c
b77676
+++ b/src/extract.c
b77676
@@ -639,9 +639,14 @@ maybe_recoverable (char *file_name, bool regular, bool *interdir_made)
b77676
 
b77676
       switch (old_files_option)
b77676
 	{
b77676
-	case KEEP_OLD_FILES:
b77676
+	case SKIP_OLD_FILES:
b77676
+	  WARNOPT (WARN_EXISTING_FILE,
b77676
+		   (0, 0, _("%s: skipping existing file"), file_name));
b77676
 	  return RECOVER_SKIP;
b77676
 
b77676
+	case KEEP_OLD_FILES:
b77676
+	  return RECOVER_NO;
b77676
+
b77676
 	case KEEP_NEWER_FILES:
b77676
 	  if (file_newer_p (file_name, stp, &current_stat_info))
b77676
 	    break;
b77676
diff --git a/src/tar.c b/src/tar.c
b77676
index 7b62996..7a673e0 100644
b77676
--- a/src/tar.c
b77676
+++ b/src/tar.c
b77676
@@ -328,6 +328,7 @@ enum
b77676
   SHOW_DEFAULTS_OPTION,
b77676
   SHOW_OMITTED_DIRS_OPTION,
b77676
   SHOW_TRANSFORMED_NAMES_OPTION,
b77676
+  SKIP_OLD_FILES_OPTION,
b77676
   SPARSE_VERSION_OPTION,
b77676
   STRIP_COMPONENTS_OPTION,
b77676
   SUFFIX_OPTION,
b77676
@@ -452,7 +453,11 @@ static struct argp_option options[] = {
b77676
   {"remove-files", REMOVE_FILES_OPTION, 0, 0,
b77676
    N_("remove files after adding them to the archive"), GRID+1 },
b77676
   {"keep-old-files", 'k', 0, 0,
b77676
-   N_("don't replace existing files when extracting"), GRID+1 },
b77676
+   N_("don't replace existing files when extracting, "
b77676
+      "treat them as errors"), GRID+1 },
b77676
+  {"skip-old-files", SKIP_OLD_FILES_OPTION, 0, 0,
b77676
+   N_("don't replace existing files when extracting, silently skip over them"),
b77676
+   GRID+1 },
b77676
   {"keep-newer-files", KEEP_NEWER_FILES_OPTION, 0, 0,
b77676
    N_("don't replace existing files that are newer than their archive copies"), GRID+1 },
b77676
   {"overwrite", OVERWRITE_OPTION, 0, 0,
b77676
@@ -1618,6 +1623,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
b77676
       sparse_option = true;
b77676
       break;
b77676
 
b77676
+    case SKIP_OLD_FILES_OPTION:
b77676
+      old_files_option = SKIP_OLD_FILES;
b77676
+      break;
b77676
+
b77676
     case SPARSE_VERSION_OPTION:
b77676
       sparse_option = true;
b77676
       {
b77676
diff --git a/src/warning.c b/src/warning.c
b77676
index 5d1bcab..ee9d684 100644
b77676
--- a/src/warning.c
b77676
+++ b/src/warning.c
b77676
@@ -42,6 +42,7 @@ static char const *const warning_args[] = {
b77676
   "unknown-keyword",
b77676
   "xdev",
b77676
   "decompress-program",
b77676
+  "existing-file",
b77676
   NULL
b77676
 };
b77676
 
b77676
@@ -66,7 +67,8 @@ static int warning_types[] = {
b77676
   WARN_UNKNOWN_CAST,
b77676
   WARN_UNKNOWN_KEYWORD,
b77676
   WARN_XDEV,
b77676
-  WARN_DECOMPRESS_PROGRAM
b77676
+  WARN_DECOMPRESS_PROGRAM,
b77676
+  WARN_EXISTING_FILE,
b77676
 };
b77676
 
b77676
 ARGMATCH_VERIFY (warning_args, warning_types);
b77676
diff --git a/tests/Makefile.am b/tests/Makefile.am
b77676
index 119f1f3..3d78ea2 100644
b77676
--- a/tests/Makefile.am
b77676
+++ b/tests/Makefile.am
b77676
@@ -77,6 +77,8 @@ TESTSUITE_AT = \
b77676
  extrac07.at\
b77676
  extrac08.at\
b77676
  extrac09.at\
b77676
+ extrac18.at\
b77676
+ extrac19.at\
b77676
  extrac10.at\
b77676
  extrac11.at\
b77676
  extrac12.at\
b77676
diff --git a/tests/extrac18.at b/tests/extrac18.at
b77676
new file mode 100644
b77676
index 0000000..8b42ef7
b77676
--- /dev/null
b77676
+++ b/tests/extrac18.at
b77676
@@ -0,0 +1,60 @@
b77676
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
b77676
+#
b77676
+# Test suite for GNU tar.
b77676
+# Copyright (C) 2011 Free Software Foundation, Inc.
b77676
+#
b77676
+# This program is free software; you can redistribute it and/or modify
b77676
+# it under the terms of the GNU General Public License as published by
b77676
+# the Free Software Foundation; either version 3, or (at your option)
b77676
+# any later version.
b77676
+#
b77676
+# This program is distributed in the hope that it will be useful,
b77676
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b77676
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b77676
+# GNU General Public License for more details.
b77676
+#
b77676
+# You should have received a copy of the GNU General Public License
b77676
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
b77676
+
b77676
+# Description: Check the functionality of the --keep-old-files option.
b77676
+# It should report an error and cause tar to exit with status 2.
b77676
+#
b77676
+# There was a regression in versions 1.23 to 1.26 inclusive, where
b77676
+# this option silently skipped such files.
b77676
+# Reported by: Doug McLaren <dougmc@frenzied.us>,
b77676
+#              Gary Partis <gary@partis.co.uk>,
b77676
+#              Jim Meyering <jim@meyering.net>
b77676
+#              
b77676
+# References: <20111117045433.GA8245@algol.frenzied.us>,
b77676
+#             <4F3D824717847C4487F77228F83329A3514CBB@server.Partis.local>,
b77676
+#             <87wrar6zzz.fsf@rho.meyering.net>
b77676
+
b77676
+AT_SETUP([keep-old-files])
b77676
+AT_KEYWORDS([extract extrac18 old-files keep-old-files])
b77676
+
b77676
+AT_TAR_CHECK([
b77676
+mkdir dir
b77676
+cd dir
b77676
+echo 'Old file a' > a
b77676
+echo 'Old file b' > b
b77676
+
b77676
+tar cf ../archive .
b77676
+
b77676
+rm b
b77676
+echo 'File a' > a
b77676
+
b77676
+tar -x -k -f ../archive
b77676
+echo status=$?
b77676
+
b77676
+cat a
b77676
+],
b77676
+[0],
b77676
+[status=2
b77676
+File a
b77676
+],
b77676
+[tar: ./a: Cannot open: File exists
b77676
+tar: Exiting with failure status due to previous errors
b77676
+])
b77676
+
b77676
+AT_CLEANUP
b77676
+
b77676
diff --git a/tests/extrac19.at b/tests/extrac19.at
b77676
new file mode 100644
b77676
index 0000000..43c4c50
b77676
--- /dev/null
b77676
+++ b/tests/extrac19.at
b77676
@@ -0,0 +1,44 @@
b77676
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
b77676
+#
b77676
+# Test suite for GNU tar.
b77676
+# Copyright (C) 2011 Free Software Foundation, Inc.
b77676
+#
b77676
+# This program is free software; you can redistribute it and/or modify
b77676
+# it under the terms of the GNU General Public License as published by
b77676
+# the Free Software Foundation; either version 3, or (at your option)
b77676
+# any later version.
b77676
+#
b77676
+# This program is distributed in the hope that it will be useful,
b77676
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b77676
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b77676
+# GNU General Public License for more details.
b77676
+#
b77676
+# You should have received a copy of the GNU General Public License
b77676
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
b77676
+
b77676
+AT_SETUP([skip-old-files])
b77676
+AT_KEYWORDS([extract extrac19 old-files skip-old-files])
b77676
+
b77676
+AT_TAR_CHECK([
b77676
+mkdir dir
b77676
+cd dir
b77676
+echo 'Old file a' > a
b77676
+echo 'Old file b' > b
b77676
+
b77676
+tar cf ../archive .
b77676
+
b77676
+rm b
b77676
+echo 'File a' > a
b77676
+
b77676
+tar -x --skip-old-files -f ../archive
b77676
+echo status=$?
b77676
+
b77676
+cat a
b77676
+],
b77676
+[0],
b77676
+[status=0
b77676
+File a
b77676
+])
b77676
+
b77676
+AT_CLEANUP
b77676
+
b77676
diff --git a/tests/testsuite.at b/tests/testsuite.at
b77676
index d1dab36..e43653e 100644
b77676
--- a/tests/testsuite.at
b77676
+++ b/tests/testsuite.at
b77676
@@ -166,6 +166,9 @@ m4_include([extrac15.at])
b77676
 m4_include([extrac16.at])
b77676
 m4_include([extrac17.at])
b77676
 
b77676
+m4_include([extrac18.at])
b77676
+m4_include([extrac19.at])
b77676
+
b77676
 m4_include([label01.at])
b77676
 m4_include([label02.at])
b77676
 m4_include([label03.at])