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; | |
25 | @@ -580,16 +581,17 @@ static int rule_matches(char *name, stru | |
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; | |
0f8eae47 | 58 | @@ -2454,7 +2455,7 @@ enum fnc_type { t_PATH, t_ITEM }; |
f80ebf7e WD |
59 | int f_name_cmp(struct file_struct *f1, struct file_struct *f2) |
60 | { | |
61 | int dif; | |
62 | - const uchar *c1, *c2; | |
63 | + const uchar *c1, *c2, ch1, ch2; | |
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; | |
0f8eae47 | 67 | @@ -2564,7 +2565,15 @@ int f_name_cmp(struct file_struct *f1, s |
3f053c45 WD |
68 | if (type1 != type2) |
69 | return type1 == t_PATH ? 1 : -1; | |
70 | } | |
71 | - } while ((dif = (int)*c1++ - (int)*c2++) == 0); | |
f80ebf7e WD |
72 | + ch1 = CVAL(c1++, 0); |
73 | + ch2 = CVAL(c2++, 0); | |
9c657c9f | 74 | + if (ignore_case) { |
f80ebf7e WD |
75 | + if (islower(ch1)) |
76 | + ch1 = toupper(ch1); | |
77 | + if (islower(ch2)) | |
78 | + ch2 = toupper(ch2); | |
79 | + } | |
80 | + } while ((dif = ch1 - ch2) == 0); | |
3f053c45 WD |
81 | |
82 | return dif; | |
83 | } | |
9a7eef96 WD |
84 | --- old/lib/wildmatch.c |
85 | +++ new/lib/wildmatch.c | |
992633a5 WD |
86 | @@ -53,6 +53,8 @@ |
87 | #define ISUPPER(c) (ISASCII(c) && isupper(c)) | |
88 | #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c)) | |
89 | ||
90 | +extern int ignore_case; | |
91 | + | |
92 | #ifdef WILD_TEST_ITERATIONS | |
93 | int wildmatch_iteration_count; | |
94 | #endif | |
66e2df0e | 95 | @@ -72,6 +74,8 @@ static int dowild(const uchar *p, const |
ffadcb36 WD |
96 | for ( ; (p_ch = *p) != '\0'; text++, p++) { |
97 | int matched, special; | |
98 | uchar t_ch, prev_ch; | |
99 | + if (ignore_case && ISUPPER(p_ch)) | |
100 | + p_ch = tolower(p_ch); | |
66e2df0e WD |
101 | while ((t_ch = *text) == '\0') { |
102 | if (*a == NULL) { | |
103 | if (p_ch != '*') | |
6100b16e WD |
104 | @@ -237,12 +241,21 @@ static int dowild(const uchar *p, const |
105 | * of "text" and any strings in array "a". */ | |
106 | static int doliteral(const uchar *s, const uchar *text, const uchar*const *a) | |
107 | { | |
108 | + uchar s_ch, t_ch; | |
109 | for ( ; *s != '\0'; text++, s++) { | |
110 | while (*text == '\0') { | |
111 | if ((text = *a++) == NULL) | |
112 | return FALSE; | |
113 | } | |
114 | - if (*text != *s) | |
115 | + s_ch = *s; | |
116 | + t_ch = *text; | |
117 | + if (ignore_case) { | |
118 | + if (ISUPPER(s_ch)) | |
119 | + s_ch = tolower(s_ch); | |
120 | + if (ISUPPER(t_ch)) | |
121 | + t_ch = tolower(t_ch); | |
122 | + } | |
123 | + if (t_ch != s_ch) | |
124 | return FALSE; | |
125 | } | |
126 | ||
127 | @@ -288,10 +301,14 @@ static const uchar *trailing_N_elements( | |
ffadcb36 WD |
128 | int wildmatch(const char *pattern, const char *text) |
129 | { | |
66e2df0e | 130 | static const uchar *nomore[1]; /* A NULL pointer. */ |
ffadcb36 WD |
131 | + int ret; |
132 | #ifdef WILD_TEST_ITERATIONS | |
133 | wildmatch_iteration_count = 0; | |
134 | #endif | |
66e2df0e | 135 | - return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE; |
ffadcb36 | 136 | + force_lower_case = ignore_case; |
66e2df0e | 137 | + ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE; |
ffadcb36 | 138 | + force_lower_case = 0; |
66e2df0e | 139 | + return ret; |
ffadcb36 WD |
140 | } |
141 | ||
142 | /* Match the "pattern" against the forced-to-lower-case "text" string. */ | |
c05e712e WD |
143 | @@ -331,12 +348,14 @@ int wildmatch_array(const char *pattern, |
144 | if (!text) | |
145 | return FALSE; | |
146 | ||
147 | + force_lower_case = ignore_case; | |
148 | + | |
149 | if ((matched = dowild(p, text, a)) != TRUE && where < 0 | |
150 | && matched != ABORT_ALL) { | |
151 | while (1) { | |
152 | if (*text == '\0') { | |
153 | if ((text = (uchar*)*a++) == NULL) | |
154 | - return FALSE; | |
155 | + break; | |
156 | continue; | |
157 | } | |
158 | if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE | |
159 | @@ -344,6 +363,9 @@ int wildmatch_array(const char *pattern, | |
160 | break; | |
161 | } | |
162 | } | |
163 | + | |
164 | + force_lower_case = 0; | |
165 | + | |
166 | return matched == TRUE; | |
167 | } | |
168 | ||
9a7eef96 WD |
169 | --- old/options.c |
170 | +++ new/options.c | |
6cbbe66d | 171 | @@ -114,6 +114,7 @@ OFF_T max_size = 0; |
56208f7b | 172 | OFF_T min_size = 0; |
5f7bb027 WD |
173 | int ignore_errors = 0; |
174 | int modify_window = 0; | |
175 | +int ignore_case = 0; | |
176 | int blocking_io = -1; | |
177 | int checksum_seed = 0; | |
f6c3b300 | 178 | int inplace = 0; |
6cbbe66d | 179 | @@ -389,6 +390,7 @@ void usage(enum logcode F) |
a7219d20 WD |
180 | rprintf(F," --include-from=FILE read include patterns from FILE\n"); |
181 | rprintf(F," --files-from=FILE read list of source-file names from FILE\n"); | |
896871f8 | 182 | rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n"); |
5f7bb027 | 183 | + rprintf(F," --ignore-case ignore case when comparing filenames\n"); |
2b06a19d | 184 | rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n"); |
37da98ae | 185 | rprintf(F," --port=PORT specify double-colon alternate port number\n"); |
9a7eef96 | 186 | rprintf(F," --sockopts=OPTIONS specify custom TCP options\n"); |
6cbbe66d WD |
187 | @@ -577,6 +579,8 @@ static struct poptOption long_options[] |
188 | {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 }, | |
189 | {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 }, | |
edea1111 | 190 | {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 }, |
2c20ee4e WD |
191 | + {"ignore-case", 0, POPT_ARG_VAL, &ignore_case, 1, 0, 0 }, |
192 | + {"no-ignore-case", 0, POPT_ARG_VAL, &ignore_case, 0, 0, 0 }, | |
6cbbe66d WD |
193 | {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 }, |
194 | {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0}, | |
195 | {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0}, | |
196 | @@ -1850,6 +1854,9 @@ void server_options(char **args,int *arg | |
5f7bb027 WD |
197 | args[ac++] = arg; |
198 | } | |
7628f156 | 199 | |
5f7bb027 WD |
200 | + if (ignore_case) |
201 | + args[ac++] = "--ignore-case"; | |
7628f156 | 202 | + |
afbebe13 | 203 | if (partial_dir && am_sender) { |
9a7eef96 | 204 | if (partial_dir != tmp_partialdir) { |
27a7053c | 205 | args[ac++] = "--partial-dir"; |
9a7eef96 WD |
206 | --- old/wildtest.c |
207 | +++ new/wildtest.c | |
6100b16e | 208 | @@ -31,6 +31,7 @@ int fnmatch_errors = 0; |
992633a5 WD |
209 | #endif |
210 | ||
211 | int wildmatch_errors = 0; | |
212 | +int ignore_case = 0; | |
213 | ||
214 | typedef char bool; | |
5f7bb027 | 215 |