Commit a8b9d4ed authored by David Dykstra's avatar David Dykstra

Changed exclude/include matching so that normally wildcards will stop at

slashes.  The old behavior of crossing slashes can be achieved by using a
double-asterisk ('**') anywhere in a pattern.  Note that this can change
some existing exclude patterns in a subtle way.  Also note that if the
remote side is an older release the processing on the two sides might not
be exactly the same when there's no double-asterisk, which can affect which
files are excluded from deletion, but they're close enough that people will
probably not notice.  I considered changing the protocol version and
checking the remote_version number to ensure the same processing on both
sides, but the exclude patterns are pre-processed before the remote version
number is known and it's just not worth going through extraordinary efforts.
Suggested by Cameron Simpson <cs@zip.com.au>
parent f83f0548
...@@ -66,6 +66,7 @@ Options ...@@ -66,6 +66,7 @@ Options
--numeric-ids don't map uid/gid values by user/group name --numeric-ids don't map uid/gid values by user/group name
--timeout=TIME set IO timeout in seconds --timeout=TIME set IO timeout in seconds
-I, --ignore-times don't exclude files that match length and time -I, --ignore-times don't exclude files that match length and time
--size-only only use file size when determining if a file should be transferred
-T --temp-dir=DIR create temporary files in directory DIR -T --temp-dir=DIR create temporary files in directory DIR
--compare-dest=DIR also compare destination files relative to DIR --compare-dest=DIR also compare destination files relative to DIR
-z, --compress compress file data -z, --compress compress file data
......
...@@ -56,7 +56,7 @@ AC_CHECK_FUNCS(strlcat strlcpy) ...@@ -56,7 +56,7 @@ AC_CHECK_FUNCS(strlcat strlcpy)
echo $ac_n "checking for working fnmatch... $ac_c" echo $ac_n "checking for working fnmatch... $ac_c"
AC_TRY_RUN([#include <fnmatch.h> AC_TRY_RUN([#include <fnmatch.h>
main() { exit(fnmatch("*.o", "x.o", 0) == 0? 0: 1); }], main() { exit(fnmatch("*.o", "x.o", FNM_PATHNAME) == 0? 0: 1); }],
echo yes;AC_DEFINE(HAVE_FNMATCH), echo yes;AC_DEFINE(HAVE_FNMATCH),
echo no) echo no)
......
...@@ -100,6 +100,7 @@ static struct exclude_struct *make_exclude(char *pattern, int include) ...@@ -100,6 +100,7 @@ static struct exclude_struct *make_exclude(char *pattern, int include)
only_included_files = 0; only_included_files = 0;
} }
ret->regular_exp = 1; ret->regular_exp = 1;
ret->fnmatch_flags = strstr(pattern, "**") ? 0 : FNM_PATHNAME;
} else if (!ret->include) { } else if (!ret->include) {
only_included_files = 0; only_included_files = 0;
} }
...@@ -143,7 +144,7 @@ static int check_one_exclude(char *name,struct exclude_struct *ex, ...@@ -143,7 +144,7 @@ static int check_one_exclude(char *name,struct exclude_struct *ex,
} }
if (ex->regular_exp) { if (ex->regular_exp) {
if (fnmatch(pattern, name, 0) == 0) if (fnmatch(pattern, name, ex->fnmatch_flags) == 0)
return 1; return 1;
} else { } else {
int l1 = strlen(name); int l1 = strlen(name);
......
...@@ -339,6 +339,7 @@ struct exclude_struct { ...@@ -339,6 +339,7 @@ struct exclude_struct {
char *orig; char *orig;
char *pattern; char *pattern;
int regular_exp; int regular_exp;
int fnmatch_flags;
int include; int include;
int directory; int directory;
int local; int local;
......
mailto(rsync-bugs@samba.org) mailto(rsync-bugs@samba.org)
manpage(rsync)(1)(17 Feb 1999)()() manpage(rsync)(1)(18 Feb 1999)()()
manpagename(rsync)(faster, flexible replacement for rcp) manpagename(rsync)(faster, flexible replacement for rcp)
manpagesynopsis() manpagesynopsis()
...@@ -641,14 +641,15 @@ itemize( ...@@ -641,14 +641,15 @@ itemize(
directory, not a file, link or device. directory, not a file, link or device.
it() if the pattern contains a wildcard character from the set it() if the pattern contains a wildcard character from the set
*?[ then regular expression matching is applied using the *?[ then expression matching is applied using the shell filename
normal shell filename matching rules. Otherwise a simple string matching rules. Otherwise a simple string match is used.
match is used.
it() if the pattern contains a / (not counting a trailing /) then it it() if the pattern contains a / (not counting a trailing /) then it
is matched against the full filename, including any leading is matched against the full filename, including any leading
directory. If the pattern doesn't contain a / then it is matched directory. If the pattern doesn't contain a / then it is matched
only against the final component of the filename. only against the final component of the filename. Furthermore, if
the pattern includes a double asterisk "**" then all wildcards in
the pattern will match slashes, otherwise they will stop at slashes.
it() if the pattern starts with "+ " (a plus followed by a space) it() if the pattern starts with "+ " (a plus followed by a space)
then it is always considered an include pattern, even if specified as then it is always considered an include pattern, even if specified as
...@@ -671,6 +672,10 @@ itemize( ...@@ -671,6 +672,10 @@ itemize(
it() --exclude "*.o" would exclude all filenames matching *.o it() --exclude "*.o" would exclude all filenames matching *.o
it() --exclude "/foo" would exclude a file in the base directory called foo it() --exclude "/foo" would exclude a file in the base directory called foo
it() --exclude "foo/" would exclude any directory called foo it() --exclude "foo/" would exclude any directory called foo
it() --exclude "/foo/*/bar" would exclude any file called bar two
levels below a base directory called foo
it() --exclude "/foo/**/bar" would exclude any file called bar two
or more levels below a base directory called foo
it() --include "*/" --include "*.c" --exclude "*" would include all it() --include "*/" --include "*.c" --exclude "*" would include all
directories and C source files directories and C source files
it() --include "foo/" --include "foo/bar.c" --exclude "*" would include it() --include "foo/" --include "foo/bar.c" --exclude "*" would include
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment