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

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