9934f57
tar: fix bug with -C and extracting directories
9934f57
9934f57
Problem reported by Denis Excoffier in
9934f57
<http://lists.gnu.org/archive/html/bug-tar/2010-10/msg00034.html>.
9934f57
9934f57
* src/extract.c (extract_dir): Use mkdirat, not mkdir.
9934f57
* tests/extrac16.at: New file, to test for this bug.
9934f57
* tests/Makefile.am (TESTSUITE_AT): Add it.
9934f57
* tests/testsuite.at: Include it.
9934f57
---
9934f57
 src/extract.c      |    2 +-
9934f57
 tests/Makefile.am  |    1 +
9934f57
 tests/extrac16.at  |   36 ++++++++++++++++++++++++++++++++++++
9934f57
 tests/testsuite.at |    1 +
9934f57
 4 files changed, 39 insertions(+), 1 deletions(-)
9934f57
 create mode 100644 tests/extrac16.at
9934f57
9934f57
diff --git a/src/extract.c b/src/extract.c
9934f57
index 0d23d4a..98236ac 100644
9934f57
--- a/src/extract.c
9934f57
+++ b/src/extract.c
9934f57
@@ -777,7 +777,7 @@ extract_dir (char *file_name, int typeflag)
9934f57
 
9934f57
   for (;;)
9934f57
     {
9934f57
-      status = mkdir (file_name, mode);
9934f57
+      status = mkdirat (chdir_fd, file_name, mode);
9934f57
       if (status == 0)
9934f57
 	{
9934f57
 	  current_mode = mode & ~ current_umask;
9934f57
diff --git a/tests/Makefile.am b/tests/Makefile.am
9934f57
index d29563a..b71e83c 100644
9934f57
--- a/tests/Makefile.am
9934f57
+++ b/tests/Makefile.am
9934f57
@@ -82,6 +82,7 @@ TESTSUITE_AT = \
9934f57
  extrac13.at\
9934f57
  extrac14.at\
9934f57
  extrac15.at\
9934f57
+ extrac16.at\
9934f57
  filerem01.at\
9934f57
  filerem02.at\
9934f57
  gzip.at\
9934f57
diff --git a/tests/extrac16.at b/tests/extrac16.at
9934f57
new file mode 100644
9934f57
index 0000000..625e579
9934f57
--- /dev/null
9934f57
+++ b/tests/extrac16.at
9934f57
@@ -0,0 +1,36 @@
9934f57
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
9934f57
+
9934f57
+# Test suite for GNU tar.
9934f57
+# Copyright (C) 2010 Free Software Foundation, Inc.
9934f57
+
9934f57
+# This program is free software; you can redistribute it and/or modify
9934f57
+# it under the terms of the GNU General Public License as published by
9934f57
+# the Free Software Foundation; either version 3, or (at your option)
9934f57
+# any later version.
9934f57
+
9934f57
+# This program is distributed in the hope that it will be useful,
9934f57
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
9934f57
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9934f57
+# GNU General Public License for more details.
9934f57
+
9934f57
+# You should have received a copy of the GNU General Public License
9934f57
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9934f57
+
9934f57
+# written by Paul Eggert from a bug report by Denis Excoffier
9934f57
+# <http://lists.gnu.org/archive/html/bug-tar/2010-10/msg00034.html>
9934f57
+
9934f57
+# Check extraction of empty directory with -C.
9934f57
+
9934f57
+AT_SETUP([extract empty directory with -C])
9934f57
+AT_KEYWORDS([extract extrac16])
9934f57
+
9934f57
+AT_TAR_CHECK([
9934f57
+mkdir src src/a src/a/b dest
9934f57
+touch src/a/c
9934f57
+
9934f57
+tar -cf archive.tar -C src a &&
9934f57
+tar -xf archive.tar -C dest
9934f57
+],
9934f57
+[0],[],[],[],[],[gnu])
9934f57
+
9934f57
+AT_CLEANUP
9934f57
diff --git a/tests/testsuite.at b/tests/testsuite.at
9934f57
index c386892..40f0e41 100644
9934f57
--- a/tests/testsuite.at
9934f57
+++ b/tests/testsuite.at
9934f57
@@ -154,6 +154,7 @@ m4_include([extrac12.at])
9934f57
 m4_include([extrac13.at])
9934f57
 m4_include([extrac14.at])
9934f57
 m4_include([extrac15.at])
9934f57
+m4_include([extrac16.at])
9934f57
 
9934f57
 m4_include([label01.at])
9934f57
 m4_include([label02.at])
9934f57
-- 
9934f57
1.7.2