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 based-on: 6c8ca91c731b7bf2b081694bda85b7dadc2b7aff
16 diff --git a/exclude.c b/exclude.c
19 @@ -966,16 +966,15 @@ static int rule_matches(const char *fname, filter_rule *ex, int name_flags)
20 if (litmatch_array(pattern, strings, slash_handling))
22 } else if (anchored_match) {
23 - if (strcmp(name, pattern) == 0)
24 + if (ic_strEQ(name, pattern))
27 int l1 = strlen(name);
28 int l2 = strlen(pattern);
30 - strcmp(name+(l1-l2),pattern) == 0 &&
31 - (l1==l2 || name[l1-(l2+1)] == '/')) {
33 + && ic_strEQ(name + (l1-l2), pattern)
34 + && (l1 == l2 || name[l1 - (l2+1)] == '/'))
40 diff --git a/flist.c b/flist.c
43 @@ -34,6 +34,7 @@ extern int am_generator;
44 extern int inc_recurse;
45 extern int always_checksum;
47 +extern int ignore_case;
48 extern int ignore_errors;
49 extern int numeric_ids;
51 @@ -2638,7 +2639,8 @@ struct file_list *recv_file_list(int f, int dir_ndx)
53 if (cur_dir != good_dirname) {
54 const char *d = dir_ndx >= 0 ? f_name(dir_flist->files[dir_ndx], NULL) : empty_dir;
55 - if (strcmp(cur_dir, d) != 0) {
56 + int dir_differs = ignore_case ? strcasecmp(cur_dir, d) : strcmp(cur_dir, d);
59 "ABORTING due to invalid path from sender: %s/%s\n",
60 cur_dir, file->basename);
61 @@ -3205,6 +3207,7 @@ int f_name_cmp(const struct file_struct *f1, const struct file_struct *f2)
66 enum fnc_state state1, state2;
67 enum fnc_type type1, type2;
68 enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM;
69 @@ -3315,7 +3318,15 @@ int f_name_cmp(const struct file_struct *f1, const struct file_struct *f2)
71 return type1 == t_PATH ? 1 : -1;
73 - } while ((dif = (int)*c1++ - (int)*c2++) == 0);
82 + } while ((dif = (int)ch1 - (int)ch2) == 0);
86 diff --git a/ifuncs.h b/ifuncs.h
89 @@ -110,3 +110,38 @@ static inline char *my_strdup(const char *str, const char *file, int line)
90 memcpy(buf, str, len);
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 --- a/lib/wildmatch.c
130 +++ b/lib/wildmatch.c
132 #define ISUPPER(c) (ISASCII(c) && isupper(c))
133 #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
135 +extern int ignore_case;
137 #ifdef WILD_TEST_ITERATIONS
138 int wildmatch_iteration_count;
140 @@ -72,6 +74,8 @@ static int dowild(const uchar *p, const uchar *text, const uchar*const *a)
141 for ( ; (p_ch = *p) != '\0'; text++, p++) {
142 int matched, special;
144 + if (ignore_case && ISUPPER(p_ch))
145 + p_ch = tolower(p_ch);
146 while ((t_ch = *text) == '\0') {
149 @@ -237,12 +241,21 @@ static int dowild(const uchar *p, const uchar *text, const uchar*const *a)
150 * of "text" and any strings in array "a". */
151 static int doliteral(const uchar *s, const uchar *text, const uchar*const *a)
154 for ( ; *s != '\0'; text++, s++) {
155 while (*text == '\0') {
156 if ((text = *a++) == NULL)
164 + s_ch = tolower(s_ch);
166 + t_ch = tolower(t_ch);
172 @@ -288,10 +301,14 @@ static const uchar *trailing_N_elements(const uchar*const **a_ptr, int count)
173 int wildmatch(const char *pattern, const char *text)
175 static const uchar *nomore[1]; /* A NULL pointer. */
177 #ifdef WILD_TEST_ITERATIONS
178 wildmatch_iteration_count = 0;
180 - return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
181 + force_lower_case = ignore_case;
182 + ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
183 + force_lower_case = 0;
187 /* Match the "pattern" against the forced-to-lower-case "text" string. */
188 @@ -331,12 +348,14 @@ int wildmatch_array(const char *pattern, const char*const *texts, int where)
192 + force_lower_case = ignore_case;
194 if ((matched = dowild(p, text, a)) != TRUE && where < 0
195 && matched != ABORT_ALL) {
198 if ((text = (uchar*)*a++) == NULL)
203 if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE
204 @@ -344,6 +363,9 @@ int wildmatch_array(const char *pattern, const char*const *texts, int where)
209 + force_lower_case = 0;
211 return matched == TRUE;
214 diff --git a/options.c b/options.c
217 @@ -131,6 +131,7 @@ OFF_T max_size = -1;
219 int ignore_errors = 0;
220 int modify_window = 0;
221 +int ignore_case = 0;
222 int blocking_io = -1;
223 int checksum_seed = 0;
225 @@ -784,6 +785,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 @@ -2865,6 +2868,9 @@ void server_options(char **args, int *argc_p)
239 + args[ac++] = "--ignore-case";
241 if (partial_dir && am_sender) {
242 if (partial_dir != tmp_partialdir) {
243 args[ac++] = "--partial-dir";
244 diff --git a/rsync.1.md b/rsync.1.md
247 @@ -528,6 +528,7 @@ has its own detailed description later in this manpage.
248 --secluded-args, -s use the protocol to safely send the args
249 --trust-sender trust the remote sender's file list
250 --copy-as=USER[:GROUP] specify user & optional group for the copy
251 +--ignore-case ignore case when comparing filenames
252 --address=ADDRESS bind address for outgoing socket to daemon
253 --port=PORT specify double-colon alternate port number
254 --sockopts=OPTIONS specify custom TCP options
255 @@ -2583,6 +2584,12 @@ expand it.
257 > sudo rsync -aive lsh -M--copy-as=joe src/ lh:dest/
261 + This option tells rsync to ignore upper-/lower-case differences when
262 + comparing filenames. This can avoid problems when sending files to a
263 + filesystem that ignores these differences.
265 0. `--temp-dir=DIR`, `-T`
267 This option instructs rsync to use DIR as a scratch directory when creating
268 diff --git a/t_stub.c b/t_stub.c
271 @@ -34,6 +34,7 @@ int preserve_perms = 0;
272 int preserve_executability = 0;
273 int omit_link_times = 0;
274 int open_noatime = 0;
275 +int ignore_case = 0;
276 size_t max_alloc = 0; /* max_alloc is needed when combined with util2.o */
279 diff --git a/wildtest.c b/wildtest.c
283 int fnmatch_errors = 0;
286 +int ignore_case = 0;
287 int wildmatch_errors = 0;