From aeffa4f266dbeb3325300a86ae7a6652589d2021 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Wed, 12 Aug 2009 19:25:29 +0300 Subject: [PATCH] Update for new exclude module from gnulib. Add testcases by Phil Proudman. * src/names.c (is_pattern): Remove. (regex_usage_warning): Use fnmatch_pattern_has_wildcards instead of is_pattern. * src/tar.c: New option --exclude-backups. (vcs_file_table, backup_file_table): New globals. (add_exclude_array): New function. * tests/exclude01.at, tests/exclude02.at, tests/exclude03.at, tests/exclude04.at, tests/exclude05.at: New testcases. Supplied by Phil Proudman. * tests/Makefile.am (TESTSUITE_AT): Add new tests. * tests/testsuite.at: Add new tests. * THANKS: Update. --- THANKS | 1 + src/names.c | 8 +---- src/tar.c | 85 +++++++++++++++++++++++++++------------------- tests/Makefile.am | 5 +++ tests/exclude01.at | 69 +++++++++++++++++++++++++++++++++++++ tests/exclude02.at | 77 +++++++++++++++++++++++++++++++++++++++++ tests/exclude03.at | 73 +++++++++++++++++++++++++++++++++++++++ tests/exclude04.at | 73 +++++++++++++++++++++++++++++++++++++++ tests/exclude05.at | 55 ++++++++++++++++++++++++++++++ tests/testsuite.at | 5 +++ 10 files changed, 409 insertions(+), 42 deletions(-) create mode 100644 tests/exclude01.at create mode 100644 tests/exclude02.at create mode 100644 tests/exclude03.at create mode 100644 tests/exclude04.at create mode 100644 tests/exclude05.at diff --git a/THANKS b/THANKS index 9d918ba..922682f 100644 --- a/THANKS +++ b/THANKS @@ -389,6 +389,7 @@ Peter Fox fox@gec-mi-at.co.uk Peter Kutschera peter@zditr1.arcs.ac.at Peter Seebach seebs@taniemarie.solon.com Phil Hands phil@hands.com +Phil Proudman phil@proudman51.freeserve.co.uk Philippe Defert defert@cern.ch Piercarlo Grandi piercarl@sabi.demon.co.uk Pierce Cantrell cantrell@ee.tamu.edu diff --git a/src/names.c b/src/names.c index 16566bb..6e251e3 100644 --- a/src/names.c +++ b/src/names.c @@ -589,18 +589,12 @@ all_names_found (struct tar_stat_info *p) return true; } -static inline int -is_pattern (const char *string) -{ - return strchr (string, '*') || strchr (string, '[') || strchr (string, '?'); -} - static void regex_usage_warning (const char *name) { static int warned_once = 0; - if (warn_regex_usage && is_pattern (name)) + if (warn_regex_usage && fnmatch_pattern_has_wildcards (name, 0)) { warned_once = 1; WARN ((0, 0, diff --git a/src/tar.c b/src/tar.c index 943de84..3aa5287 100644 --- a/src/tar.c +++ b/src/tar.c @@ -256,6 +256,7 @@ enum DELAY_DIRECTORY_RESTORE_OPTION, HARD_DEREFERENCE_OPTION, DELETE_OPTION, + EXCLUDE_BACKUPS_OPTION, EXCLUDE_CACHES_OPTION, EXCLUDE_CACHES_UNDER_OPTION, EXCLUDE_CACHES_ALL_OPTION, @@ -659,6 +660,8 @@ static struct argp_option options[] = { N_("exclude directories containing FILE"), GRID+1 }, {"exclude-vcs", EXCLUDE_VCS_OPTION, NULL, 0, N_("exclude version control system directories"), GRID+1 }, + {"exclude-backups", EXCLUDE_BACKUPS_OPTION, NULL, 0, + N_("exclude backup and lock files"), GRID+1 }, {"no-recursion", NO_RECURSION_OPTION, 0, 0, N_("avoid descending automatically in directories"), GRID+1 }, {"one-file-system", ONE_FILE_SYSTEM_OPTION, 0, 0, @@ -844,44 +847,52 @@ struct tar_args /* Variables used during option parsing */ | (args)->matching_flags \ | recursion_option) +static char const * const vcs_file_table[] = { + /* CVS: */ + "CVS", + ".cvsignore", + /* RCS: */ + "RCS", + /* SCCS: */ + "SCCS", + /* SVN: */ + ".svn", + /* git: */ + ".git", + ".gitignore", + /* Arch: */ + ".arch-ids", + "{arch}", + "=RELEASE-ID", + "=meta-update", + "=update", + /* Bazaar */ + ".bzr", + ".bzrignore", + ".bzrtags", + /* Mercurial */ + ".hg", + ".hgignore", + ".hgtags", + /* darcs */ + "_darcs", + NULL +}; + +static char const * const backup_file_table[] = { + ".#*", + "*~", + "#*#", + NULL +}; + void -exclude_vcs_files () +add_exclude_array (char const * const * fv) { int i; - static char *vcs_file[] = { - /* CVS: */ - "CVS", - ".cvsignore", - /* RCS: */ - "RCS", - /* SCCS: */ - "SCCS", - /* SVN: */ - ".svn", - /* git: */ - ".git", - ".gitignore", - /* Arch: */ - ".arch-ids", - "{arch}", - "=RELEASE-ID", - "=meta-update", - "=update", - /* Bazaar */ - ".bzr", - ".bzrignore", - ".bzrtags", - /* Mercurial */ - ".hg", - ".hgignore", - ".hgtags", - /* darcs */ - "_darcs", - NULL - }; - for (i = 0; vcs_file[i]; i++) - add_exclude (excluded, vcs_file[i], 0); + for (i = 0; fv[i]; i++) + add_exclude (excluded, fv[i], 0); } @@ -1652,6 +1663,10 @@ parse_opt (int key, char *arg, struct argp_state *state) set_subcommand_option (DELETE_SUBCOMMAND); break; + case EXCLUDE_BACKUPS_OPTION: + add_exclude_array (backup_file_table); + break; + case EXCLUDE_OPTION: add_exclude (excluded, arg, MAKE_EXCL_OPTIONS (args)); break; @@ -1684,7 +1699,7 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case EXCLUDE_VCS_OPTION: - exclude_vcs_files (); + add_exclude_array (vcs_file_table); break; case FORCE_LOCAL_OPTION: diff --git a/tests/Makefile.am b/tests/Makefile.am index 0e22bdf..51ad526 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -61,6 +61,11 @@ TESTSUITE_AT = \ delete04.at\ delete05.at\ exclude.at\ + exclude01.at\ + exclude02.at\ + exclude03.at\ + exclude04.at\ + exclude05.at\ extrac01.at\ extrac02.at\ extrac03.at\ diff --git a/tests/exclude01.at b/tests/exclude01.at new file mode 100644 index 0000000..778a7fc --- /dev/null +++ b/tests/exclude01.at @@ -0,0 +1,69 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# Copyright (C) 2009 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 . + +AT_SETUP([exclude wildcards]) +AT_KEYWORDS([exclude exclude01]) + +AT_TAR_CHECK([ +AT_SORT_PREREQ + +rm -rf testdir +mkdir -p testdir/dir1 testdir/dir2 testdir/dir3 +touch testdir/dir1/file1 +touch testdir/dir1/\* +touch testdir/dir2/file2 +touch testdir/dir2/\* +touch testdir/dir3/file3 +touch testdir/dir3/\* + +tar cf archive --exclude=testdir/dir1/\* \ + --no-wildcards \ + --exclude=testdir/dir2/\* \ + --wildcards \ + --exclude=testdir/dir3/\* \ + testdir +tar tf archive | sort + +echo "NEXT" +tar cf archive testdir +tar t "testdir/dir1/*" -f archive | sort + +echo "NEXT" +tar cf archive testdir/dir1 +tar t --no-wildcards "testdir/dir1/*" -f archive | sort + +echo "NEXT" +tar cf archive testdir +tar t --wildcards "testdir/dir1/*" -f archive | sort + +rm -rf testdir +], +[0], +[testdir/ +testdir/dir1/ +testdir/dir2/ +testdir/dir2/file2 +testdir/dir3/ +NEXT +testdir/dir1/* +NEXT +testdir/dir1/* +NEXT +testdir/dir1/* +testdir/dir1/file1 +]) + +AT_CLEANUP diff --git a/tests/exclude02.at b/tests/exclude02.at new file mode 100644 index 0000000..7996d16 --- /dev/null +++ b/tests/exclude02.at @@ -0,0 +1,77 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# Copyright (C) 2009 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 . + +AT_SETUP([exclude: anchoring]) +AT_KEYWORDS([exclude exclude02]) + +AT_TAR_CHECK([ +AT_SORT_PREREQ + +rm -rf testdir +mkdir -p testdir +touch file1.txt +touch testdir/file1.txt +touch testdir/file2 + +tar cf archive --exclude="file1.txt" \ + testdir +tar tf archive | sort + +echo "SUB 1" +tar cf archive --no-anchored \ + --exclude="file1.txt" \ + testdir +tar tf archive | sort + +echo "SUB 2" +tar cf archive --anchored \ + --exclude="file1.txt" \ + testdir +tar tf archive | sort + +echo "SUB 3" +tar cf archive testdir file1.txt +tar t "file1.txt" -f archive | sort + +echo "SUB 4" +tar t --no-anchored "file1.txt" -f archive | sort + +echo "SUB 5" +tar t --anchored "file1.txt" -f archive | sort + +rm -rf testdir file1.txt + +], +[0], +[testdir/ +testdir/file2 +SUB 1 +testdir/ +testdir/file2 +SUB 2 +testdir/ +testdir/file1.txt +testdir/file2 +SUB 3 +file1.txt +SUB 4 +file1.txt +testdir/file1.txt +SUB 5 +file1.txt +]) + +AT_CLEANUP diff --git a/tests/exclude03.at b/tests/exclude03.at new file mode 100644 index 0000000..d592109 --- /dev/null +++ b/tests/exclude03.at @@ -0,0 +1,73 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# Copyright (C) 2009 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 . + +AT_SETUP([exclude: wildcards match slash]) +AT_KEYWORDS([exclude exclude03]) + +AT_TAR_CHECK([ +AT_SORT_PREREQ + +rm -rf testdir +mkdir -p testdir/dir1 testdir/dir2 testdir/dir3 +touch testdir/\*f\*1 +touch testdir/dir1/file1 +touch testdir/dir1/\* +touch testdir/dir2/file2 +touch testdir/dir2/\* +touch testdir/dir3/file3 +touch testdir/dir3/\* + +tar cf archive --exclude='testdir*f*1' \ + --no-wildcards-match-slash \ + --exclude='testdir*f*2' \ + --wildcards-match-slash \ + --exclude='testdir*f*3' \ + testdir +tar tf archive | sort + +echo "NEXT" +tar cf archive testdir +tar t --wildcards 'testdir/*f*1' -f archive | sort + +echo "NEXT" +tar t --wildcards --no-wildcards-match-slash 'testdir/*f*1' -f archive | sort + +echo "NEXT" +tar t --wildcards --wildcards-match-slash 'testdir/*f*1' -f archive | sort + +rm -rf testdir + +], +[0], +[testdir/ +testdir/dir1/ +testdir/dir1/* +testdir/dir2/ +testdir/dir2/* +testdir/dir2/file2 +testdir/dir3/ +testdir/dir3/* +NEXT +testdir/*f*1 +testdir/dir1/file1 +NEXT +testdir/*f*1 +NEXT +testdir/*f*1 +testdir/dir1/file1 +]) + +AT_CLEANUP diff --git a/tests/exclude04.at b/tests/exclude04.at new file mode 100644 index 0000000..c6f03cb --- /dev/null +++ b/tests/exclude04.at @@ -0,0 +1,73 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# Copyright (C) 2009 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 . + +AT_SETUP([exclude: case insensitive]) +AT_KEYWORDS([exclude exclude04]) + +AT_TAR_CHECK([ +AT_SORT_PREREQ + +rm -rf testdir +mkdir -p testdir/dir +touch testdir/file1 +touch testdir/file2 +touch testdir/file3 +touch testdir/file4 +touch testdir/dir/File1 +touch testdir/dir/File2 +touch testdir/dir/File3 +touch testdir/dir/File4 + +tar cf archive --exclude=FILE2 \ + --exclude=file1 \ + --ignore-case \ + --exclude=file3 \ + --no-ignore-case \ + --exclude=FILE2 \ + --exclude=file4 \ + testdir +tar tf archive | sort + +echo "SUB 1" +tar cf archive testdir +tar t --wildcards --wildcards-match-slash '*File2' -f archive | sort + +echo "SUB 2" +tar t --wildcards --wildcards-match-slash --ignore-case '*File2' -f archive | sort + +echo "SUB 3" +tar t --wildcards --wildcards-match-slash --no-ignore-case '*File2' -f archive | sort + +rm -rf testdir + +], +[0], +[testdir/ +testdir/dir/ +testdir/dir/File1 +testdir/dir/File2 +testdir/dir/File4 +testdir/file2 +SUB 1 +testdir/dir/File2 +SUB 2 +testdir/dir/File2 +testdir/file2 +SUB 3 +testdir/dir/File2 +]) + +AT_CLEANUP diff --git a/tests/exclude05.at b/tests/exclude05.at new file mode 100644 index 0000000..d7ad8f3 --- /dev/null +++ b/tests/exclude05.at @@ -0,0 +1,55 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- +# Copyright (C) 2009 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 . + +# Test the functioning of many items in an exclude list (should run quickly) + +AT_SETUP([exclude: lots of excludes]) +AT_KEYWORDS([exclude exclude05]) + +AT_TAR_CHECK([ +AT_SORT_PREREQ + +rm -rf testdir exclfile +mkdir -p testdir +`awk 'BEGIN {for (i=9; i < 100; ++i ) { print > "testdir/file" i; }}'` + +`awk 'BEGIN {for (i=1000000; i >= 12; --i ) { print "testdir/file" i > "exclfile"; }}'` + +tar cf archive --anchored --exclude-from=exclfile \ + testdir +tar tf archive | sort + +echo "NEXT" +tar cf archive --exclude-from=exclfile \ + testdir +tar tf archive | sort + +rm -rf testdir exclfile + +], +[0], +[testdir/ +testdir/file10 +testdir/file11 +testdir/file9 +NEXT +testdir/ +testdir/file10 +testdir/file11 +testdir/file9 +]) + +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index b22850e..325f9d0 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -125,6 +125,11 @@ m4_include([append02.at]) m4_include([xform-h.at]) m4_include([exclude.at]) +m4_include([exclude01.at]) +m4_include([exclude02.at]) +m4_include([exclude03.at]) +m4_include([exclude04.at]) +m4_include([exclude05.at]) m4_include([delete01.at]) m4_include([delete02.at]) -- 2.45.2