PATCH: option to ignore case in filenames

John R. LoVerso john at loverso.southborough.ma.us
Wed Oct 1 08:36:54 EST 2003


I have two DOS filesystems mounted on Linux as "vfat" which I want to rsync.
(They are on flash cards, so that they are also small).  rsync gets tricked
because the filesystem treats names differing in only case as the same.
Thus, when it tries to sync "FOO123" with "foO123", it copies over the
"new" file, and then renames it over the old one (which it couldn't delete
before the transfer, because the names didn't match!)

The effect is that the files will _always_ be rsync'd every time I run it.

I'm using the included patch for 2.5.6 to add an "--ignorecase" switch.
It is passed from client to server.  It's only appropriate when used
on a FAT filesystem.

John


===== flist.c 1.1 vs edited =====
--- 1.1/rsync/flist.c   Thu Feb 13 11:51:39 2003
+++ edited/flist.c      Tue Sep 30 18:16:35 2003
@@ -1137,6 +1137,13 @@
  **/
 int file_compare(struct file_struct **f1, struct file_struct **f2)
 {
+       extern int ignore_case;
+       int (*cf)(const char *, const char *);
+       if (ignore_case)
+               cf = strcasecmp;
+       else
+               cf = u_strcmp;
+
        if (!(*f1)->basename && !(*f2)->basename)
                return 0;
        if (!(*f1)->basename)
@@ -1144,8 +1151,8 @@
        if (!(*f2)->basename)
                return 1;
        if ((*f1)->dirname == (*f2)->dirname)
-               return u_strcmp((*f1)->basename, (*f2)->basename);
-       return u_strcmp(f_name(*f1), f_name(*f2));
+               return cf((*f1)->basename, (*f2)->basename);
+       return cf(f_name(*f1), f_name(*f2));
 }
 
 
===== options.c 1.1 vs edited =====
--- 1.1/rsync/options.c Thu Feb 13 11:51:39 2003
+++ edited/options.c    Tue Sep 30 18:16:47 2003
@@ -83,6 +83,7 @@
 int ignore_errors=0;
 int modify_window=0;
 int blocking_io=-1;
+int ignore_case=0;
 
 
 /** Network address family. **/
@@ -207,6 +208,7 @@
   rprintf(F," -v, --verbose               increase verbosity\n");
   rprintf(F," -q, --quiet                 decrease verbosity\n");
   rprintf(F," -c, --checksum              always checksum\n");
+  rprintf(F,"     --ignorecase            STARENT: ignore case\n");
   rprintf(F," -a, --archive               archive mode, equivalent to -rlptgoD\n");
   rprintf(F," -r, --recursive             recurse into directories\n");
   rprintf(F," -R, --relative              use relative path names\n");
@@ -332,6 +334,7 @@
   {"devices",         'D', POPT_ARG_NONE,   &preserve_devices , 0, 0, 0 },
   {"times",           't', POPT_ARG_NONE,   &preserve_times , 0, 0, 0 },
   {"checksum",        'c', POPT_ARG_NONE,   &always_checksum , 0, 0, 0 },
+  {"ignorecase",       0,  POPT_ARG_NONE,   &ignore_case, 0, 0, 0 },
   {"verbose",         'v', POPT_ARG_NONE,   0,               'v', 0, 0 },
   {"quiet",           'q', POPT_ARG_NONE,   0,               'q', 0, 0 },
   {"archive",         'a', POPT_ARG_NONE,   0,               'a', 0, 0 }, 
@@ -819,6 +822,9 @@
 
        if (opt_ignore_existing && am_sender) 
                args[ac++] = "--ignore-existing";
+
+       if (ignore_case)
+               args[ac++] = "--ignorecase";
 
        if (tmpdir) {
                args[ac++] = "--temp-dir";




More information about the rsync mailing list