Blame SOURCES/tar-1.26-restore-incremental-backups.patch

0c9d7d
diff -urN tar-1.26/src/common.h tar-1.26new/src/common.h
0c9d7d
--- tar-1.26/src/common.h	2017-01-24 09:43:08.638550577 +0100
0c9d7d
+++ tar-1.26new/src/common.h	2017-01-23 10:58:19.675411746 +0100
0c9d7d
@@ -598,6 +598,7 @@
0c9d7d
 char *normalize_filename (const char *name);
0c9d7d
 void replace_prefix (char **pname, const char *samp, size_t slen,
0c9d7d
 		     const char *repl, size_t rlen);
0c9d7d
+char *tar_savedir (const char *name, int must_exist);
0c9d7d
 
0c9d7d
 typedef struct namebuf *namebuf_t;
0c9d7d
 namebuf_t namebuf_create (const char *dir);
0c9d7d
diff -urN tar-1.26/src/incremen.c tar-1.26new/src/incremen.c
0c9d7d
--- tar-1.26/src/incremen.c	2011-02-16 23:12:16.000000000 +0100
0c9d7d
+++ tar-1.26new/src/incremen.c	2017-01-23 10:58:19.676411754 +0100
0c9d7d
@@ -1580,7 +1580,7 @@
0c9d7d
   if (!is_dumpdir (&current_stat_info))
0c9d7d
     return false;
0c9d7d
 
0c9d7d
-  current_dir = savedir (directory_name);
0c9d7d
+  current_dir = tar_savedir (directory_name, 0);
0c9d7d
 
0c9d7d
   if (!current_dir)
