* 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.
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
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,
DELAY_DIRECTORY_RESTORE_OPTION,
HARD_DEREFERENCE_OPTION,
DELETE_OPTION,
+ EXCLUDE_BACKUPS_OPTION,
EXCLUDE_CACHES_OPTION,
EXCLUDE_CACHES_UNDER_OPTION,
EXCLUDE_CACHES_ALL_OPTION,
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,
| (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);
}
\f
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;
break;
case EXCLUDE_VCS_OPTION:
- exclude_vcs_files ();
+ add_exclude_array (vcs_file_table);
break;
case FORCE_LOCAL_OPTION:
delete04.at\
delete05.at\
exclude.at\
+ exclude01.at\
+ exclude02.at\
+ exclude03.at\
+ exclude04.at\
+ exclude05.at\
extrac01.at\
extrac02.at\
extrac03.at\
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+# 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
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])