]> Dogcows Code - chaz/tar/commitdiff
Take into account chdir_fd when extracting from incremental dumps.
authorSergey Poznyakoff <gray@gnu.org.ua>
Sun, 15 Sep 2013 07:13:45 +0000 (10:13 +0300)
committerSergey Poznyakoff <gray@gnu.org.ua>
Sun, 15 Sep 2013 07:13:45 +0000 (10:13 +0300)
* src/common.h (tar_savedir): New prototype.
* src/misc.c (tar_savedir): New function.
(remove_any_file): Use tar_savedir.
* src/incremen.c (try_purge_directory): Use tar_savedir.
* src/update.c (update_archive): Use tar_savedir.
* tests/incr07.at: New testcase.
* tests/Makefile.am (TESTSUITE_AT): Add new test.
* tests/testsuite.at: Likewise.
* THANKS: Updated.

THANKS
src/common.h
src/incremen.c
src/misc.c
src/update.c
tests/Makefile.am
tests/incr07.at [new file with mode: 0644]
tests/testsuite.at

diff --git a/THANKS b/THANKS
index c8052a4f4d72ef0ae82fb9c2143bff5f9526e21d..79aa0ce10f5c5befec9bc35bf69328134f7253af 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -402,6 +402,7 @@ Phil Proudman               phil@proudman51.freeserve.co.uk
 Philippe Defert                defert@cern.ch
 Piercarlo Grandi       piercarl@sabi.demon.co.uk
 Pierce Cantrell                cantrell@ee.tamu.edu
+Piotr Rotter           piotr.rotter@active24.pl
 R. Kent Dybvig         dyb@cadence.bloomington.in.us
 R. Scott Butler                butler@prism.es.dupont.com
 Rainer Orth            ro@TechFak.Uni-Bielefeld.DE
index 21df8c132819dbcb79797df5ef61167cc0af1343..ccf27c33522307f177e763b15b4bffbfd4be6163 100644 (file)
@@ -596,6 +596,7 @@ char *zap_slashes (char *name);
 char *normalize_filename (const char *name);
 void replace_prefix (char **pname, const char *samp, size_t slen,
                     const char *repl, size_t rlen);
+char *tar_savedir (const char *name, int must_exist);
 
 typedef struct namebuf *namebuf_t;
 namebuf_t namebuf_create (const char *dir);
index 557df3090d502ce0074121f8501c4eb44af3a072..8aeefbeda86b403cb07399df6bdaba35d42ced6e 100644 (file)
@@ -1582,7 +1582,7 @@ try_purge_directory (char const *directory_name)
   if (!is_dumpdir (&current_stat_info))
     return false;
 