0c9d7d
     /* The directory doesn't exist now.  It'll be created.  In any
0c9d7d
diff -urN tar-1.26/src/misc.c tar-1.26new/src/misc.c
0c9d7d
--- tar-1.26/src/misc.c	2011-02-16 23:12:16.000000000 +0100
0c9d7d
+++ tar-1.26new/src/misc.c	2017-01-23 10:58:19.677411762 +0100
0c9d7d
@@ -483,7 +483,7 @@
0c9d7d
 
0c9d7d
 	case RECURSIVE_REMOVE_OPTION:
0c9d7d
 	  {
0c9d7d
-	    char *directory = savedir (file_name);
0c9d7d
+	    char *directory = tar_savedir (file_name, 0);
0c9d7d
 	    char const *entry;
0c9d7d
 	    size_t entrylen;
0c9d7d
 
0c9d7d
@@ -945,3 +945,31 @@
0c9d7d
   strcpy (buf->buffer + buf->dir_length, name);
0c9d7d
   return buf->buffer;
0c9d7d
 }
0c9d7d
+
0c9d7d
+/* Return the filenames in directory NAME, relative to the chdir_fd.
0c9d7d
+   If the directory does not exist, report error if MUST_EXIST is
0c9d7d
+   true.
0c9d7d
+
0c9d7d
+   Return NULL on errors.
0c9d7d
+*/
0c9d7d
+char *
0c9d7d
+tar_savedir (const char *name, int must_exist)
0c9d7d
+{
0c9d7d
+  char *ret = NULL;
0c9d7d
+  DIR *dir = NULL;
0c9d7d
+  int fd = openat (chdir_fd, name, open_read_flags | O_DIRECTORY);
0c9d7d
+  if (fd < 0)
0c9d7d
+    {
0c9d7d
+      if (!must_exist && errno == ENOENT)
0c9d7d
+	return NULL;
0c9d7d
+      open_error (name);
0c9d7d
+    }
0c9d7d
+  else if (! ((dir = fdopendir (fd))
0c9d7d
+	      && (ret = streamsavedir (dir))))
0c9d7d
+    savedir_error (name);
0c9d7d
+
0c9d7d
+  if (dir ? closedir (dir) != 0 : 0 <= fd && close (fd) != 0)
0c9d7d
+    savedir_error (name);
0c9d7d
+
0c9d7d
+  return ret;
0c9d7d
+}
0c9d7d
diff -urN tar-1.26/src/update.c tar-1.26new/src/update.c
0c9d7d
--- tar-1.26/src/update.c	2017-01-24 09:43:08.620550423 +0100
0c9d7d
+++ tar-1.26new/src/update.c	2017-01-23 12:29:20.410943374 +0100
0c9d7d
@@ -144,16 +144,8 @@
0c9d7d
 		  {
0c9d7d
 		    if (S_ISDIR (s.st_mode))
0c9d7d
 		      {
0c9d7d
-			char *p, *dirp;
0c9d7d
-			DIR *stream;
0c9d7d
-			int fd = openat (chdir_fd, name->name,
0c9d7d
-					 open_read_flags | O_DIRECTORY);
0c9d7d
-			if (fd < 0)
0c9d7d
-			  open_error (name->name);
0c9d7d
-			else if (! ((stream = fdopendir (fd))
0c9d7d
-				    && (dirp = streamsavedir (stream))))
0c9d7d
-			  savedir_error (name->name);
0c9d7d
-			else
0c9d7d
+			char *p, *dirp = tar_savedir (name->name, 1);
0c9d7d
+			if (dirp)
0c9d7d
 			  {
0c9d7d
 			    namebuf_t nbuf = namebuf_create (name->name);
0c9d7d
 
0c9d7d
@@ -166,11 +158,6 @@
0c9d7d
 
0c9d7d
 			    remname (name);
0c9d7d
 			  }
0c9d7d
-
0c9d7d
-			if (stream
0c9d7d
-			    ? closedir (stream) != 0
0c9d7d
-			    : 0 <= fd && close (fd) != 0)
0c9d7d
-			  savedir_error (name->name);
0c9d7d
 		      }
0c9d7d
 		    else if (tar_timespec_cmp (get_stat_mtime (&s),
0c9d7d
 					       current_stat_info.mtime)
0c9d7d
diff -urN tar-1.26/tests/incr07.at tar-1.26new/tests/incr07.at
0c9d7d
--- tar-1.26/tests/incr07.at	1970-01-01 01:00:00.000000000 +0100
0c9d7d
+++ tar-1.26new/tests/incr07.at	2017-01-24 09:39:34.305615960 +0100
0c9d7d
@@ -0,0 +1,112 @@
0c9d7d
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
0c9d7d
+# Test suite for GNU tar.
0c9d7d
+# Copyright 2009, 2013 Free Software Foundation, Inc.
0c9d7d
+#
0c9d7d
+# GNU tar is free software; you can redistribute it and/or modify
0c9d7d
+# it under the terms of the GNU General Public License as published by
0c9d7d
+# the Free Software Foundation; either version 3 of the License, or
0c9d7d
+# (at your option) any later version.
0c9d7d
+#
0c9d7d
+# GNU tar is distributed in the hope that it will be useful,
0c9d7d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
0c9d7d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0c9d7d
+# GNU General Public License for more details.
0c9d7d
+#
0c9d7d
+# You should have received a copy of the GNU General Public License
0c9d7d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
0c9d7d
+
0c9d7d
+AT_SETUP([incremental restores with -C])
0c9d7d
+AT_KEYWORDS([incremental extract incr07])
0c9d7d
+
0c9d7d
+# Tar 1.26 had problems extracting from incremental restores when given
0c9d7d
+# the -C option.  The code in incremen.c:try_purge_directory and
0c9d7d
+# misc.c:remove_any_file was using savedir(), which ignored eventual changes
0c9d7d
+# in the current working directory and caused the malfunctioning.
0c9d7d
+#
0c9d7d
+# The problem was reported by Piotr Rotter on 2013-03-22.
0c9d7d
+#
0c9d7d
+# This testcase is based on scripts provided by Piotr Rotter and Nathan
0c9d7d
+# Stratton Treadway.
0c9d7d
+#
0c9d7d
+# References: <514C8F56.90900@active24.pl>,
0c9d7d
+#             http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00036.html, 
0c9d7d
+#             <20130326181922.GZ3732@shire.ontko.com>,
0c9d7d
+#             http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00042.html,
0c9d7d
+#             <20130327051828.GA3732@shire.ontko.com>,
0c9d7d
+#             http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00043.html,
0c9d7d
+#             <20130327054957.GB3732@shire.ontko.com>,
0c9d7d
+#             http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00044.html
0c9d7d
+
0c9d7d
+AT_TAR_CHECK([
0c9d7d
+mkdir dirA
0c9d7d
+echo 'a' > dirA/a
0c9d7d
+echo 'a' > dirA/b
0c9d7d
+
0c9d7d
+decho C0
0c9d7d
+tar -g test.snar -vcf test.0.tar dirA
0c9d7d
+
0c9d7d
+echo 'a' > dirA/c
0c9d7d
+decho C1
0c9d7d
+tar -g test.snar -vcf test.1.tar dirA
0c9d7d
+
0c9d7d
+rm -f dirA/a
0c9d7d
+decho C2
0c9d7d
+tar -g test.snar -vcf test.2.tar dirA
0c9d7d
+
0c9d7d
+mkdir ext
0c9d7d
+rm -rf dirA
0c9d7d
+
0c9d7d
+decho E0
0c9d7d
+tar -g test.snar -vxf test.0.tar -C ext/
0c9d7d
+decho E1
0c9d7d
+tar -g test.snar -vxf test.1.tar -C ext/
0c9d7d
+
0c9d7d
+decho E2
0c9d7d
+tar -g test.snar -vxf test.2.tar -C ext/
0c9d7d
+
0c9d7d
+mkdir ext/dirA/dirB
0c9d7d
+touch ext/dirA/dirB/file
0c9d7d
+
0c9d7d
+decho E3
0c9d7d
+tar -g test.snar -vxf test.2.tar -C ext/
0c9d7d
+
0c9d7d
+echo FIN
0c9d7d
+test -d dirA && echo >&2 "toplevel dirA exists"
0c9d7d
+exit 0
0c9d7d
+],
0c9d7d
+[0],
0c9d7d
+[C0
0c9d7d
+dirA/
0c9d7d
+dirA/a
0c9d7d
+dirA/b
0c9d7d
+C1
0c9d7d
+dirA/
0c9d7d
+dirA/c
0c9d7d
+C2
0c9d7d
+dirA/
0c9d7d
+E0
0c9d7d
+dirA/
0c9d7d
+dirA/a
0c9d7d
+dirA/b
0c9d7d
+E1
0c9d7d
+dirA/
0c9d7d
+dirA/c
0c9d7d
+E2
0c9d7d
+dirA/
0c9d7d
+tar: Deleting `dirA/a'
0c9d7d
+E3
0c9d7d
+dirA/
0c9d7d
+tar: Deleting `dirA/dirB'
0c9d7d
+FIN
0c9d7d
+],
0c9d7d
+[C0
0c9d7d
+tar: dirA: Directory is new
0c9d7d
+C1
0c9d7d
+C2
0c9d7d
+E0
0c9d7d
+E1
0c9d7d
+E2
0c9d7d
+E3
0c9d7d
+],[],[],[gnu, oldgnu, posix])
0c9d7d
+
0c9d7d
+AT_CLEANUP
0c9d7d
diff -urN tar-1.26/tests/Makefile.am tar-1.26new/tests/Makefile.am
0c9d7d
--- tar-1.26/tests/Makefile.am	2017-01-24 09:43:08.656550731 +0100
0c9d7d
+++ tar-1.26new/tests/Makefile.am	2017-01-23 10:58:19.678411770 +0100
0c9d7d
@@ -98,6 +98,7 @@
0c9d7d
  incr04.at\
0c9d7d
  incr05.at\
0c9d7d
  incr06.at\
0c9d7d
+ incr07.at\
0c9d7d
  indexfile.at\
0c9d7d
  ignfail.at\
0c9d7d
  label01.at\
0c9d7d
diff -urN tar-1.26/tests/testsuite.at tar-1.26new/tests/testsuite.at
0c9d7d
--- tar-1.26/tests/testsuite.at	2017-01-24 09:43:08.656550731 +0100
0c9d7d
+++ tar-1.26new/tests/testsuite.at	2017-01-23 10:58:19.678411770 +0100
0c9d7d
@@ -259,6 +259,7 @@
0c9d7d
 m4_include([incr04.at])
0c9d7d
 m4_include([incr05.at])
0c9d7d
 m4_include([incr06.at])
0c9d7d
+m4_include([incr07.at])
0c9d7d
 
0c9d7d
 m4_include([filerem01.at])
0c9d7d
 m4_include([filerem02.at])
0c9d7d
diff -urN tar-1.26/THANKS tar-1.26new/THANKS
0c9d7d
--- tar-1.26/THANKS	2017-01-24 09:43:08.636550560 +0100
0c9d7d
+++ tar-1.26new/THANKS	2017-01-23 10:58:19.674411738 +0100
0c9d7d
@@ -397,6 +397,7 @@
0c9d7d
 Philippe Defert		defert@cern.ch
0c9d7d
 Piercarlo Grandi	piercarl@sabi.demon.co.uk
0c9d7d
 Pierce Cantrell		cantrell@ee.tamu.edu
0c9d7d
+Piotr Rotter 		piotr.rotter@active24.pl
0c9d7d
 R. Kent Dybvig		dyb@cadence.bloomington.in.us
0c9d7d
 R. Scott Butler		butler@prism.es.dupont.com
0c9d7d
 Rainer Orth		ro@TechFak.Uni-Bielefeld.DE