1 This adds the --ignore-case option, which makes rsync compare filenames
2 in a case-insensitive manner.
4 To use this patch, run these commands for a successful build:
6 patch -p1 <patches/ignore-case.diff
7 ./configure (optional if already run)
12 - Make this code handle multibyte character encodings, and honor the
13 --iconv setting when converting case.
25 @@ -583,16 +584,15 @@ static int rule_matches(char *name, stru
26 if (litmatch_array(pattern, strings, slash_handling))
28 } else if (anchored_match) {
29 - if (strcmp(name, pattern) == 0)
30 + if (ic_strEQ(name, pattern))
33 int l1 = strlen(name);
34 int l2 = strlen(pattern);
36 - strcmp(name+(l1-l2),pattern) == 0 &&
37 - (l1==l2 || name[l1-(l2+1)] == '/')) {
39 + && ic_strEQ(name + (l1-l2), pattern)
40 + && (l1 == l2 || name[l1 - (l2+1)] == '/'))
48 @@ -35,6 +35,7 @@ extern int inc_recurse;
49 extern int do_progress;
50 extern int always_checksum;
52 +extern int ignore_case;
53 extern int ignore_errors;
54 extern int numeric_ids;
56 @@ -2570,6 +2571,7 @@ int f_name_cmp(const struct file_struct
61 enum fnc_state state1, state2;
62 enum fnc_type type1, type2;
63 enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM;
64 @@ -2680,7 +2682,15 @@ int f_name_cmp(const struct file_struct
66 return type1 == t_PATH ? 1 : -1;
68 - } while ((dif = (int)*c1++ - (int)*c2++) == 0);
77 + } while ((dif = (int)ch1 - (int)ch2) == 0);
83 @@ -98,3 +98,38 @@ toUpper(const char *ptr)
85 return toupper(*(unsigned char *)ptr);
89 +strEQ(const char *s1, const char *s2)
91 + return strcmp(s1, s2) == 0;
95 +strnEQ(const char *s1, const char *s2, size_t n)
97 + return strncmp(s1, s2, n) == 0;
101 +ic_strEQ(const char *s1, const char *s2)
103 + extern int ignore_case;
105 + return strcasecmp(s1, s2) == 0;
106 + return strcmp(s1, s2) == 0;
110 +ic_strnEQ(const char *s1, const char *s2, size_t n)
112 + extern int ignore_case;
114 + return strncasecmp(s1, s2, n) == 0;
115 + return strncmp(s1, s2, n) == 0;
118 +#define strNE(s1,s2) (!strEQ(s1,s2))
119 +#define strnNE(s1,s2,n) (!strnEQ(s1,s2,n))
120 +#define ic_strNE(s1,s2) (!ic_strEQ(s1,s2))
121 +#define ic_strnNE(s1,s2) (!ic_strnEQ(s1,s2,n))
122 --- old/lib/wildmatch.c
123 +++ new/lib/wildmatch.c
125 #define ISUPPER(c) (ISASCII(c) && isupper(c))
126 #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
128 +extern int ignore_case;
130 #ifdef WILD_TEST_ITERATIONS
131 int wildmatch_iteration_count;
133 @@ -72,6 +74,8 @@ static int dowild(const uchar *p, const
134 for ( ; (p_ch = *p) != '\0'; text++, p++) {
135 int matched, special;
137 + if (ignore_case && ISUPPER(p_ch))
138 + p_ch = tolower(p_ch);
139 while ((t_ch = *text) == '\0') {
142 @@ -237,12 +241,21 @@ static int dowild(const uchar *p, const
143 * of "text" and any strings in array "a". */
144 static int doliteral(const uchar *s, const uchar *text, const uchar*const *a)
147 for ( ; *s != '\0'; text++, s++) {
148 while (*text == '\0') {
149 if ((text = *a++) == NULL)
157 + s_ch = tolower(s_ch);
159 + t_ch = tolower(t_ch);
165 @@ -288,10 +301,14 @@ static const uchar *trailing_N_elements(
166 int wildmatch(const char *pattern, const char *text)
168 static const uchar *nomore[1]; /* A NULL pointer. */
170 #ifdef WILD_TEST_ITERATIONS
171 wildmatch_iteration_count = 0;
173 - return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
174 + force_lower_case = ignore_case;
175 + ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
176 + force_lower_case = 0;
180 /* Match the "pattern" against the forced-to-lower-case "text" string. */
181 @@ -331,12 +348,14 @@ int wildmatch_array(const char *pattern,
185 + force_lower_case = ignore_case;
187 if ((matched = dowild(p, text, a)) != TRUE && where < 0
188 && matched != ABORT_ALL) {
191 if ((text = (uchar*)*a++) == NULL)
196 if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE
197 @@ -344,6 +363,9 @@ int wildmatch_array(const char *pattern,
202 + force_lower_case = 0;
204 return matched == TRUE;
209 @@ -115,6 +115,7 @@ OFF_T max_size = 0;
211 int ignore_errors = 0;
212 int modify_window = 0;
213 +int ignore_case = 0;
214 int blocking_io = -1;
215 int checksum_seed = 0;
217 @@ -400,6 +401,7 @@ void usage(enum logcode F)
218 rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
219 rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
220 rprintf(F," -s, --protect-args no space-splitting; only wildcard special-chars\n");
221 + rprintf(F," --ignore-case ignore case when comparing filenames\n");
222 rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
223 rprintf(F," --port=PORT specify double-colon alternate port number\n");
224 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
225 @@ -593,6 +595,8 @@ static struct poptOption long_options[]
226 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
227 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
228 {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
229 + {"ignore-case", 0, POPT_ARG_VAL, &ignore_case, 1, 0, 0 },
230 + {"no-ignore-case", 0, POPT_ARG_VAL, &ignore_case, 0, 0, 0 },
231 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
232 {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0},
233 {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0},
234 @@ -1909,6 +1913,9 @@ void server_options(char **args, int *ar
239 + args[ac++] = "--ignore-case";
241 if (partial_dir && am_sender) {
242 if (partial_dir != tmp_partialdir) {
243 args[ac++] = "--partial-dir";
246 @@ -402,6 +402,7 @@ to the detailed description below for a
247 --files-from=FILE read list of source-file names from FILE
248 -0, --from0 all *from/filter files are delimited by 0s
249 -s, --protect-args no space-splitting; wildcard chars only
250 + --ignore-case ignore case when comparing filenames
251 --address=ADDRESS bind address for outgoing socket to daemon
252 --port=PORT specify double-colon alternate port number
253 --sockopts=OPTIONS specify custom TCP options
254 @@ -1383,6 +1384,10 @@ If you use this option with bf(--iconv),
255 from the local to the remote character set. The translation happens before
256 wild-cards are expanded. See also the bf(--files-from) option.
258 +dit(bf(--ignore-case)) This option tells rsync to ignore upper-/lower-case
259 +differences when comparing filenames. This can avoid problems when sending
260 +files to a filesystem that ignores these differences.
262 dit(bf(-T, --temp-dir=DIR)) This option instructs rsync to use DIR as a
263 scratch directory when creating temporary copies of the files transferred
264 on the receiving side. The default behavior is to create each temporary
267 @@ -31,6 +31,7 @@ int fnmatch_errors = 0;
270 int wildmatch_errors = 0;
271 +int ignore_case = 0;