From f2cd01037a4f33b6d73bb95c4d7ff19609dcd643 Mon Sep 17 00:00:00 2001 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 | 16 +++++++++++++--- src/update.c | 1 + tests/Makefile.am | 1 + tests/exclude07.at | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 1 + 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 tests/exclude07.at diff --git a/src/common.h b/src/common.h index 192cf9e..dc86900 100644 --- a/src/common.h +++ b/src/common.h @@ -550,6 +550,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 d15653d..445de56 100644 --- a/src/list.c +++ b/src/list.c @@ -89,6 +89,7 @@ read_and (void (*do_something) (void)) open_archive (ACCESS_READ); do { + bool skip; prev_status = status; tar_stat_destroy (¤t_stat_info); @@ -106,7 +107,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. */ @@ -117,7 +118,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) { @@ -655,11 +659,15 @@ decode_header (union block *header, struct tar_stat_info *stat_info, || stat_info->dumpdir) stat_info->is_dumpdir = true; } +} +void +transform_name_from_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; - + transform_member_name (&stat_info->file_name, XFORM_REGFILE); switch (header->header.typeflag) { @@ -1315,6 +1323,7 @@ print_volume_label (void) 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); @@ -1422,6 +1431,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 69fa592..3b3c0e1 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 34be617..2e781d5 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 8d76887..be4bff1 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -132,6 +132,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]) -- 1.7.2.3