+--- old/compat.c
++++ new/compat.c
+@@ -41,6 +41,7 @@ extern int checksum_seed;
+ extern int basis_dir_cnt;
+ extern int prune_empty_dirs;
+ extern int protocol_version;
++extern int detect_renamed;
+ extern int protect_args;
+ extern int preserve_uid;
+ extern int preserve_gid;
+@@ -218,7 +219,7 @@ void setup_protocol(int f_out,int f_in)
+ } else if (protocol_version >= 30) {
+ if (recurse && allow_inc_recurse
+ && !delete_before && !delete_after && !delay_updates
+- && !use_qsort && !prune_empty_dirs)
++ && !use_qsort && !prune_empty_dirs && !detect_renamed)
+ inc_recurse = 1;
+ need_messages_from_generator = 1;
+ }
-@@ -68,6 +69,8 @@ int checksum_len;
- dev_t filesystem_dev; /* used to implement -x */
- unsigned int file_struct_len;
+@@ -113,6 +114,8 @@ static int64 tmp_dev, tmp_ino;
+ #endif
+ static char tmp_sum[MAX_DIGEST_LEN];
- static char empty_sum[MD4_SUM_LENGTH];
- static int flist_count_offset;
-
-@@ -250,6 +253,44 @@ static mode_t from_wire_mode(int mode)
- return mode;
+ static char empty_sum[MAX_DIGEST_LEN];
+ static int flist_count_offset; /* for --delete --progress */
+ static int dir_count = 0;
+@@ -252,6 +255,45 @@ static int is_excluded(char *fname, int
+ return 0;
}
+static int fattr_compare(struct file_struct **file1, struct file_struct **file2)
+{
+ struct file_struct *f1 = *file1;
+ struct file_struct *f2 = *file2;
}
+static int fattr_compare(struct file_struct **file1, struct file_struct **file2)
+{
+ struct file_struct *f1 = *file1;
+ struct file_struct *f2 = *file2;
-@@ -1379,6 +1420,25 @@ struct file_list *recv_file_list(int f)
-
- clean_flist(flist, relative_paths, 1);
+@@ -2021,6 +2063,25 @@ struct file_list *send_file_list(int f,
+ if (verbose > 2)
+ rprintf(FINFO, "send_file_list done\n");
+ memcpy(the_fattr_list.files, flist->files,
+ j * sizeof (struct file_struct *));
+ qsort(the_fattr_list.files, j,
+ memcpy(the_fattr_list.files, flist->files,
+ j * sizeof (struct file_struct *));
+ qsort(the_fattr_list.files, j,
-
--/* For calling delete_item() */
-+/* For calling delete_item() and delete_in_dir() */
+ static int deldelay_size = 0, deldelay_cnt = 0;
+ static char *deldelay_buf = NULL;
+ static int deldelay_fd = -1;
+@@ -114,7 +117,8 @@ static int need_retouch_dir_times;
+ static int need_retouch_dir_perms;
+ static const char *solo_file = NULL;
+
+-/* For calling delete_item() and delete_dir_contents(). */
++/* For calling delete_item(), delete_dir_contents(), and delete_in_dir(). */
++#define DEL_NO_DELETIONS (1<<0)
+ * time (plus the basename, if possible) or (2) the size & checksum. If
+ * we find an exact match down to the dirname, return -1 because we found
+ * an up-to-date file in the transfer, not a renamed file. */
+ * time (plus the basename, if possible) or (2) the size & checksum. If
+ * we find an exact match down to the dirname, return -1 because we found
+ * an up-to-date file in the transfer, not a renamed file. */
+{
+ int low = the_fattr_list.low, high = the_fattr_list.high;
+ int mid, ok_match = -1, good_match = -1;
+{
+ int low = the_fattr_list.low, high = the_fattr_list.high;
+ int mid, ok_match = -1, good_match = -1;
+ if (fmid->modtime == f->modtime
+ && f_name_cmp(fmid, f) == 0)
+ return -1; /* assume we can't help */
+ if (fmid->modtime == f->modtime
+ && f_name_cmp(fmid, f) == 0)
+ return -1; /* assume we can't help */
-+ f->u.sum = pool_alloc(pool, MD4_SUM_LENGTH,
-+ "fattr_find");
-+ file_checksum(fname, f->u.sum, f->length);
++ file_checksum(fname, F_SUM(f), F_LENGTH(f));
++ f->flags |= FLAG_FILE_SENT;
-@@ -185,6 +300,8 @@ static enum delret delete_item(char *fna
- /* Prep directory is to be deleted, so delete all its contents. Note
- * that fname must point to a MAXPATHLEN buffer! (The buffer is used
- * for recursion, but returned unchanged.)
+@@ -208,6 +323,8 @@ static enum delret delete_item(char *fbu
+ * its contents, otherwise just checks for content. Returns DR_SUCCESS or
+ * DR_NOT_EMPTY. Note that fname must point to a MAXPATHLEN buffer! (The
+ * buffer is used for recursion, but returned unchanged.)
-@@ -221,6 +338,16 @@ static enum delret delete_dir_contents(c
- }
-
- strlcpy(p, fp->basename, remainder);
-+ if (detect_renamed) {
-+ if (S_ISDIR(fp->mode) && flags & DEL_NO_DELETIONS) {
-+ delete_dir_contents(fname, flags);
-+ continue;
-+ }
-+ if (S_ISREG(fp->mode))
-+ look_for_rename(fp, fname, dirlist->file_pool);
-+ if (flags & DEL_NO_DELETIONS)
-+ continue;
-+ }
- result = delete_item(fname, fp->mode, NULL, flags);
- if (result != DR_SUCCESS && ret == DR_SUCCESS)
- ret = result == DR_PINNED ? result : DR_NOT_EMPTY;
-@@ -239,15 +366,19 @@ static enum delret delete_dir_contents(c
+@@ -227,7 +344,9 @@ static enum delret delete_dir_contents(c
+ save_filters = push_local_filters(fname, dlen);
+
+ non_perishable_cnt = 0;
++ file_extra_cnt += SUM_EXTRA_CNT;
+ dirlist = get_dirlist(fname, dlen, 0);
++ file_extra_cnt -= SUM_EXTRA_CNT;
+ ret = non_perishable_cnt ? DR_NOT_EMPTY : DR_SUCCESS;
+
+ if (!dirlist->used)
+@@ -264,6 +383,8 @@ static enum delret delete_dir_contents(c
+ if (S_ISDIR(fp->mode)
+ && delete_dir_contents(fname, flags | DEL_RECURSE) != DR_SUCCESS)
+ ret = DR_NOT_EMPTY;
++ if (detect_renamed && S_ISREG(fp->mode))
++ look_for_rename(fp, fname);
+ if (delete_item(fname, fp->mode, NULL, flags) != DR_SUCCESS)
+ ret = DR_NOT_EMPTY;
+ }
+@@ -416,12 +537,17 @@ static void do_delayed_deletions(char *d
* all the --delete-WHEN options. Note that the fbuf pointer must point to a
* MAXPATHLEN buffer with the name of the directory in it (the functions we
* call will append names onto the end, but the old dir value will be restored
- * on exit). */
* all the --delete-WHEN options. Note that the fbuf pointer must point to a
* MAXPATHLEN buffer with the name of the directory in it (the functions we
* call will append names onto the end, but the old dir value will be restored
- * on exit). */
- static void delete_in_dir(struct file_list *flist, char *fbuf,
-- struct file_struct *file, STRUCT_STAT *stp)
-+ struct file_struct *file, STRUCT_STAT *stp, int flags)
++static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev,
++ int flags)
-- delete_item(delbuf, fp->mode, NULL, DEL_RECURSE);
+- if (delete_during == 2) {
++ if (delete_during == 2 && !(flags & DEL_NO_DELETIONS)) {
+ if (!remember_delete(fp, delbuf))
+ break;
+ } else
+- delete_item(delbuf, fp->mode, NULL, DEL_RECURSE);
-- delete_in_dir(flist, fbuf, file, &st);
-+ delete_in_dir(flist, fbuf, file, &st, 0);
+- delete_in_dir(fbuf, file, &st.st_dev);
++ delete_in_dir(fbuf, file, &st.st_dev, 0);
-- delete_in_dir(NULL, NULL, NULL, NULL);
-+ delete_in_dir(NULL, NULL, NULL, NULL, 0);
+- delete_in_dir(NULL, NULL, &dev_zero);
++ delete_in_dir(NULL, NULL, &dev_zero, 0);
- /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
-@@ -1056,8 +1207,12 @@ static void recv_generator(char *fname,
- if (real_ret != 0 && one_file_system)
- real_st.st_dev = filesystem_dev;
- if (delete_during && f_out != -1 && !phase && dry_run < 2
-- && (file->flags & FLAG_DEL_HERE))
-- delete_in_dir(the_file_list, fname, file, &real_st);
-+ && (file->flags & FLAG_DEL_HERE)) {
+@@ -1345,8 +1491,12 @@ static void recv_generator(char *fname,
+ }
+ }
+ else if (delete_during && f_out != -1 && !phase && dry_run < 2
+- && (file->flags & FLAG_XFER_DIR))
+- delete_in_dir(fname, file, &real_sx.st.st_dev);
++ && (file->flags & FLAG_XFER_DIR)) {
-@@ -1309,8 +1464,14 @@ static void recv_generator(char *fname,
- && hard_link_check(file, ndx, fname, statret, &st,
- itemizing, code, HL_SKIP))
- return;
+@@ -1624,8 +1774,14 @@ static void recv_generator(char *fname,
+ goto cleanup;
+ }
+ #endif
- return;
-@@ -1496,11 +1657,17 @@ void generate_files(int f_out, struct fi
- (long)getpid(), flist->count);
- }
+ goto cleanup;
+@@ -1961,6 +2117,12 @@ void generate_files(int f_out, const cha
+ if (verbose > 2)
+ rprintf(FINFO, "generator starting pid=%ld\n", (long)getpid());
-@@ -1555,7 +1722,23 @@ void generate_files(int f_out, struct fi
- }
- recv_generator(NULL, NULL, 0, 0, 0, code, -1);
+@@ -2009,7 +2171,7 @@ void generate_files(int f_out, const cha
+ dirdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp));
+ } else
+ dirdev = MAKEDEV(0, 0);
+- delete_in_dir(f_name(fp, fbuf), fp, &dirdev);
++ delete_in_dir(f_name(fp, fbuf), fp, &dirdev, 0);
+ }
+ }
+ }
+@@ -2054,7 +2216,21 @@ void generate_files(int f_out, const cha
+ } while ((cur_flist = cur_flist->next) != NULL);
+
-- delete_in_dir(NULL, NULL, NULL, NULL);
-+ delete_in_dir(NULL, NULL, NULL, NULL, 0);
-+
+- delete_in_dir(NULL, NULL, &dev_zero);
++ delete_in_dir(NULL, NULL, &dev_zero, 0);
-+ recv_generator(fbuf, file, i, itemizing,
-+ maybe_ATTRS_REPORT, code, f_out);
++ recv_generator(fbuf, file, i, itemizing, code, f_out);
rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
{"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
{"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
{"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
+ {"detect-renamed", 0, POPT_ARG_NONE, &detect_renamed, 0, 0, 0 },
{"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
{"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
{"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
{"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
{"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
+ {"detect-renamed", 0, POPT_ARG_NONE, &detect_renamed, 0, 0, 0 },
{"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
{"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
- {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 },
-@@ -1362,7 +1365,7 @@ int parse_arguments(int *argc, const cha
+ {"no-compress", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
+@@ -1533,7 +1536,7 @@ int parse_arguments(int *argc_p, const c
snprintf(err_buf, sizeof err_buf,
"--%s cannot be used with --%s\n",
append_mode ? "append" : "inplace",
snprintf(err_buf, sizeof err_buf,
"--%s cannot be used with --%s\n",
append_mode ? "append" : "inplace",
--modify-window=NUM compare mod-times with reduced accuracy
-T, --temp-dir=DIR create temporary files in directory DIR
-y, --fuzzy find similar file for basis if no dest file
--modify-window=NUM compare mod-times with reduced accuracy
-T, --temp-dir=DIR create temporary files in directory DIR
-y, --fuzzy find similar file for basis if no dest file
--compare-dest=DIR also compare received files relative to DIR
--copy-dest=DIR ... and include copies of unchanged files
--link-dest=DIR hardlink to files in DIR when unchanged
--compare-dest=DIR also compare received files relative to DIR
--copy-dest=DIR ... and include copies of unchanged files
--link-dest=DIR hardlink to files in DIR when unchanged