Commit | Line | Data |
---|---|---|
992633a5 WD |
1 | This adds the --ignore-case option, which makes rsync compare filenames |
2 | in a case-insensitive manner. | |
8a524ae0 | 3 | |
03019e41 WD |
4 | To use this patch, run these commands for a successful build: |
5 | ||
6 | patch -p1 <patches/ignore-case.diff | |
7 | ./configure (optional if already run) | |
8 | make | |
9 | ||
0f8eae47 WD |
10 | TODO: |
11 | ||
12 | - Make this code handle multibyte character encodings, and honor the | |
13 | --iconv setting when converting case. | |
14 | ||
6100b16e WD |
15 | --- old/exclude.c |
16 | +++ new/exclude.c | |
17 | @@ -32,6 +32,7 @@ extern int io_error; | |
18 | extern int local_server; | |
19 | extern int prune_empty_dirs; | |
20 | extern int ignore_perishable; | |
21 | +extern int ignore_case; | |
22 | extern int delete_mode; | |
23 | extern int delete_excluded; | |
24 | extern int cvs_exclude; | |
790ba11a | 25 | @@ -583,16 +584,17 @@ static int rule_matches(char *name, stru |
6100b16e WD |
26 | if (litmatch_array(pattern, strings, slash_handling)) |
27 | return ret_match; | |
28 | } else if (anchored_match) { | |
29 | - if (strcmp(name, pattern) == 0) | |
30 | + if ((ignore_case ? strcasecmp(name, pattern) | |
31 | + : strcmp(name, pattern)) == 0) | |
32 | return ret_match; | |
33 | } else { | |
34 | int l1 = strlen(name); | |
35 | int l2 = strlen(pattern); | |
36 | - if (l2 <= l1 && | |
37 | - strcmp(name+(l1-l2),pattern) == 0 && | |
38 | - (l1==l2 || name[l1-(l2+1)] == '/')) { | |
39 | + if (l2 <= l1 | |
40 | + && (ignore_case ? strcasecmp(name + (l1-l2), pattern) | |
41 | + : strcmp(name + (l1-l2), pattern)) == 0 | |
42 | + && (l1 == l2 || name[l1 - (l2+1)] == '/')) | |
43 | return ret_match; | |
44 | - } | |
45 | } | |
46 | ||
47 | return !ret_match; | |
9a7eef96 WD |
48 | --- old/flist.c |
49 | +++ new/flist.c | |
f80ebf7e | 50 | @@ -35,6 +35,7 @@ extern int inc_recurse; |
9c657c9f WD |
51 | extern int do_progress; |
52 | extern int always_checksum; | |
53 | extern int module_id; | |
54 | +extern int ignore_case; | |
55 | extern int ignore_errors; | |
56 | extern int numeric_ids; | |
57 | extern int recurse; | |
7bfcb297 | 58 | @@ -2494,6 +2495,7 @@ int f_name_cmp(const struct file_struct |
f80ebf7e WD |
59 | { |
60 | int dif; | |
7bfcb297 WD |
61 | const uchar *c1, *c2; |
62 | + uchar ch1, ch2; | |
f80ebf7e WD |
63 | enum fnc_state state1, state2; |
64 | enum fnc_type type1, type2; | |
65 | enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM; | |
7bfcb297 | 66 | @@ -2604,7 +2606,15 @@ int f_name_cmp(const struct file_struct |
3f053c45 WD |
67 | if (type1 != type2) |
68 | return type1 == t_PATH ? 1 : -1; | |
69 | } | |
70 | - } while ((dif = (int)*c1++ - (int)*c2++) == 0); | |
f80ebf7e WD |
71 | + ch1 = CVAL(c1++, 0); |
72 | + ch2 = CVAL(c2++, 0); | |
9c657c9f | 73 | + if (ignore_case) { |
f80ebf7e WD |
74 | + if (islower(ch1)) |
75 | + ch1 = toupper(ch1); | |
76 | + if (islower(ch2)) | |
77 | + ch2 = toupper(ch2); | |
78 | + } | |
79 | + } while ((dif = ch1 - ch2) == 0); | |
3f053c45 WD |
80 | |
81 | return dif; | |
82 | } | |
9a7eef96 WD |
83 | --- old/lib/wildmatch.c |
84 | +++ new/lib/wildmatch.c | |
992633a5 WD |
85 | @@ -53,6 +53,8 @@ |
86 | #define ISUPPER(c) (ISASCII(c) && isupper(c)) | |
87 | #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c)) | |
88 | ||
89 | +extern int ignore_case; | |
90 | + | |
91 | #ifdef WILD_TEST_ITERATIONS | |
92 | int wildmatch_iteration_count; | |
93 | #endif | |
66e2df0e | 94 | @@ -72,6 +74,8 @@ static int dowild(const uchar *p, const |
ffadcb36 WD |
95 | for ( ; (p_ch = *p) != '\0'; text++, p++) { |
96 | int matched, special; | |
97 | uchar t_ch, prev_ch; | |
98 | + if (ignore_case && ISUPPER(p_ch)) | |
99 | + p_ch = tolower(p_ch); | |
66e2df0e WD |
100 | while ((t_ch = *text) == '\0') { |
101 | if (*a == NULL) { | |
102 | if (p_ch != '*') | |
6100b16e WD |
103 | @@ -237,12 +241,21 @@ static int dowild(const uchar *p, const |
104 | * of "text" and any strings in array "a". */ | |
105 | static int doliteral(const uchar *s, const uchar *text, const uchar*const *a) | |
106 | { | |
107 | + uchar s_ch, t_ch; | |
108 | for ( ; *s != '\0'; text++, s++) { | |
109 | while (*text == '\0') { | |
110 | if ((text = *a++) == NULL) | |
111 | return FALSE; | |
112 | } | |
113 | - if (*text != *s) | |
114 | + s_ch = *s; | |
115 | + t_ch = *text; | |
116 | + if (ignore_case) { | |
117 | + if (ISUPPER(s_ch)) | |
118 | + s_ch = tolower(s_ch); | |
119 | + if (ISUPPER(t_ch)) | |
120 | + t_ch = tolower(t_ch); | |
121 | + } | |
122 | + if (t_ch != s_ch) | |
123 | return FALSE; | |
124 | } | |
125 | ||
126 | @@ -288,10 +301,14 @@ static const uchar *trailing_N_elements( | |
ffadcb36 WD |
127 | int wildmatch(const char *pattern, const char *text) |
128 | { | |
66e2df0e | 129 | static const uchar *nomore[1]; /* A NULL pointer. */ |
ffadcb36 WD |
130 | + int ret; |
131 | #ifdef WILD_TEST_ITERATIONS | |
132 | wildmatch_iteration_count = 0; | |
133 | #endif | |
66e2df0e | 134 | - return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE; |
ffadcb36 | 135 | + force_lower_case = ignore_case; |
66e2df0e | 136 | + ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE; |
ffadcb36 | 137 | + force_lower_case = 0; |
66e2df0e | 138 | + return ret; |
ffadcb36 WD |
139 | } |
140 | ||
141 | /* Match the "pattern" against the forced-to-lower-case "text" string. */ | |
c05e712e WD |
142 | @@ -331,12 +348,14 @@ int wildmatch_array(const char *pattern, |
143 | if (!text) | |
144 | return FALSE; | |
145 | ||
146 | + force_lower_case = ignore_case; | |
147 | + | |
148 | if ((matched = dowild(p, text, a)) != TRUE && where < 0 | |
149 | && matched != ABORT_ALL) { | |
150 | while (1) { | |
151 | if (*text == '\0') { | |
152 | if ((text = (uchar*)*a++) == NULL) | |
153 | - return FALSE; | |
154 | + break; | |
155 | continue; | |
156 | } | |
157 | if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE | |
158 | @@ -344,6 +363,9 @@ int wildmatch_array(const char *pattern, | |
159 | break; | |
160 | } | |
161 | } | |
162 | + | |
163 | + force_lower_case = 0; | |
164 | + | |
165 | return matched == TRUE; | |
166 | } | |
167 | ||
9a7eef96 WD |
168 | --- old/options.c |
169 | +++ new/options.c | |
6cbbe66d | 170 | @@ -114,6 +114,7 @@ OFF_T max_size = 0; |
56208f7b | 171 | OFF_T min_size = 0; |
5f7bb027 WD |
172 | int ignore_errors = 0; |
173 | int modify_window = 0; | |
174 | +int ignore_case = 0; | |
175 | int blocking_io = -1; | |
176 | int checksum_seed = 0; | |
f6c3b300 | 177 | int inplace = 0; |
790ba11a WD |
178 | @@ -396,6 +397,7 @@ void usage(enum logcode F) |
179 | rprintf(F," --exclude-from=FILE read exclude patterns from FILE\n"); | |
180 | rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n"); | |
a7219d20 | 181 | rprintf(F," --include-from=FILE read include patterns from FILE\n"); |
790ba11a | 182 | + rprintf(F," --ignore-case ignore case when comparing filenames\n"); |
a7219d20 | 183 | rprintf(F," --files-from=FILE read list of source-file names from FILE\n"); |
896871f8 | 184 | rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n"); |
790ba11a | 185 | rprintf(F," -s, --protect-args no space-splitting; only wildcard special-chars\n"); |
7bfcb297 | 186 | @@ -593,6 +595,8 @@ static struct poptOption long_options[] |
6cbbe66d WD |
187 | {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 }, |
188 | {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 }, | |
edea1111 | 189 | {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 }, |
2c20ee4e WD |
190 | + {"ignore-case", 0, POPT_ARG_VAL, &ignore_case, 1, 0, 0 }, |
191 | + {"no-ignore-case", 0, POPT_ARG_VAL, &ignore_case, 0, 0, 0 }, | |
6cbbe66d WD |
192 | {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 }, |
193 | {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0}, | |
194 | {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0}, | |
7bfcb297 | 195 | @@ -1907,6 +1911,9 @@ void server_options(char **args, int *ar |
5f7bb027 WD |
196 | args[ac++] = arg; |
197 | } | |
7628f156 | 198 | |
5f7bb027 WD |
199 | + if (ignore_case) |
200 | + args[ac++] = "--ignore-case"; | |
7628f156 | 201 | + |
afbebe13 | 202 | if (partial_dir && am_sender) { |
9a7eef96 | 203 | if (partial_dir != tmp_partialdir) { |
27a7053c | 204 | args[ac++] = "--partial-dir"; |
9a7eef96 WD |
205 | --- old/wildtest.c |
206 | +++ new/wildtest.c | |
6100b16e | 207 | @@ -31,6 +31,7 @@ int fnmatch_errors = 0; |
992633a5 WD |
208 | #endif |
209 | ||
210 | int wildmatch_errors = 0; | |
211 | +int ignore_case = 0; | |
212 | ||
213 | typedef char bool; | |
5f7bb027 | 214 |