Fix bug in the inplementation of --one-top-level.
When extracting an archive that contains './' with the --one-top-level option, the mode and ownership of '.' would be incorrectly applied to the current working directory, instead of the requested top-level directory. * src/list.c (enforce_one_top_level): Map '.' to the top-level directory. * tests/Makefile.am: Add onetop05.at * tests/testsuite.at: Include onetop05.at. * tests/onetop05.at: New file. * tests/onetop01.at: Fix keywords. * tests/onetop02.at: Likewise. * tests/onetop03.at: Likewise. * tests/onetop04.at: Likewise.
This commit is contained in:
20
src/list.c
20
src/list.c
@@ -124,18 +124,20 @@ enforce_one_top_level (char **pfile_name)
|
|||||||
for (p = file_name; *p && (ISSLASH (*p) || *p == '.'); p++)
|
for (p = file_name; *p && (ISSLASH (*p) || *p == '.'); p++)
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!*p)
|
if (*p)
|
||||||
return;
|
|
||||||
|
|
||||||
if (strncmp (p, one_top_level_dir, strlen (one_top_level_dir)) == 0)
|
|
||||||
{
|
{
|
||||||
int pos = strlen (one_top_level_dir);
|
int pos = strlen (one_top_level_dir);
|
||||||
if (ISSLASH (p[pos]) || p[pos] == 0)
|
if (strncmp (p, one_top_level_dir, pos) == 0)
|
||||||
return;
|
{
|
||||||
|
if (ISSLASH (p[pos]) || p[pos] == 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pfile_name = new_name (one_top_level_dir, file_name);
|
||||||
|
normalize_filename_x (*pfile_name);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
*pfile_name = new_name (one_top_level_dir, file_name);
|
*pfile_name = xstrdup (one_top_level_dir);
|
||||||
normalize_filename_x (*pfile_name);
|
|
||||||
free (file_name);
|
free (file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ TESTSUITE_AT = \
|
|||||||
onetop02.at\
|
onetop02.at\
|
||||||
onetop03.at\
|
onetop03.at\
|
||||||
onetop04.at\
|
onetop04.at\
|
||||||
|
onetop05.at\
|
||||||
opcomp01.at\
|
opcomp01.at\
|
||||||
opcomp02.at\
|
opcomp02.at\
|
||||||
opcomp03.at\
|
opcomp03.at\
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Process this file with autom4te to create testsuite. -*- Autotest -*-
|
# Process this file with autom4te to create testsuite. -*- Autotest -*-
|
||||||
#
|
#
|
||||||
# Test suite for GNU tar.
|
# Test suite for GNU tar.
|
||||||
# Copyright 2014 Free Software Foundation, Inc.
|
# Copyright 2014,2015 Free Software Foundation, Inc.
|
||||||
#
|
#
|
||||||
# This file is part of GNU tar.
|
# This file is part of GNU tar.
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Process this file with autom4te to create testsuite. -*- Autotest -*-
|
# Process this file with autom4te to create testsuite. -*- Autotest -*-
|
||||||
#
|
#
|
||||||
# Test suite for GNU tar.
|
# Test suite for GNU tar.
|
||||||
# Copyright 2014 Free Software Foundation, Inc.
|
# Copyright 2014,2015 Free Software Foundation, Inc.
|
||||||
#
|
#
|
||||||
# This file is part of GNU tar.
|
# This file is part of GNU tar.
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Process this file with autom4te to create testsuite. -*- Autotest -*-
|
# Process this file with autom4te to create testsuite. -*- Autotest -*-
|
||||||
#
|
#
|
||||||
# Test suite for GNU tar.
|
# Test suite for GNU tar.
|
||||||
# Copyright 2014 Free Software Foundation, Inc.
|
# Copyright 2014,2015 Free Software Foundation, Inc.
|
||||||
#
|
#
|
||||||
# This file is part of GNU tar.
|
# This file is part of GNU tar.
|
||||||
#
|
#
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
AT_SETUP([tar --one-top-level --transform])
|
AT_SETUP([tar --one-top-level --transform])
|
||||||
AT_KEYWORDS([extract onetop onetop02])
|
AT_KEYWORDS([extract onetop onetop03])
|
||||||
|
|
||||||
AT_TAR_CHECK([
|
AT_TAR_CHECK([
|
||||||
AT_SORT_PREREQ
|
AT_SORT_PREREQ
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Process this file with autom4te to create testsuite. -*- Autotest -*-
|
# Process this file with autom4te to create testsuite. -*- Autotest -*-
|
||||||
#
|
#
|
||||||
# Test suite for GNU tar.
|
# Test suite for GNU tar.
|
||||||
# Copyright 2014 Free Software Foundation, Inc.
|
# Copyright 2014,2015 Free Software Foundation, Inc.
|
||||||
#
|
#
|
||||||
# This file is part of GNU tar.
|
# This file is part of GNU tar.
|
||||||
#
|
#
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
AT_SETUP([tar --one-top-level --transform])
|
AT_SETUP([tar --one-top-level --transform])
|
||||||
AT_KEYWORDS([extract onetop onetop02])
|
AT_KEYWORDS([extract onetop onetop04])
|
||||||
|
|
||||||
AT_TAR_CHECK([
|
AT_TAR_CHECK([
|
||||||
AT_SORT_PREREQ
|
AT_SORT_PREREQ
|
||||||
|
|||||||
69
tests/onetop05.at
Normal file
69
tests/onetop05.at
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# Process this file with autom4te to create testsuite. -*- Autotest -*-
|
||||||
|
#
|
||||||
|
# Test suite for GNU tar.
|
||||||
|
# Copyright 2015 Free Software Foundation, Inc.
|
||||||
|
#
|
||||||
|
# This file is part of GNU tar.
|
||||||
|
#
|
||||||
|
# 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([tar --one-top-level restoring permissions])
|
||||||
|
AT_KEYWORDS([extract onetop onetop05])
|
||||||
|
|
||||||
|
# When extracting an archive that contains ./ with the --one-top-level option,
|
||||||
|
# the mode and ownership of ./ would be incorrectly applied to the current
|
||||||
|
# working directory, instead of the requested top-level directory.
|
||||||
|
|
||||||
|
AT_TAR_CHECK([
|
||||||
|
orig_mode=3702
|
||||||
|
mkdir d
|
||||||
|
chmod $orig_mode d
|
||||||
|
genfile --file d/file
|
||||||
|
tar -cf d.tar -C d .
|
||||||
|
rm -rf d
|
||||||
|
|
||||||
|
(mkdir d1
|
||||||
|
chmod 700 d1
|
||||||
|
cd d1
|
||||||
|
tar --one-top-level=top -xpf ../d.tar)
|
||||||
|
mode=$(genfile --stat=mode.777 d1)
|
||||||
|
if test 700 = $mode; then
|
||||||
|
echo "CWD: OK"
|
||||||
|
else
|
||||||
|
echo "CWD: mode changed: 700 != $mode"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir d2
|
||||||
|
chmod 700 d2
|
||||||
|
tar -C d2 --one-top-level=top -xpf d.tar
|
||||||
|
mode=$(genfile --stat=mode.777 d2)
|
||||||
|
if test 700 = $mode; then
|
||||||
|
echo "DIR: OK"
|
||||||
|
else
|
||||||
|
echo "DIR: mode changed: 700 != $mode"
|
||||||
|
fi
|
||||||
|
mode=$(genfile --stat=mode.7777 d2/top)
|
||||||
|
if test $mode = $orig_mode; then
|
||||||
|
echo "TOP: OK"
|
||||||
|
else
|
||||||
|
echo "TOP: mode changed: $orig_mode != $mode"
|
||||||
|
fi
|
||||||
|
],
|
||||||
|
[0],
|
||||||
|
[CWD: OK
|
||||||
|
DIR: OK
|
||||||
|
TOP: OK
|
||||||
|
])
|
||||||
|
|
||||||
|
AT_CLEANUP
|
||||||
@@ -428,6 +428,7 @@ m4_include([onetop01.at])
|
|||||||
m4_include([onetop02.at])
|
m4_include([onetop02.at])
|
||||||
m4_include([onetop03.at])
|
m4_include([onetop03.at])
|
||||||
m4_include([onetop04.at])
|
m4_include([onetop04.at])
|
||||||
|
m4_include([onetop05.at])
|
||||||
|
|
||||||
AT_BANNER([Star tests])
|
AT_BANNER([Star tests])
|
||||||
m4_include([star/gtarfail.at])
|
m4_include([star/gtarfail.at])
|
||||||
|
|||||||
Reference in New Issue
Block a user