-  current_dir = savedir (directory_name);
+  current_dir = tar_savedir (directory_name, 0);
 
   if (!current_dir)
     /* The directory doesn't exist now.  It'll be created.  In any
index 1b78b69ea199cdc09e29a1c769eef595a4165594..d68d80656c8d76f25c117b073c9e71e9e62785e5 100644 (file)
@@ -631,7 +631,7 @@ remove_any_file (const char *file_name, enum remove_option option)
 
        case RECURSIVE_REMOVE_OPTION:
          {
-           char *directory = savedir (file_name);
+           char *directory = tar_savedir (file_name, 0);
            char const *entry;
            size_t entrylen;
 
@@ -1144,3 +1144,31 @@ namebuf_name (namebuf_t buf, const char *name)
   strcpy (buf->buffer + buf->dir_length, name);
   return buf->buffer;
 }
+
+/* Return the filenames in directory NAME, relative to the chdir_fd.
+   If the directory does not exist, report error if MUST_EXIST is
+   true.
+
+   Return NULL on errors.
+*/
+char *
+tar_savedir (const char *name, int must_exist)
+{
+  char *ret = NULL;
+  DIR *dir = NULL;
+  int fd = openat (chdir_fd, name, open_read_flags | O_DIRECTORY);
+  if (fd < 0)
+    {
+      if (!must_exist && errno == ENOENT)
+       return NULL;
+      open_error (name);
+    }
+  else if (! ((dir = fdopendir (fd))
+             && (ret = streamsavedir (dir))))
+    savedir_error (name);
+
+  if (dir ? closedir (dir) != 0 : 0 <= fd && close (fd) != 0)
+    savedir_error (name);
+
+  return ret;
+}
index 5e9ab98ba2c30690505a145128b5e096966c8891..72141b21bd168e8bfaea15f048aeae60a917868d 100644 (file)
@@ -145,16 +145,8 @@ update_archive (void)
                  {
                    if (S_ISDIR (s.st_mode))
                      {
-                       char *p, *dirp;
-                       DIR *stream = NULL;
-                       int fd = openat (chdir_fd, name->name,
-                                        open_read_flags | O_DIRECTORY);
-                       if (fd < 0)
-                         open_error (name->name);
-                       else if (! ((stream = fdopendir (fd))
-                                   && (dirp = streamsavedir (stream))))
-                         savedir_error (name->name);
-                       else
+                       char *p, *dirp = tar_savedir (name->name, 1);
+                       if (dirp)
                          {
                            namebuf_t nbuf = namebuf_create (name->name);
 
@@ -167,11 +159,6 @@ update_archive (void)
 
                            remname (name);
                          }
-
-                       if (stream
-                           ? closedir (stream) != 0
-                           : 0 <= fd && close (fd) != 0)
-                         savedir_error (name->name);
                      }
                    else if (tar_timespec_cmp (get_stat_mtime (&s),
                                               current_stat_info.mtime)
index b6bceea3733efde6b69e7edc7a593141e1ef742a..cfab3e0825f5fc43038255a455c04758d3ec576a 100644 (file)
@@ -111,6 +111,7 @@ TESTSUITE_AT = \
  incr04.at\
  incr05.at\
  incr06.at\
+ incr07.at\
  indexfile.at\
  ignfail.at\
  label01.at\
diff --git a/tests/incr07.at b/tests/incr07.at
new file mode 100644 (file)
index 0000000..3d5fc0e
--- /dev/null
@@ -0,0 +1,106 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+# Test suite for GNU tar.
+# Copyright 2009, 2013 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 <http://www.gnu.org/licenses/>.
+
+AT_SETUP([incremental restores with -C])
+AT_KEYWORDS([incremental extract incr07])
+
+# Tar 1.26 had problems extracting from incremental restores when given
+# the -C option.  The code in incremen.c:try_purge_directory and
+# misc.c:remove_any_file was using savedir(), which ignored eventual changes
+# in the current working directory and caused the malfunctioning.
+#
+# The problem was reported by Piotr Rotter on 2013-03-22.
+#
+# This testcase is based on scripts provided by Piotr Rotter and Nathan
+# Stratton Treadway.
+#
+# References: <514C8F56.90900@active24.pl>,
+#             http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00036.html, 
+#             <20130326181922.GZ3732@shire.ontko.com>,
+#             http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00042.html,
+#             <20130327051828.GA3732@shire.ontko.com>,
+#             http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00043.html,
+#             <20130327054957.GB3732@shire.ontko.com>,
+#             http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00044.html
+
+AT_TAR_CHECK([
+mkdir A
+echo 'a' > A/a
+echo 'a' > A/b
+
+decho C0
+tar -g test.snar -vcf test.0.tar A
+
+echo 'a' > A/c
+decho C1
+tar -g test.snar -vcf test.1.tar A
+
+rm -f A/a
+decho C2
+tar -g test.snar -vcf test.2.tar A
+
+mkdir ext
+rm -rf A
+
+decho E0
+tar -g test.snar -vxf test.0.tar -C ext/
+decho E1
+tar -g test.snar -vxf test.1.tar -C ext/
+
+mkdir ext/A/B
+touch ext/A/B/file
+
+decho E2
+tar -g test.snar -vxf test.2.tar -C ext/
+
+echo FIN
+test -d A && echo >&2 "toplevel A exists"
+exit 0
+],
+[0],
+[C0
+A/
+A/a
+A/b
+C1
+A/
+A/c
+C2
+A/
+E0
+A/
+A/a
+A/b
+E1
+A/
+A/c
+E2
+A/
+tar: Deleting 'A/a'
+tar: Deleting 'A/B'
+FIN
+],
+[C0
+tar: A: Directory is new
+C1
+C2
+E0
+E1
+E2
+],[],[],[gnu, oldgnu, posix])
+
+AT_CLEANUP
index 36868c078350009110b1d6ea8a40d5d4aed508e9..8aeebfec2ee89a51bb79384833880ebbb4aec87f 100644 (file)
@@ -296,6 +296,7 @@ m4_include([incr03.at])
 m4_include([incr04.at])
 m4_include([incr05.at])
 m4_include([incr06.at])
+m4_include([incr07.at])
 
 AT_BANNER([Files removed while archiving])
 m4_include([filerem01.at])
This page took 0.039484 seconds and 4 git commands to generate.