From: Kamil Dudka Date: Fri, 24 Sep 2010 14:16:04 +0200 Subject: [PATCH] tar: match non-stripped file names * src/common.h: Declare of transform_name_from_header(). * src/list.c (read_and): Match non-stripped file names. (transform_name_from_header): Detached part of code of decode_header(). (print_volume_label): Avoid any change in behavior here. (test_archive_label): Avoid any change in behavior here. * src/update.c (update_archive): Avoid any change in behavior here. * tests/exclude07.at: New test case. * tests/testsuite.at: Include exclude07.at. * tests/Makefile.am (TESTSUITE_AT): Add exclude07.at. --- src/common.h | 1 + src/list.c | 14 ++++++++++++-- src/update.c | 1 + tests/Makefile.am | 1 + tests/exclude07.at | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 1 + 6 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/common.h b/src/common.h index 4cadab9..3a36b9b 100644 --- a/src/common.h +++ b/src/common.h @@ -575,6 +575,7 @@ extern size_t recent_long_link_blocks; void decode_header (union block *header, struct tar_stat_info *stat_info, enum archive_format *format_pointer, int do_user_group); +void transform_name_from_header(union block *header, struct tar_stat_info *); char const *tartime (struct timespec t, bool full_time); #define OFF_FROM_HEADER(where) off_from_header (where, sizeof (where)) diff --git a/src/list.c b/src/list.c index 1edd504..4e0e1a0 100644 --- a/src/list.c +++ b/src/list.c @@ -75,6 +75,7 @@ read_and (void (*do_something) (void)) open_archive (ACCESS_READ); do { + bool skip; prev_status = status; tar_stat_destroy (¤t_stat_info); @@ -92,7 +93,7 @@ read_and (void (*do_something) (void)) Ensure incoming names are null terminated. */ decode_header (current_header, ¤t_stat_info, ¤t_format, 1); - if (! name_match (current_stat_info.file_name) + skip = (! name_match (current_stat_info.file_name) || (NEWER_OPTION_INITIALIZED (newer_mtime_option) /* FIXME: We get mtime now, and again later; this causes duplicate diagnostics if header.mtime is bogus. */ @@ -103,7 +104,10 @@ read_and (void (*do_something) (void)) mtime.tv_nsec = 0, current_stat_info.mtime = mtime, OLDER_TAR_STAT_TIME (current_stat_info, m))) - || excluded_name (current_stat_info.file_name)) + || excluded_name (current_stat_info.file_name)); + + transform_name_from_header (current_header, ¤t_stat_info); + if (skip) { switch (current_header->header.typeflag) { @@ -659,7 +663,11 @@ decode_header (union block *header, struct tar_stat_info *stat_info, if (header->header.typeflag == GNUTYPE_VOLHDR) /* Name transformations don't apply to volume headers. */ return; +} +void +transform_name_from_header(union block *header, struct tar_stat_info *stat_info) +{ transform_member_name (&stat_info->file_name, XFORM_REGFILE); switch (header->header.typeflag) { @@ -1322,6 +1330,7 @@ print_volume_label () tar_stat_init (&vstat); assign_string (&vstat.file_name, "."); decode_header (&vblk, &vstat, &dummy, 0); + transform_name_from_header (&vblk, &vstat); assign_string (&vstat.file_name, volume_label); simple_print_header (&vstat, &vblk, 0); tar_stat_destroy (&vstat); @@ -1431,6 +1440,7 @@ test_archive_label () { decode_header (current_header, ¤t_stat_info, ¤t_format, 0); + transform_name_from_header (current_header, ¤t_stat_info); if (current_header->header.typeflag == GNUTYPE_VOLHDR) assign_string (&volume_label, current_header->header.name); diff --git a/src/update.c b/src/update.c index b015175..7dd16cb 100644 --- a/src/update.c +++ b/src/update.c @@ -130,6 +130,7 @@ update_archive (void) decode_header (current_header, ¤t_stat_info, ¤t_format, 0); + transform_name_from_header (current_header, ¤t_stat_info); archive_format = current_format; if (subcommand_option == UPDATE_SUBCOMMAND diff --git a/tests/Makefile.am b/tests/Makefile.am index fe2535a..7434fc2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -67,6 +67,7 @@ TESTSUITE_AT = \ exclude04.at\ exclude05.at\ exclude06.at\ + exclude07.at\ extrac01.at\ extrac02.at\ extrac03.at\ diff --git a/tests/exclude07.at b/tests/exclude07.at new file mode 100644 index 0000000..ad376aa --- /dev/null +++ b/tests/exclude07.at @@ -0,0 +1,42 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# 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 . + +# upstream tar from 14efeb9f956e38d7beaf3fbedb04d3f3bb9ece3a fails to exclude +# files by stripped part of path by --strip-components +# +# Reported-by: Darius Ivanauskas +# References: https://bugzilla.redhat.com/637085 + +AT_SETUP([exclude: stripped part of path]) +AT_KEYWORDS([exclude exclude07]) + +AT_TAR_CHECK([ +mkdir foo bar +genfile --length 20 -f foo/file1 +genfile --length 20 -f foo/file2 +genfile --length 20 -f foo/file3 +genfile --length 20 -f bar/file4 + +tar cf archive.tar foo bar +mkdir out +tar -C out -xf archive.tar --strip-components=1 bar/ +find out -type f +], +[0], +[out/file4] +) + +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index ef70b99..8b533ed 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -131,6 +131,7 @@ m4_include([exclude03.at]) m4_include([exclude04.at]) m4_include([exclude05.at]) m4_include([exclude06.at]) +m4_include([exclude07.at]) m4_include([delete01.at]) m4_include([delete02.at]) diff -urNp tar-1.24-orig/tests/xform01.at tar-1.24/tests/xform01.at --- tar-1.24-orig/tests/xform01.at 2010-10-24 20:07:47.000000000 +0200 +++ tar-1.24/tests/xform01.at 2010-10-25 15:49:42.866904079 +0200 @@ -29,7 +29,7 @@ AT_KEYWORDS([transform xform xform01 vol AT_TAR_CHECK([ genfile --file file tar -cf archive.tar -V /label/ file -tar tf archive.tar +tar Ptf archive.tar ], [0], [/label/