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.
17 @@ -583,16 +583,15 @@ static int rule_matches(char *name, stru
18 if (litmatch_array(pattern, strings, slash_handling))
20 } else if (anchored_match) {
21 - if (strcmp(name, pattern) == 0)
22 + if (ic_strEQ(name, pattern))
25 int l1 = strlen(name);
26 int l2 = strlen(pattern);
28 - strcmp(name+(l1-l2),pattern) == 0 &&
29 - (l1==l2 || name[l1-(l2+1)] == '/')) {
31 + && ic_strEQ(name + (l1-l2), pattern)
32 + && (l1 == l2 || name[l1 - (l2+1)] == '/'))
40 @@ -35,6 +35,7 @@ extern int inc_recurse;
41 extern int do_progress;
42 extern int always_checksum;
44 +extern int ignore_case;
45 extern int ignore_errors;
46 extern int numeric_ids;
48 @@ -2570,6 +2571,7 @@ int f_name_cmp(const struct file_struct
53 enum fnc_state state1, state2;
54 enum fnc_type type1, type2;
55 enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM;
56 @@ -2680,7 +2682,15 @@ int f_name_cmp(const struct file_struct
58 return type1 == t_PATH ? 1 : -1;
60 - } while ((dif = (int)*c1++ - (int)*c2++) == 0);
69 + } while ((dif = (int)ch1 - (int)ch2) == 0);
75 @@ -98,3 +98,38 @@ toUpper(const char *ptr)
77 return toupper(*(unsigned char *)ptr);
81 +strEQ(const char *s1, const char *s2)
83 + return strcmp(s1, s2) == 0;
87 +strnEQ(const char *s1, const char *s2, size_t n)
89 + return strncmp(s1, s2, n) == 0;
93 +ic_strEQ(const char *s1, const char *s2)
95 + extern int ignore_case;
97 + return strcasecmp(s1, s2) == 0;
98 + return strcmp(s1, s2) == 0;
102 +ic_strnEQ(const char *s1, const char *s2, size_t n)
104 + extern int ignore_case;
106 + return strcasecmp(s1, s2, n) == 0;
107 + return strcmp(s1, s2, n) == 0;
110 +#define strNE(s1,s2) (!strEQ(s1,s2))
111 +#define strnNE(s1,s2,n) (!strnEQ(s1,s2,n))
112 +#define ic_strNE(s1,s2) (!ic_strEQ(s1,s2))
113 +#define ic_strnNE(s1,s2) (!ic_strnEQ(s1,s2,n))
114 --- old/lib/wildmatch.c
115 +++ new/lib/wildmatch.c
117 #define ISUPPER(c) (ISASCII(c) && isupper(c))
118 #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
120 +extern int ignore_case;
122 #ifdef WILD_TEST_ITERATIONS
123 int wildmatch_iteration_count;
125 @@ -72,6 +74,8 @@ static int dowild(const uchar *p, const
126 for ( ; (p_ch = *p) != '\0'; text++, p++) {
127 int matched, special;
129 + if (ignore_case && ISUPPER(p_ch))
130 + p_ch = tolower(p_ch);
131 while ((t_ch = *text) == '\0') {
134 @@ -237,12 +241,21 @@ static int dowild(const uchar *p, const
135 * of "text" and any strings in array "a". */
136 static int doliteral(const uchar *s, const uchar *text, const uchar*const *a)
139 for ( ; *s != '\0'; text++, s++) {
140 while (*text == '\0') {
141 if ((text = *a++) == NULL)
149 + s_ch = tolower(s_ch);
151 + t_ch = tolower(t_ch);
157 @@ -288,10 +301,14 @@ static const uchar *trailing_N_elements(
158 int wildmatch(const char *pattern, const char *text)
160 static const uchar *nomore[1]; /* A NULL pointer. */
162 #ifdef WILD_TEST_ITERATIONS
163 wildmatch_iteration_count = 0;
165 - return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
166 + force_lower_case = ignore_case;
167 + ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
168 + force_lower_case = 0;
172 /* Match the "pattern" against the forced-to-lower-case "text" string. */
173 @@ -331,12 +348,14 @@ int wildmatch_array(const char *pattern,
177 + force_lower_case = ignore_case;
179 if ((matched = dowild(p, text, a)) != TRUE && where < 0
180 && matched != ABORT_ALL) {
183 if ((text = (uchar*)*a++) == NULL)
188 if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE
189 @@ -344,6 +363,9 @@ int wildmatch_array(const char *pattern,
194 + force_lower_case = 0;
196 return matched == TRUE;
201 @@ -115,6 +115,7 @@ OFF_T max_size = 0;
203 int ignore_errors = 0;
204 int modify_window = 0;
205 +int ignore_case = 0;
206 int blocking_io = -1;
207 int checksum_seed = 0;
209 @@ -400,6 +401,7 @@ void usage(enum logcode F)
210 rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
211 rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
212 rprintf(F," -s, --protect-args no space-splitting; only wildcard special-chars\n");
213 + rprintf(F," --ignore-case ignore case when comparing filenames\n");
214 rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
215 rprintf(F," --port=PORT specify double-colon alternate port number\n");
216 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
217 @@ -593,6 +595,8 @@ static struct poptOption long_options[]
218 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
219 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
220 {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
221 + {"ignore-case", 0, POPT_ARG_VAL, &ignore_case, 1, 0, 0 },
222 + {"no-ignore-case", 0, POPT_ARG_VAL, &ignore_case, 0, 0, 0 },
223 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
224 {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0},
225 {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0},
226 @@ -1909,6 +1913,9 @@ void server_options(char **args, int *ar
231 + args[ac++] = "--ignore-case";
233 if (partial_dir && am_sender) {
234 if (partial_dir != tmp_partialdir) {
235 args[ac++] = "--partial-dir";
238 @@ -402,6 +402,7 @@ to the detailed description below for a
239 --files-from=FILE read list of source-file names from FILE
240 -0, --from0 all *from/filter files are delimited by 0s
241 -s, --protect-args no space-splitting; wildcard chars only
242 + --ignore-case ignore case when comparing filenames
243 --address=ADDRESS bind address for outgoing socket to daemon
244 --port=PORT specify double-colon alternate port number
245 --sockopts=OPTIONS specify custom TCP options
246 @@ -1383,6 +1384,10 @@ If you use this option with bf(--iconv),
247 from the local to the remote character set. The translation happens before
248 wild-cards are expanded. See also the bf(--files-from) option.
250 +dit(bf(--ignore-case)) This option tells rsync to ignore upper-/lower-case
251 +differences when comparing filenames. This can avoid problems when sending
252 +files to a filesystem that ignores these differences.
254 dit(bf(-T, --temp-dir=DIR)) This option instructs rsync to use DIR as a
255 scratch directory when creating temporary copies of the files transferred
256 on the receiving side. The default behavior is to create each temporary
259 @@ -31,6 +31,7 @@ int fnmatch_errors = 0;
262 int wildmatch_errors = 0;
263 +int ignore_case = 0;