glob(3) on HP/UX 11 always strips a trailing slash from a pathname. This
breaks the differing semantics of
rsync directory host:/foo/bar
rsync directory host:/foo/bar/
Here's a patch which, at least, doesn't seem to do any harm on Solaris
or Linux and fixes the problem on HP.
Cheers,
Mark
--- util.c.OLD Tue Jan 29 15:25:08 2002
+++ util.c Tue Jan 29 15:30:03 2002
@@ -542,6 +542,7 @@
return;
#else
extern int sanitize_paths;
+ int trailing_slash = 0;
glob_t globbuf;
int i;
@@ -559,10 +560,25 @@
globfree(&globbuf);
return;
}
- for (i=0; i<(maxargs - (*argc)) && i < (int)
globbuf.gl_pathc;i++) {
+
+ /* remember pattern's trailing '/' (HP/UX glob(3) leaves it off
matches) */
+ if (*(argv[*argc] + strlen(argv[*argc]) - 1) == '/')
+ trailing_slash = 1;
+
+ for (i = 0; i < (maxargs - (*argc)) && i <
(int)globbuf.gl_pathc; i++) {
+ char *mpath;
if (i == 0) free(argv[*argc]);
- argv[(*argc) + i] = strdup(globbuf.gl_pathv[i]);
- if (!argv[(*argc) + i]) out_of_memory("glob_expand");
+ mpath = globbuf.gl_pathv[i];
+ /* pattern had a trailing '/' and this matching path does not */
+ if (trailing_slash && *mpath && (mpath[strlen(mpath) - 1] !=
'/')) {
+ argv[(*argc) + i] = malloc(strlen(mpath) + 2);
+ if (!argv[(*argc) + i]) out_of_memory("glob_expand");
+ sprintf(argv[(*argc) + i], "%s/", mpath);
+ }
+ else {
+ argv[(*argc) + i] = strdup(mpath);
+ if (!argv[(*argc) + i]) out_of_memory("glob_expand");
+ }
}
globfree(&globbuf);
(*argc) += i;