tar: --dereference consistency

This closes another race condition, that occurs when overwriting a
symlink with a regular file.
* NEWS (--dereference consistency): New section.
* doc/tar.texi (Option Summary): Describe new --deference behavior.
(dereference): Likewise.  Remove discussion that I didn't follow,
even before --dereference was changed.
* src/common.h (deref_stat, set_file_atime): Adjust signatures.
* src/compare.c (diff_file, diff_multivol): Respect open_read_flags
instead of rolling our own flags.  This implements the new behavior
for --dereference.
(diff_file, diff_dumpdir): Likewise, for fstatat_flags.
* src/create.c: Adjust to set_file_atime signature change.
* src/extract.c (mark_after_links, file_newer_p, extract_dir):
Likewise.
* src/incremen.c (try_purge_directory): Likewise.
* src/misc.c (maybe_backup_file): Likewise.
* src/extract.c (file_newer_p): New arg STP.  All callers changed.
(maybe_recoverable): New arg REGULAR.  All callers changed.
Handle the case of overwriting a symlink with a regular file,
when --overwrite is specified but --dereference is not.
(open_output_file): Add O_CLOEXEC, O_NOCTTY, O_NONBLOCK for
consistency with file creation.  Add O_NOFOLLOW if
overwriting_old_files && ! dereference_option.
* src/incremen.c (update_parent_directory): Use fstat, not fstatat;
there's less to go wrong.
* src/misc.c (deref_stat): Remove DEREF arg.  All callers changed.
Instead, use fstatat_flags.
(set_file_atime): Remove ATFLAG arg.  All callers changed.
Instead, use fstatat_flags.
* src/names.c, src/update.c: Adjust to deref_stat signature change.
* src/tar.c (get_date_or_file): Use stat, not deref_stat, as this
is not a file to be archived.
* tests/Makefile.am (TESTSUITE_AT): Add extrac13.at.
* tests/extrac13.at: New file.
* tests/testsuite.at: Include it.
This commit is contained in:
Paul Eggert
2010-09-23 19:41:05 -07:00
parent efe26f98ec
commit 14efeb9f95
14 changed files with 195 additions and 122 deletions

View File

@@ -79,6 +79,7 @@ TESTSUITE_AT = \
extrac10.at\
extrac11.at\
extrac12.at\
extrac13.at\
filerem01.at\
filerem02.at\
gzip.at\

53
tests/extrac13.at Normal file
View File

@@ -0,0 +1,53 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
# Test suite for GNU tar.
# Copyright (C) 2010 Free Software Foundation, Inc.
# This program 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, or (at your option)
# any later version.
# This program 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/>.
# written by Paul Eggert
# Check that 'tar' normally does follow symbolic links when extracting,
# unless --dereference is specified.
AT_SETUP([extract over symlinks])
AT_KEYWORDS([extract extrac13])
AT_TAR_CHECK([
mkdir src dst1 dst2 dst3
echo file1 >src/file1
ln -s target1 dst1/file1
echo target1 >dst1/target1
echo target1 >target1
tar -cf archive.tar -C src . &&
tar -xf archive.tar -C dst1 &&
diff -c src/file1 dst1/file1 &&
diff -c target1 dst1/target1
ln -s target1 dst2/file1
echo target1 >dst2/target1
tar --overwrite -xf archive.tar -C dst2 &&
diff -c src/file1 dst2/file1 &&
diff -c target1 dst2/target1
ln -s target1 dst3/file1
echo target1 >dst3/target1
tar --overwrite -xhf archive.tar -C dst3 &&
diff -c src/file1 dst3/file1 &&
diff -c src/file1 dst3/target1
],
[0],[],[],[],[],[gnu])
AT_CLEANUP

View File

@@ -151,6 +151,7 @@ m4_include([extrac09.at])
m4_include([extrac10.at])
m4_include([extrac11.at])
m4_include([extrac12.at])
m4_include([extrac13.at])
m4_include([label01.at])
m4_include([label02.at])