Improve tar_getcwd

* src/common.h (tar_getcwd): Return pointer is const.
* src/misc.c (wd) <cwd>: New member.
(chdir_arg): Initialize cwd.
(tar_getcwd): Use cwd member to cache the result.  Take into
account absolute pathnames,
(normalize_filename): Don't free the value
returned from tar_getcwd.
* src/names.c (name_next_elt): Remove leftover call chdir().
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.

* tests/incr08.at: New testcase.
* tests/remfiles04.at: New testcase.
* tests/remfiles05.at: New testcase.
* tests/remfiles06.at: New testcase.
* tests/remfiles07.at: New testcase.
This commit is contained in:
Sergey Poznyakoff
2013-09-25 16:04:21 +03:00
parent e3d28d84bd
commit b41b004638
10 changed files with 378 additions and 24 deletions
+5
View File
@@ -112,6 +112,7 @@ TESTSUITE_AT = \
incr05.at\
incr06.at\
incr07.at\
incr08.at\
indexfile.at\
ignfail.at\
label01.at\
@@ -161,6 +162,10 @@ TESTSUITE_AT = \
remfiles01.at\
remfiles02.at\
remfiles03.at\
remfiles04.at\
remfiles05.at\
remfiles06.at\
remfiles07.at\
same-order01.at\
same-order02.at\
shortfile.at\
+86
View File
@@ -0,0 +1,86 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
# Test suite for GNU tar.
# Copyright 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/>.
# Description: In tar 1.26 listed-incremental with -C and absolute path
# would malfunction under certain conditions due to buggy filename
# normalization.
#
# The value returned by normalize_filename() is used to populate the "caname"
# field in both the "directory" structure in incremen.c and the "name"
# structure in names.c, and in both cases that field is then used in the
# "hash" and "compare" functions for the related hash tables. Thus, the
# fact that the returned value doesn't reflect the operation of previous
# "-C" options means that it's possible for two different directories to
# be given the same "caname" value in the hashed structure and thus end up
# being confused with each other.
#
# The bug is triggered when dumping both relative paths after -C and
# absolute paths that match the process' current working directory.
#
# Reported by: Nathan Stratton Treadway <nathanst@ontko.com>
# References: <20130922192135.GJ32256@shire.ontko.com>,
# http://lists.gnu.org/archive/html/bug-tar/2013-09/msg00034.html
AT_SETUP([filename normalization])
AT_KEYWORDS([incremental create incr08])
AT_TAR_CHECK([
AT_SORT_PREREQ
mkdir tartest
cd tartest
mkdir foo
mkdir foo/subdir
mkdir foo/subdir/dir1
mkdir subdir
mkdir subdir/dir2
decho A
find|sort
decho B
DIR=`pwd`
tar -cvf ../foo.tar --listed-incremental=../foo.snar -C foo . $DIR 2>../err |\
sed "s|$DIR|ABSPATH|"
sed "s|$DIR|ABSPATH|" ../err >&2
],
[0],
[A
.
./foo
./foo/subdir
./foo/subdir/dir1
./subdir
./subdir/dir2
B
./
./subdir/
./subdir/dir1/
ABSPATH/
ABSPATH/subdir/
ABSPATH/subdir/dir2/
],
[A
B
tar: .: Directory is new
tar: ./subdir: Directory is new
tar: ./subdir/dir1: Directory is new
tar: ABSPATH: Directory is new
tar: ABSPATH/subdir: Directory is new
tar: ABSPATH/subdir/dir2: Directory is new
tar: Removing leading `/' from member names
],[],[],[gnu])
AT_CLEANUP
+53
View File
@@ -0,0 +1,53 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
# Test suite for GNU tar.
# Copyright 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/>.
# Description: Tar 1.26 would remove wrong files when called with
# --remove-files and -C
# Reported by: Jörgen Strand <Jorgen.Strand@sonymobile.com>
# References: <9FC79E5CB90CEC47B9647DCAB7BD327A01AD83B452EE@seldmbx02.corpusers.net>
# http://lists.gnu.org/archive/html/bug-tar/2013-09/msg00024.html
AT_SETUP([remove-files with -C])
AT_KEYWORDS([create remove-files remfiles04])
AT_TAR_CHECK([
AT_SORT_PREREQ
mkdir foo
echo bar > bar
echo foobar > foo/bar
tar -cf foo.tar --remove-files -C foo bar
echo A
find . | sort
echo foobar > foo/bar
tar -rf foo.tar --remove-files -C foo bar
echo B
find . | sort
],
[0],
[A
.
./bar
./foo
./foo.tar
B
.
./bar
./foo
./foo.tar
],[],[],[],[gnu])
AT_CLEANUP
+60
View File
@@ -0,0 +1,60 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
# Test suite for GNU tar.
# Copyright 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/>.
# Description: Tar 1.26 would remove wrong files when invoked with
# --listed-incremental and -C
# Reported by: Nathan Stratton Treadway <nathanst@ontko.com>
# References: <20130921171234.GG32256@shire.ontko.com>,
# http://lists.gnu.org/archive/html/bug-tar/2013-09/msg00028.html
AT_SETUP([incremental and -C])
AT_KEYWORDS([incremental create remove-files remfiles05])
AT_TAR_CHECK([
AT_SORT_PREREQ
mkdir foo
echo bar > bar
echo foo/bar > foo/bar
decho A
find . | sort
decho B
tar -cvf foo.tar --listed-incremental=foo.snar --remove-files -C foo bar
decho C
find . | sort
],
[0],
[A
.
./bar
./foo
./foo/bar
B
bar
C
.
./bar
./foo
./foo.snar
./foo.tar
],
[A
B
C
],[],[],[gnu])
AT_CLEANUP
+65
View File
@@ -0,0 +1,65 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
# Test suite for GNU tar.
# Copyright 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/>.
# Description: There was a leftover call to chdir in name_next_elt() in
# tar 1.26. After commit e3d28d84 this call would confuse the tar_getcwd
# function.
# Reported by: Nathan Stratton Treadway <nathanst@ontko.com>
# References: <20130924145657.GM32256@shire.ontko.com>,
# http://lists.gnu.org/archive/html/bug-tar/2013-09/msg00045.html
AT_SETUP([incremental with two -C])
AT_KEYWORDS([incremental create remove-files remfiles06])
AT_TAR_CHECK([
AT_SORT_PREREQ
mkdir tartest
cd tartest
mkdir foo
echo foo/file > foo/file
mkdir bar
echo bar/file > bar/file
decho A
find|sort
decho B
tar -cvf ../foo.tar --remove-files -C foo file -C ../bar file
decho C
find|sort
],
[0],
[A
.
./bar
./bar/file
./foo
./foo/file
B
file
file
C
.
./bar
./foo
],
[A
B
C
],[],[],[gnu])
AT_CLEANUP
+63
View File
@@ -0,0 +1,63 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
# Test suite for GNU tar.
# Copyright 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/>.
# Description: See remfiles06.at
# Reported by: Nathan Stratton Treadway <nathanst@ontko.com>
# References: <20130924185129.GO32256@shire.ontko.com>
AT_SETUP([incremental with -C to absolute path])
AT_KEYWORDS([incremental create remove-files remfiles07])
AT_TAR_CHECK([
AT_SORT_PREREQ
mkdir tartest
cd tartest
mkdir foo
echo foo/file > foo/file
mkdir bar
echo bar/file > bar/file
decho A
find|sort
DIR=`pwd`
decho B
tar -cvf ../foo.tar --remove-files -C foo file -C $DIR/bar file
decho C
find|sort
],
[0],
[A
.
./bar
./bar/file
./foo
./foo/file
B
file
file
C
.
./bar
./foo
],
[A
B
C
],[],[],[gnu])
AT_CLEANUP
+5
View File
@@ -297,6 +297,7 @@ m4_include([incr04.at])
m4_include([incr05.at])
m4_include([incr06.at])
m4_include([incr07.at])
m4_include([incr08.at])
AT_BANNER([Files removed while archiving])
m4_include([filerem01.at])
@@ -377,6 +378,10 @@ AT_BANNER([Removing files after archiving])
m4_include([remfiles01.at])
m4_include([remfiles02.at])
m4_include([remfiles03.at])
m4_include([remfiles04.at])
m4_include([remfiles05.at])
m4_include([remfiles06.at])
m4_include([remfiles07.at])
AT_BANNER([Extended attributes])
m4_include([xattr01.at])