+/* Try to find a filename in the same dir as "fname" with a similar name. */
+static int find_fuzzy(struct file_struct *file, struct file_list *dirlist)
+{
+ int fname_len, fname_suf_len;
+ const char *fname_suf, *fname = file->basename;
+ uint32 lowest_dist = 0x7FFFFFFF;
+ int j, lowest_j = -1;
+
+ fname_len = strlen(fname);
+ fname_suf = find_filename_suffix(fname, fname_len, &fname_suf_len);
+
+ for (j = 0; j < dirlist->count; j++) {
+ struct file_struct *fp = dirlist->files[j];
+ const char *suf, *name;
+ int len, suf_len;
+ uint32 dist;
+
+ if (!S_ISREG(fp->mode) || !fp->length
+ || fp->flags & FLAG_NO_FUZZY)
+ continue;
+
+ name = fp->basename;
+
+ if (fp->length == file->length
+ && fp->modtime == file->modtime) {
+ if (verbose > 4) {
+ rprintf(FINFO,
+ "fuzzy size/modtime match for %s\n",
+ name);
+ }
+ return j;
+ }
+
+ len = strlen(name);
+ suf = find_filename_suffix(name, len, &suf_len);
+
+ dist = fuzzy_distance(name, len, fname, fname_len);
+ /* Add some extra weight to how well the suffixes match. */
+ dist += fuzzy_distance(suf, suf_len, fname_suf, fname_suf_len)
+ * 10;
+ if (verbose > 4) {
+ rprintf(FINFO, "fuzzy distance for %s = %d.%05d\n",
+ name, (int)(dist>>16), (int)(dist&0xFFFF));
+ }
+ if (dist <= lowest_dist) {
+ lowest_dist = dist;
+ lowest_j = j;
+ }
+ }
+
+ return lowest_j;
+}
+
+
+/* Acts on flist->file's ndx'th item, whose name is fname. If a directory,
+ * make sure it exists, and has the right permissions/timestamp info. For
+ * all other non-regular files (symlinks, etc.) we create them here. For
+ * regular files that have changed, we try to find a basis file and then
+ * start sending checksums.
+ *
+ * Note that f_out is set to -1 when doing final directory-permission and
+ * modification-time repair. */
+static void recv_generator(char *fname, struct file_list *flist,
+ struct file_struct *file, int ndx,
+ int itemizing, int maybe_PERMS_REPORT,
+ enum logcode code, int allowed_lull,
+ int f_out, int f_out_name)
+{
+ static int missing_below = -1, excluded_below = -1;
+ static char *fuzzy_dirname = NULL;
+ static struct file_list *fuzzy_dirlist = NULL;
+ struct file_struct *fuzzy_file = NULL;
+ int fd = -1, f_copy = -1;
+ STRUCT_STAT st, partial_st;
+ struct file_struct *back_file = NULL;
+ int statret, stat_errno;
+ char *fnamecmp, *partialptr, *backupptr = NULL;