Skip to content

Instantly share code, notes, and snippets.

@iracooke
Created July 19, 2014 01:59
Show Gist options
  • Save iracooke/9db6d12c037b6bcb04e9 to your computer and use it in GitHub Desktop.
Save iracooke/9db6d12c037b6bcb04e9 to your computer and use it in GitHub Desktop.
rsync42-better-ignore-case.diff
Common subdirectories: ../../rsync-42/rsync/doc and ./doc
diff -u ../../rsync-42/rsync/exclude.c ./exclude.c
--- ../../rsync-42/rsync/exclude.c 2007-11-07 06:31:30.000000000 +1100
+++ ./exclude.c 2014-02-09 17:35:43.000000000 +1100
@@ -38,6 +38,7 @@
extern int sanitize_paths;
extern int protocol_version;
extern int module_id;
+extern int ignore_case;
extern char curr_dir[];
extern unsigned int curr_dir_len;
@@ -492,6 +493,15 @@
free(pop);
}
+static inline int
+ic_strEQ(const char *s1, const char *s2)
+{
+ extern int ignore_case;
+ if (ignore_case)
+ return strcasecmp(s1, s2) == 0;
+ return strcmp(s1, s2) == 0;
+}
+
static int rule_matches(char *name, struct filter_struct *ex, int name_is_dir)
{
int slash_handling, str_cnt = 0, anchored_match = 0;
@@ -556,16 +566,15 @@
if (litmatch_array(pattern, strings, slash_handling))
return ret_match;
} else if (anchored_match) {
- if (strcmp(name, pattern) == 0)
+ if (ic_strEQ(name, pattern))
return ret_match;
} else {
int l1 = strlen(name);
int l2 = strlen(pattern);
- if (l2 <= l1 &&
- strcmp(name+(l1-l2),pattern) == 0 &&
- (l1==l2 || name[l1-(l2+1)] == '/')) {
+ if (l2 <= l1
+ && ic_strEQ(name + (l1-l2), pattern)
+ && (l1 == l2 || name[l1 - (l2+1)] == '/'))
return ret_match;
- }
}
return !ret_match;
diff -u ../../rsync-42/rsync/flist.c ./flist.c
--- ../../rsync-42/rsync/flist.c 2008-08-28 08:03:28.000000000 +1000
+++ ./flist.c 2014-02-09 07:21:16.000000000 +1100
@@ -35,6 +35,7 @@
extern int do_progress;
extern int always_checksum;
extern int module_id;
+extern int ignore_case;
extern int ignore_errors;
extern int numeric_ids;
extern int recurse;
@@ -1866,7 +1867,7 @@
if (type1 != type2)
return type1 == t_PATH ? 1 : -1;
- do {
+ while (1) {
if (!*c1) {
switch (state1) {
case s_DIR:
@@ -1929,7 +1930,16 @@
if (type1 != type2)
return type1 == t_PATH ? 1 : -1;
}
- } while ((dif = (int)*c1++ - (int)*c2++) == 0);
+ if (ignore_case) {
+ uchar ch1, ch2;
+ ch1 = islower(*c1) ? toupper(*c1) : *c1;
+ ch2 = islower(*c2) ? toupper(*c2) : *c2;
+ c1++, c2++;
+ if ((dif = (int)ch1 - (int)ch2) != 0)
+ break;
+ } else if ((dif = (int)*c1++ - (int)*c2++) != 0)
+ break;
+ }
return dif;
}
Only in .: flist.c.orig
Common subdirectories: ../../rsync-42/rsync/lib and ./lib
diff -u ../../rsync-42/rsync/options.c ./options.c
--- ../../rsync-42/rsync/options.c 2010-02-24 11:42:30.000000000 +1100
+++ ./options.c 2014-02-09 07:21:16.000000000 +1100
@@ -111,6 +111,7 @@
OFF_T min_size = 0;
int ignore_errors = 0;
int modify_window = 0;
+int ignore_case = 0;
int blocking_io = -1;
int checksum_seed = 0;
int inplace = 0;
@@ -365,6 +366,7 @@
rprintf(F," --include-from=FILE read include patterns from FILE\n");
rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
+ rprintf(F," --ignore-case ignore case when comparing filenames\n");
rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
rprintf(F," --port=PORT specify double-colon alternate port number\n");
rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
@@ -533,6 +535,7 @@
{"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
{"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
{"from0", '0', POPT_ARG_NONE, &eol_nulls, 0, 0, 0},
+ {"ignore-case", 0, POPT_ARG_NONE, &ignore_case, 0, 0, 0 },
{"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids, 0, 0, 0 },
{"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 },
{"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
@@ -1711,6 +1714,9 @@
args[ac++] = arg;
}
+ if (ignore_case)
+ args[ac++] = "--ignore-case";
+
if (partial_dir && am_sender) {
if (partial_dir != tmp_partialdir) {
args[ac++] = "--partial-dir";
Only in .: options.c.orig
Common subdirectories: ../../rsync-42/rsync/packaging and ./packaging
Common subdirectories: ../../rsync-42/rsync/patches and ./patches
Common subdirectories: ../../rsync-42/rsync/popt and ./popt
Common subdirectories: ../../rsync-42/rsync/support and ./support
Common subdirectories: ../../rsync-42/rsync/testhelp and ./testhelp
Common subdirectories: ../../rsync-42/rsync/testsuite and ./testsuite
diff -u ../../rsync-42/rsync/wildtest.c ./wildtest.c
--- ../../rsync-42/rsync/wildtest.c 2007-11-07 06:31:30.000000000 +1100
+++ ./wildtest.c 2014-02-09 07:21:16.000000000 +1100
@@ -32,6 +32,7 @@
#endif
int wildmatch_errors = 0;
+int ignore_case = 0;
typedef char bool;
Common subdirectories: ../../rsync-42/rsync/zlib and ./zlib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment