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: 035a13f7e483efa47847c5d77a8b0dd30ebd8925
16 diff --git a/exclude.c b/exclude.c
27 @@ -690,16 +691,15 @@ static int rule_matches(const char *fname, filter_rule *ex, int name_flags)
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
51 @@ -35,6 +35,7 @@ extern int inc_recurse;
52 extern int always_checksum;
53 extern int checksum_type;
55 +extern int ignore_case;
56 extern int ignore_errors;
57 extern int numeric_ids;
59 @@ -3083,6 +3084,7 @@ int f_name_cmp(const struct file_struct *f1, const struct file_struct *f2)
64 enum fnc_state state1, state2;
65 enum fnc_type type1, type2;
66 enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM;
67 @@ -3193,7 +3195,15 @@ int f_name_cmp(const struct file_struct *f1, const struct file_struct *f2)
69 return type1 == t_PATH ? 1 : -1;
71 - } while ((dif = (int)*c1++ - (int)*c2++) == 0);
80 + } while ((dif = (int)ch1 - (int)ch2) == 0);
84 diff --git a/ifuncs.h b/ifuncs.h
87 @@ -104,3 +104,38 @@ free_stat_x(stat_x *sx_p)
93 +strEQ(const char *s1, const char *s2)
95 + return strcmp(s1, s2) == 0;
99 +strnEQ(const char *s1, const char *s2, size_t n)
101 + return strncmp(s1, s2, n) == 0;
105 +ic_strEQ(const char *s1, const char *s2)
107 + extern int ignore_case;
109 + return strcasecmp(s1, s2) == 0;
110 + return strcmp(s1, s2) == 0;
114 +ic_strnEQ(const char *s1, const char *s2, size_t n)
116 + extern int ignore_case;
118 + return strncasecmp(s1, s2, n) == 0;
119 + return strncmp(s1, s2, n) == 0;
122 +#define strNE(s1,s2) (!strEQ(s1,s2))
123 +#define strnNE(s1,s2,n) (!strnEQ(s1,s2,n))
124 +#define ic_strNE(s1,s2) (!ic_strEQ(s1,s2))
125 +#define ic_strnNE(s1,s2) (!ic_strnEQ(s1,s2,n))
126 diff --git a/lib/wildmatch.c b/lib/wildmatch.c
127 --- a/lib/wildmatch.c
128 +++ b/lib/wildmatch.c
130 #define ISUPPER(c) (ISASCII(c) && isupper(c))
131 #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
133 +extern int ignore_case;
135 #ifdef WILD_TEST_ITERATIONS
136 int wildmatch_iteration_count;
138 @@ -72,6 +74,8 @@ static int dowild(const uchar *p, const uchar *text, const uchar*const *a)
139 for ( ; (p_ch = *p) != '\0'; text++, p++) {
140 int matched, special;
142 + if (ignore_case && ISUPPER(p_ch))
143 + p_ch = tolower(p_ch);
144 while ((t_ch = *text) == '\0') {
147 @@ -237,12 +241,21 @@ static int dowild(const uchar *p, const uchar *text, const uchar*const *a)
148 * of "text" and any strings in array "a". */
149 static int doliteral(const uchar *s, const uchar *text, const uchar*const *a)
152 for ( ; *s != '\0'; text++, s++) {
153 while (*text == '\0') {
154 if ((text = *a++) == NULL)
162 + s_ch = tolower(s_ch);
164 + t_ch = tolower(t_ch);
170 @@ -288,10 +301,14 @@ static const uchar *trailing_N_elements(const uchar*const **a_ptr, int count)
171 int wildmatch(const char *pattern, const char *text)
173 static const uchar *nomore[1]; /* A NULL pointer. */
175 #ifdef WILD_TEST_ITERATIONS
176 wildmatch_iteration_count = 0;
178 - return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
179 + force_lower_case = ignore_case;
180 + ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
181 + force_lower_case = 0;
185 /* Match the "pattern" against the forced-to-lower-case "text" string. */
186 @@ -331,12 +348,14 @@ int wildmatch_array(const char *pattern, const char*const *texts, int where)
190 + force_lower_case = ignore_case;
192 if ((matched = dowild(p, text, a)) != TRUE && where < 0
193 && matched != ABORT_ALL) {
196 if ((text = (uchar*)*a++) == NULL)
201 if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE
202 @@ -344,6 +363,9 @@ int wildmatch_array(const char *pattern, const char*const *texts, int where)
207 + force_lower_case = 0;
209 return matched == TRUE;
212 diff --git a/options.c b/options.c
215 @@ -124,6 +124,7 @@ OFF_T max_size = -1;
217 int ignore_errors = 0;
218 int modify_window = 0;
219 +int ignore_case = 0;
220 int blocking_io = -1;
221 int checksum_seed = 0;
223 @@ -786,6 +787,7 @@ void usage(enum logcode F)
224 rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
225 rprintf(F," -s, --protect-args no space-splitting; only wildcard special-chars\n");
226 rprintf(F," --copy-as=USER[:GROUP] specify user & optional group for the copy\n");
227 + rprintf(F," --ignore-case ignore case when comparing filenames\n");
228 rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
229 rprintf(F," --port=PORT specify double-colon alternate port number\n");
230 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
231 @@ -1018,6 +1020,8 @@ static struct poptOption long_options[] = {
232 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
233 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
234 {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
235 + {"ignore-case", 0, POPT_ARG_VAL, &ignore_case, 1, 0, 0 },
236 + {"no-ignore-case", 0, POPT_ARG_VAL, &ignore_case, 0, 0, 0 },
237 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
238 {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0},
239 {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0},
240 @@ -2743,6 +2747,9 @@ void server_options(char **args, int *argc_p)
245 + args[ac++] = "--ignore-case";
247 if (partial_dir && am_sender) {
248 if (partial_dir != tmp_partialdir) {
249 args[ac++] = "--partial-dir";
250 diff --git a/rsync.yo b/rsync.yo
253 @@ -444,6 +444,7 @@ to the detailed description below for a complete description. verb(
254 -0, --from0 all *from/filter files are delimited by 0s
255 -s, --protect-args no space-splitting; wildcard chars only
256 --copy-as=USER[:GROUP] specify user & optional group for the copy
257 + --ignore-case ignore case when comparing filenames
258 --address=ADDRESS bind address for outgoing socket to daemon
259 --port=PORT specify double-colon alternate port number
260 --sockopts=OPTIONS specify custom TCP options
261 @@ -1898,6 +1899,10 @@ available to that user, and makes it impossible for the joe user to do a timed
262 exploit of the path to induce a change to a file that the joe use has no
263 permissions to change.
265 +dit(bf(--ignore-case)) This option tells rsync to ignore upper-/lower-case
266 +differences when comparing filenames. This can avoid problems when sending
267 +files to a filesystem that ignores these differences.
269 dit(bf(-T, --temp-dir=DIR)) This option instructs rsync to use DIR as a
270 scratch directory when creating temporary copies of the files transferred
271 on the receiving side. The default behavior is to create each temporary
272 diff --git a/wildtest.c b/wildtest.c
276 int fnmatch_errors = 0;
279 +int ignore_case = 0;
280 int wildmatch_errors = 0;