From 087bf010d2cd89848181e49b4ecdfd29a66353e9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 May 1998 08:43:11 +0000 Subject: [PATCH] allow the specification of multiple filenames (with or without wildcards) to a rsync server. For example you can do: rsync -avz samba::'ftp/pub/samba/README ftp/pub/samba/*.gz' . --- clientserver.c | 2 +- util.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/clientserver.c b/clientserver.c index 244bbc68..b8c4da04 100644 --- a/clientserver.c +++ b/clientserver.c @@ -212,7 +212,7 @@ static int rsync_module(int fd, int i) } if (start_glob) { - glob_expand(argv, &argc, MAX_ARGS); + glob_expand(name, argv, &argc, MAX_ARGS); } else { argc++; } diff --git a/util.c b/util.c index ed8d34e2..1fdeee6f 100644 --- a/util.c +++ b/util.c @@ -506,15 +506,18 @@ int lock_range(int fd, int offset, int len) } -void glob_expand(char **argv, int *argc, int maxargs) +static void glob_expand_one(char *s, char **argv, int *argc, int maxargs) { #ifndef HAVE_GLOB + argv[*argc] = strdup(s); (*argc)++; return; #else glob_t globbuf; int i; + argv[*argc] = strdup(s); + memset(&globbuf, 0, sizeof(globbuf)); glob(argv[*argc], 0, NULL, &globbuf); if (globbuf.gl_pathc == 0) { @@ -532,6 +535,32 @@ void glob_expand(char **argv, int *argc, int maxargs) #endif } +void glob_expand(char *base, char **argv, int *argc, int maxargs) +{ + char *s = argv[*argc]; + char *p, *q; + + if (!s || !*s) return; + + s = strdup(s); + if (!s) out_of_memory("glob_expand"); + + q = s; + while ((p = strstr(q,base)) && ((*argc) < maxargs)) { + if (p != q && *(p-1) == ' ' && p[strlen(base)] == '/') { + /* split it at this point */ + *(p-1) = 0; + glob_expand_one(q, argv, argc, maxargs); + q = p+strlen(base); + } else { + q++; + } + } + + if (*q && (*argc < maxargs)) glob_expand_one(q, argv, argc, maxargs); + + free(s); +} /******************************************************************* convert a string to lower case -- 2.34.1