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 | ||
6100b16e WD |
10 | --- old/exclude.c |
11 | +++ new/exclude.c | |
12 | @@ -32,6 +32,7 @@ extern int io_error; | |
13 | extern int local_server; | |
14 | extern int prune_empty_dirs; | |
15 | extern int ignore_perishable; | |
16 | +extern int ignore_case; | |
17 | extern int delete_mode; | |
18 | extern int delete_excluded; | |
19 | extern int cvs_exclude; | |
20 | @@ -580,16 +581,17 @@ static int rule_matches(char *name, stru | |
21 | if (litmatch_array(pattern, strings, slash_handling)) | |
22 | return ret_match; | |
23 | } else if (anchored_match) { | |
24 | - if (strcmp(name, pattern) == 0) | |
25 | + if ((ignore_case ? strcasecmp(name, pattern) | |
26 | + : strcmp(name, pattern)) == 0) | |
27 | return ret_match; | |
28 | } else { | |
29 | int l1 = strlen(name); | |
30 | int l2 = strlen(pattern); | |
31 | - if (l2 <= l1 && | |
32 | - strcmp(name+(l1-l2),pattern) == 0 && | |
33 | - (l1==l2 || name[l1-(l2+1)] == '/')) { | |
34 | + if (l2 <= l1 | |
35 | + && (ignore_case ? strcasecmp(name + (l1-l2), pattern) | |
36 | + : strcmp(name + (l1-l2), pattern)) == 0 | |
37 | + && (l1 == l2 || name[l1 - (l2+1)] == '/')) | |
38 | return ret_match; | |
39 | - } | |
40 | } | |
41 | ||
42 | return !ret_match; | |
9a7eef96 WD |
43 | --- old/flist.c |
44 | +++ new/flist.c | |
f80ebf7e | 45 | @@ -35,6 +35,7 @@ extern int inc_recurse; |
9c657c9f WD |
46 | extern int do_progress; |
47 | extern int always_checksum; | |
48 | extern int module_id; | |
49 | +extern int ignore_case; | |
50 | extern int ignore_errors; | |
51 | extern int numeric_ids; | |
52 | extern int recurse; | |
f80ebf7e WD |
53 | @@ -2390,7 +2391,7 @@ enum fnc_type { t_PATH, t_ITEM }; |
54 | int f_name_cmp(struct file_struct *f1, struct file_struct *f2) | |
55 | { | |
56 | int dif; | |
57 | - const uchar *c1, *c2; | |
58 | + const uchar *c1, *c2, ch1, ch2; | |
59 | enum fnc_state state1, state2; | |
60 | enum fnc_type type1, type2; | |
61 | enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM; | |
62 | @@ -2500,7 +2501,15 @@ int f_name_cmp(struct file_struct *f1, s | |
3f053c45 WD |
63 | if (type1 != type2) |
64 | return type1 == t_PATH ? 1 : -1; | |
65 | } | |
66 | - } while ((dif = (int)*c1++ - (int)*c2++) == 0); | |
f80ebf7e WD |
67 | + ch1 = CVAL(c1++, 0); |
68 | + ch2 = CVAL(c2++, 0); | |
9c657c9f | 69 | + if (ignore_case) { |
f80ebf7e WD |
70 | + if (islower(ch1)) |
71 | + ch1 = toupper(ch1); | |
72 | + if (islower(ch2)) | |
73 | + ch2 = toupper(ch2); | |
74 | + } | |
75 | + } while ((dif = ch1 - ch2) == 0); | |
3f053c45 WD |
76 | |
77 | return dif; | |
78 | } | |
9a7eef96 WD |
79 | --- old/lib/wildmatch.c |
80 | +++ new/lib/wildmatch.c | |
992633a5 WD |
81 | @@ -53,6 +53,8 @@ |
82 | #define ISUPPER(c) (ISASCII(c) && isupper(c)) | |
83 | #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c)) | |
84 | ||
85 | +extern int ignore_case; | |
86 | + | |
87 | #ifdef WILD_TEST_ITERATIONS | |
88 | int wildmatch_iteration_count; | |
89 | #endif | |
66e2df0e | 90 | @@ -72,6 +74,8 @@ static int dowild(const uchar *p, const |
ffadcb36 WD |
91 | for ( ; (p_ch = *p) != '\0'; text++, p++) { |
92 | int matched, special; | |
93 | uchar t_ch, prev_ch; | |
94 | + if (ignore_case && ISUPPER(p_ch)) | |
95 | + p_ch = tolower(p_ch); | |
66e2df0e WD |
96 | while ((t_ch = *text) == '\0') { |
97 | if (*a == NULL) { | |
98 | if (p_ch != '*') | |
6100b16e WD |
99 | @@ -237,12 +241,21 @@ static int dowild(const uchar *p, const |
100 | * of "text" and any strings in array "a". */ | |
101 | static int doliteral(const uchar *s, const uchar *text, const uchar*const *a) | |
102 | { | |
103 | + uchar s_ch, t_ch; | |
104 | for ( ; *s != '\0'; text++, s++) { | |
105 | while (*text == '\0') { | |
106 | if ((text = *a++) == NULL) | |
107 | return FALSE; | |
108 | } | |
109 | - if (*text != *s) | |
110 | + s_ch = *s; | |
111 | + t_ch = *text; | |
112 | + if (ignore_case) { | |
113 | + if (ISUPPER(s_ch)) | |
114 | + s_ch = tolower(s_ch); | |
115 | + if (ISUPPER(t_ch)) | |
116 | + t_ch = tolower(t_ch); | |
117 | + } | |
118 | + if (t_ch != s_ch) | |
119 | return FALSE; | |
120 | } | |
121 | ||
122 | @@ -288,10 +301,14 @@ static const uchar *trailing_N_elements( | |
ffadcb36 WD |
123 | int wildmatch(const char *pattern, const char *text) |
124 | { | |
66e2df0e | 125 | static const uchar *nomore[1]; /* A NULL pointer. */ |
ffadcb36 WD |
126 | + int ret; |
127 | #ifdef WILD_TEST_ITERATIONS | |
128 | wildmatch_iteration_count = 0; | |
129 | #endif | |
66e2df0e | 130 | - return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE; |
ffadcb36 | 131 | + force_lower_case = ignore_case; |
66e2df0e | 132 | + ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE; |
ffadcb36 | 133 | + force_lower_case = 0; |
66e2df0e | 134 | + return ret; |
ffadcb36 WD |
135 | } |
136 | ||
137 | /* Match the "pattern" against the forced-to-lower-case "text" string. */ | |
c05e712e WD |
138 | @@ -331,12 +348,14 @@ int wildmatch_array(const char *pattern, |
139 | if (!text) | |
140 | return FALSE; | |
141 | ||
142 | + force_lower_case = ignore_case; | |
143 | + | |
144 | if ((matched = dowild(p, text, a)) != TRUE && where < 0 | |
145 | && matched != ABORT_ALL) { | |
146 | while (1) { | |
147 | if (*text == '\0') { | |
148 | if ((text = (uchar*)*a++) == NULL) | |
149 | - return FALSE; | |
150 | + break; | |
151 | continue; | |
152 | } | |
153 | if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE | |
154 | @@ -344,6 +363,9 @@ int wildmatch_array(const char *pattern, | |
155 | break; | |
156 | } | |
157 | } | |
158 | + | |
159 | + force_lower_case = 0; | |
160 | + | |
161 | return matched == TRUE; | |
162 | } | |
163 | ||
9a7eef96 WD |
164 | --- old/options.c |
165 | +++ new/options.c | |
f80ebf7e | 166 | @@ -113,6 +113,7 @@ OFF_T max_size = 0; |
56208f7b | 167 | OFF_T min_size = 0; |
5f7bb027 WD |
168 | int ignore_errors = 0; |
169 | int modify_window = 0; | |
170 | +int ignore_case = 0; | |
171 | int blocking_io = -1; | |
172 | int checksum_seed = 0; | |
f6c3b300 | 173 | int inplace = 0; |
f80ebf7e | 174 | @@ -388,6 +389,7 @@ void usage(enum logcode F) |
a7219d20 WD |
175 | rprintf(F," --include-from=FILE read include patterns from FILE\n"); |
176 | rprintf(F," --files-from=FILE read list of source-file names from FILE\n"); | |
896871f8 | 177 | rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n"); |
5f7bb027 | 178 | + rprintf(F," --ignore-case ignore case when comparing filenames\n"); |
2b06a19d | 179 | rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n"); |
37da98ae | 180 | rprintf(F," --port=PORT specify double-colon alternate port number\n"); |
9a7eef96 | 181 | rprintf(F," --sockopts=OPTIONS specify custom TCP options\n"); |
2c20ee4e | 182 | @@ -567,6 +569,8 @@ static struct poptOption long_options[] |
edea1111 WD |
183 | {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 }, |
184 | {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 }, | |
185 | {"from0", '0', POPT_ARG_NONE, &eol_nulls, 0, 0, 0}, | |
2c20ee4e WD |
186 | + {"ignore-case", 0, POPT_ARG_VAL, &ignore_case, 1, 0, 0 }, |
187 | + {"no-ignore-case", 0, POPT_ARG_VAL, &ignore_case, 0, 0, 0 }, | |
edea1111 WD |
188 | {"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids, 0, 0, 0 }, |
189 | {"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 }, | |
190 | {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 }, | |
2c20ee4e | 191 | @@ -1834,6 +1838,9 @@ void server_options(char **args,int *arg |
5f7bb027 WD |
192 | args[ac++] = arg; |
193 | } | |
7628f156 | 194 | |
5f7bb027 WD |
195 | + if (ignore_case) |
196 | + args[ac++] = "--ignore-case"; | |
7628f156 | 197 | + |
afbebe13 | 198 | if (partial_dir && am_sender) { |
9a7eef96 | 199 | if (partial_dir != tmp_partialdir) { |
27a7053c | 200 | args[ac++] = "--partial-dir"; |
9a7eef96 WD |
201 | --- old/wildtest.c |
202 | +++ new/wildtest.c | |
6100b16e | 203 | @@ -31,6 +31,7 @@ int fnmatch_errors = 0; |
992633a5 WD |
204 | #endif |
205 | ||
206 | int wildmatch_errors = 0; | |
207 | +int ignore_case = 0; | |
208 | ||
209 | typedef char bool; | |
5f7bb027 | 210 |