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.
15 diff --git a/exclude.c b/exclude.c
16 index 5fa6e00..5b3b135 100644
27 @@ -697,16 +698,15 @@ static int rule_matches(const char *fname, struct filter_struct *ex, int name_is
28 if (litmatch_array(pattern, strings, slash_handling))
30 } else if (anchored_match) {
31 - if (strcmp(name, pattern) == 0)
32 + if (ic_strEQ(name, pattern))
35 int l1 = strlen(name);
36 int l2 = strlen(pattern);
38 - strcmp(name+(l1-l2),pattern) == 0 &&
39 - (l1==l2 || name[l1-(l2+1)] == '/')) {
41 + && ic_strEQ(name + (l1-l2), pattern)
42 + && (l1 == l2 || name[l1 - (l2+1)] == '/'))
48 diff --git a/flist.c b/flist.c
49 index 09b4fc5..ae70300 100644
52 @@ -34,6 +34,7 @@ extern int am_generator;
53 extern int inc_recurse;
54 extern int always_checksum;
56 +extern int ignore_case;
57 extern int ignore_errors;
58 extern int numeric_ids;
60 @@ -2924,6 +2925,7 @@ int f_name_cmp(const struct file_struct *f1, const struct file_struct *f2)
65 enum fnc_state state1, state2;
66 enum fnc_type type1, type2;
67 enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM;
68 @@ -3034,7 +3036,15 @@ int f_name_cmp(const struct file_struct *f1, const struct file_struct *f2)
70 return type1 == t_PATH ? 1 : -1;
72 - } while ((dif = (int)*c1++ - (int)*c2++) == 0);
81 + } while ((dif = (int)ch1 - (int)ch2) == 0);
85 diff --git a/ifuncs.h b/ifuncs.h
86 index 8c128d5..a4cfd3d 100644
89 @@ -77,3 +77,38 @@ init_stat_x(stat_x *sx_p)
95 +strEQ(const char *s1, const char *s2)
97 + return strcmp(s1, s2) == 0;
101 +strnEQ(const char *s1, const char *s2, size_t n)
103 + return strncmp(s1, s2, n) == 0;
107 +ic_strEQ(const char *s1, const char *s2)
109 + extern int ignore_case;
111 + return strcasecmp(s1, s2) == 0;
112 + return strcmp(s1, s2) == 0;
116 +ic_strnEQ(const char *s1, const char *s2, size_t n)
118 + extern int ignore_case;
120 + return strncasecmp(s1, s2, n) == 0;
121 + return strncmp(s1, s2, n) == 0;
124 +#define strNE(s1,s2) (!strEQ(s1,s2))
125 +#define strnNE(s1,s2,n) (!strnEQ(s1,s2,n))
126 +#define ic_strNE(s1,s2) (!ic_strEQ(s1,s2))
127 +#define ic_strnNE(s1,s2) (!ic_strnEQ(s1,s2,n))
128 diff --git a/lib/wildmatch.c b/lib/wildmatch.c
129 index f3a1731..72660ca 100644
130 --- a/lib/wildmatch.c
131 +++ b/lib/wildmatch.c
133 #define ISUPPER(c) (ISASCII(c) && isupper(c))
134 #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
136 +extern int ignore_case;
138 #ifdef WILD_TEST_ITERATIONS
139 int wildmatch_iteration_count;
141 @@ -72,6 +74,8 @@ static int dowild(const uchar *p, const uchar *text, const uchar*const *a)
142 for ( ; (p_ch = *p) != '\0'; text++, p++) {
143 int matched, special;
145 + if (ignore_case && ISUPPER(p_ch))
146 + p_ch = tolower(p_ch);
147 while ((t_ch = *text) == '\0') {
150 @@ -237,12 +241,21 @@ static int dowild(const uchar *p, const uchar *text, const uchar*const *a)
151 * of "text" and any strings in array "a". */
152 static int doliteral(const uchar *s, const uchar *text, const uchar*const *a)
155 for ( ; *s != '\0'; text++, s++) {
156 while (*text == '\0') {
157 if ((text = *a++) == NULL)
165 + s_ch = tolower(s_ch);
167 + t_ch = tolower(t_ch);
173 @@ -288,10 +301,14 @@ static const uchar *trailing_N_elements(const uchar*const **a_ptr, int count)
174 int wildmatch(const char *pattern, const char *text)
176 static const uchar *nomore[1]; /* A NULL pointer. */
178 #ifdef WILD_TEST_ITERATIONS
179 wildmatch_iteration_count = 0;
181 - return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
182 + force_lower_case = ignore_case;
183 + ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
184 + force_lower_case = 0;
188 /* Match the "pattern" against the forced-to-lower-case "text" string. */
189 @@ -331,12 +348,14 @@ int wildmatch_array(const char *pattern, const char*const *texts, int where)
193 + force_lower_case = ignore_case;
195 if ((matched = dowild(p, text, a)) != TRUE && where < 0
196 && matched != ABORT_ALL) {
199 if ((text = (uchar*)*a++) == NULL)
204 if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE
205 @@ -344,6 +363,9 @@ int wildmatch_array(const char *pattern, const char*const *texts, int where)
210 + force_lower_case = 0;
212 return matched == TRUE;
215 diff --git a/options.c b/options.c
216 index e7c6c61..6e73e9c 100644
219 @@ -117,6 +117,7 @@ OFF_T max_size = 0;
221 int ignore_errors = 0;
222 int modify_window = 0;
223 +int ignore_case = 0;
224 int blocking_io = -1;
225 int checksum_seed = 0;
227 @@ -759,6 +760,7 @@ void usage(enum logcode F)
228 rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
229 rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
230 rprintf(F," -s, --protect-args no space-splitting; only wildcard special-chars\n");
231 + rprintf(F," --ignore-case ignore case when comparing filenames\n");
232 rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
233 rprintf(F," --port=PORT specify double-colon alternate port number\n");
234 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
235 @@ -973,6 +975,8 @@ static struct poptOption long_options[] = {
236 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
237 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
238 {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
239 + {"ignore-case", 0, POPT_ARG_VAL, &ignore_case, 1, 0, 0 },
240 + {"no-ignore-case", 0, POPT_ARG_VAL, &ignore_case, 0, 0, 0 },
241 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
242 {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0},
243 {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0},
244 @@ -2505,6 +2509,9 @@ void server_options(char **args, int *argc_p)
249 + args[ac++] = "--ignore-case";
251 if (partial_dir && am_sender) {
252 if (partial_dir != tmp_partialdir) {
253 args[ac++] = "--partial-dir";
254 diff --git a/rsync.yo b/rsync.yo
255 index 941f7a5..339aca8 100644
258 @@ -414,6 +414,7 @@ to the detailed description below for a complete description. verb(
259 --files-from=FILE read list of source-file names from FILE
260 -0, --from0 all *from/filter files are delimited by 0s
261 -s, --protect-args no space-splitting; wildcard chars only
262 + --ignore-case ignore case when comparing filenames
263 --address=ADDRESS bind address for outgoing socket to daemon
264 --port=PORT specify double-colon alternate port number
265 --sockopts=OPTIONS specify custom TCP options
266 @@ -1563,6 +1564,10 @@ If you use this option with bf(--iconv), the args will also be translated
267 from the local to the remote character-set. The translation happens before
268 wild-cards are expanded. See also the bf(--files-from) option.
270 +dit(bf(--ignore-case)) This option tells rsync to ignore upper-/lower-case
271 +differences when comparing filenames. This can avoid problems when sending
272 +files to a filesystem that ignores these differences.
274 dit(bf(-T, --temp-dir=DIR)) This option instructs rsync to use DIR as a
275 scratch directory when creating temporary copies of the files transferred
276 on the receiving side. The default behavior is to create each temporary
277 diff --git a/wildtest.c b/wildtest.c
278 index 07351a1..c899eb8 100644
282 int fnmatch_errors = 0;
285 +int ignore_case = 0;
286 int wildmatch_errors = 0;
287 char number_separator = ',';