--- embedaddon/rsync/generator.c 2016/11/01 09:54:32 1.1.1.3 +++ embedaddon/rsync/generator.c 2021/03/17 00:32:36 1.1.1.4 @@ -4,7 +4,7 @@ * Copyright (C) 1996-2000 Andrew Tridgell * Copyright (C) 1996 Paul Mackerras * Copyright (C) 2002 Martin Pool - * Copyright (C) 2003-2015 Wayne Davison + * Copyright (C) 2003-2020 Wayne Davison * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,13 +37,18 @@ extern int implied_dirs; extern int keep_dirlinks; extern int preserve_acls; extern int preserve_xattrs; +extern int preserve_hfs_compression; extern int preserve_links; extern int preserve_devices; +extern int copy_devices; +extern int write_devices; extern int preserve_specials; extern int preserve_hard_links; extern int preserve_executability; +extern int preserve_fileflags; extern int preserve_perms; extern int preserve_times; +extern int force_change; extern int delete_mode; extern int delete_before; extern int delete_during; @@ -51,18 +56,23 @@ extern int delete_after; extern int missing_args; extern int msgdone_cnt; extern int ignore_errors; +extern int checksum_files; extern int remove_source_files; extern int delay_updates; extern int update_only; +extern int downdate_only; extern int human_readable; extern int ignore_existing; extern int ignore_non_existing; extern int want_xattr_optim; +extern int modify_window; extern int inplace; +extern int use_db; extern int append_mode; extern int make_backups; extern int csum_length; extern int ignore_times; +extern int date_only; extern int size_only; extern OFF_T max_size; extern OFF_T min_size; @@ -74,17 +84,16 @@ extern int protocol_version; extern int file_total; extern int fuzzy_basis; extern int always_checksum; -extern int checksum_len; +extern int flist_csum_len; extern char *partial_dir; -extern int compare_dest; -extern int copy_dest; -extern int link_dest; +extern int alt_dest_type; +extern int detect_renamed; extern int whole_file; extern int list_only; extern int read_batch; extern int write_batch; extern int safe_symlinks; -extern long block_size; /* "long" because popt can't set an int32. */ +extern int32 block_size; extern int unsort_ndx; extern int max_delete; extern int force_delete; @@ -97,10 +106,13 @@ extern char *tmpdir; extern char *basis_dir[MAX_BASIS_DIRS+1]; extern struct file_list *cur_flist, *first_flist, *dir_flist; extern filter_rule_list filter_list, daemon_filter_list; +extern struct file_list the_fattr_list; int maybe_ATTRS_REPORT = 0; +int maybe_ATTRS_ACCURATE_TIME = 0; static dev_t dev_zero; +static int unexplored_dirs = 1; static int deldelay_size = 0, deldelay_cnt = 0; static char *deldelay_buf = NULL; static int deldelay_fd = -1; @@ -109,10 +121,11 @@ static int dir_tweaking; static int symlink_timeset_failed_flags; static int need_retouch_dir_times; static int need_retouch_dir_perms; +static int started_whole_dir, upcoming_whole_dir; static const char *solo_file = NULL; enum nonregtype { - TYPE_DIR, TYPE_SPECIAL, TYPE_DEVICE, TYPE_SYMLINK + TYPE_DIR, TYPE_SPECIAL, TYPE_DEVICE, TYPE_SYMLINK }; /* Forward declarations. */ @@ -170,10 +183,8 @@ static int remember_delete(struct file_struct *file, c deldelay_buf[deldelay_cnt++] = '!'; while (1) { - len = snprintf(deldelay_buf + deldelay_cnt, - deldelay_size - deldelay_cnt, - "%x %s%c", - (int)file->mode, fname, '\0'); + len = snprintf(deldelay_buf + deldelay_cnt, deldelay_size - deldelay_cnt, + "%x %s%c", (int)file->mode, fname, '\0'); if ((deldelay_cnt += len) <= deldelay_size) break; deldelay_cnt -= len; @@ -210,8 +221,7 @@ static int read_delay_line(char *buf, int *flags_p) deldelay_size - deldelay_cnt); if (len == 0) { if (deldelay_cnt) { - rprintf(FERROR, - "ERROR: unexpected EOF in delete-delay file.\n"); + rprintf(FERROR, "ERROR: unexpected EOF in delete-delay file.\n"); } return -1; } @@ -271,13 +281,19 @@ static void do_delayed_deletions(char *delbuf) * 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(char *fbuf, struct file_struct *file, dev_t *fs_dev) + * on exit). + * + * Note: --detect-rename may use this routine with DEL_NO_DELETIONS set! + */ +static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev, + int del_flags) { static int already_warned = 0; + static struct hashtable *dev_tbl; struct file_list *dirlist; - char delbuf[MAXPATHLEN]; - int dlen, i; + char *p, delbuf[MAXPATHLEN]; + unsigned remainder; + int dlen, i, restore_dot = 0; if (!fbuf) { change_local_filter_dir(NULL, 0, 0); @@ -291,26 +307,45 @@ static void delete_in_dir(char *fbuf, struct file_stru maybe_send_keepalive(time(NULL), MSK_ALLOW_FLUSH); if (io_error & IOERR_GENERAL && !ignore_errors) { - if (already_warned) + if (!already_warned) { + rprintf(FINFO, + "IO error encountered -- skipping file deletion\n"); + already_warned = 1; + } + if (!detect_renamed) return; - rprintf(FINFO, - "IO error encountered -- skipping file deletion\n"); - already_warned = 1; - return; + del_flags |= DEL_NO_DELETIONS; } dlen = strlen(fbuf); change_local_filter_dir(fbuf, dlen, F_DEPTH(file)); + if (detect_renamed) + unexplored_dirs--; + if (one_file_system) { - if (file->flags & FLAG_TOP_DIR) + if (!dev_tbl) + dev_tbl = hashtable_create(16, HT_KEY64); + if (file->flags & FLAG_TOP_DIR) { + hashtable_find(dev_tbl, *fs_dev+1, ""); filesystem_dev = *fs_dev; - else if (filesystem_dev != *fs_dev) - return; + } else if (filesystem_dev != *fs_dev) { + if (!hashtable_find(dev_tbl, *fs_dev+1, NULL)) + return; + filesystem_dev = *fs_dev; /* it's a prior top-dir dev */ + } } dirlist = get_dirlist(fbuf, dlen, 0); + p = fbuf + dlen; + if (dlen == 1 && *fbuf == '.') { + restore_dot = 1; + p = fbuf; + } else if (dlen != 1 || *fbuf != '/') + *p++ = '/'; + remainder = MAXPATHLEN - (p - fbuf); + /* If an item in dirlist is not found in flist, delete it * from the filesystem. */ for (i = dirlist->used; i--; ) { @@ -323,6 +358,10 @@ static void delete_in_dir(char *fbuf, struct file_stru f_name(fp, NULL)); continue; } + if (detect_renamed && S_ISREG(fp->mode)) { + strlcpy(p, fp->basename, remainder); + look_for_rename(fp, fbuf); + } /* Here we want to match regardless of file type. Replacement * of a file with one of another type is handled separately by * a delete_item call with a DEL_MAKE_ROOM flag. */ @@ -331,14 +370,19 @@ static void delete_in_dir(char *fbuf, struct file_stru if (!(fp->mode & S_IWUSR) && !am_root && fp->flags & FLAG_OWNED_BY_US) flags |= DEL_NO_UID_WRITE; f_name(fp, delbuf); - if (delete_during == 2) { - if (!remember_delete(fp, delbuf, flags)) + if (delete_during == 2 && !(del_flags & DEL_NO_DELETIONS)) { + if (!remember_delete(fp, delbuf, del_flags | flags)) break; } else - delete_item(delbuf, fp->mode, flags); - } + delete_item(delbuf, fp->mode, del_flags | flags); + } else if (detect_renamed && S_ISDIR(fp->mode)) + unexplored_dirs++; } + if (restore_dot) + fbuf[0] = '.'; + fbuf[dlen] = '\0'; + flist_free(dirlist); } @@ -374,19 +418,147 @@ static void do_delete_pass(void) || !S_ISDIR(st.st_mode)) continue; - delete_in_dir(fbuf, file, &st.st_dev); + delete_in_dir(fbuf, file, &st.st_dev, 0); } - delete_in_dir(NULL, NULL, &dev_zero); + delete_in_dir(NULL, NULL, &dev_zero, 0); if (INFO_GTE(FLIST, 2) && !am_server) rprintf(FINFO, " \r"); } -static inline int time_differs(struct file_struct *file, stat_x *sxp) +/* Search for a regular file that matches either (1) the size & modified + * 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. */ +static int fattr_find(struct file_struct *f, char *fname) { - return cmp_time(sxp->st.st_mtime, file->modtime); + int low = the_fattr_list.low, high = the_fattr_list.high; + int mid, ok_match = -1, good_match = -1; + struct file_struct *fmid; + int diff; + + while (low <= high) { + mid = (low + high) / 2; + fmid = the_fattr_list.files[mid]; + if (F_LENGTH(fmid) != F_LENGTH(f)) { + if (F_LENGTH(fmid) < F_LENGTH(f)) + low = mid + 1; + else + high = mid - 1; + continue; + } + if (always_checksum) { + /* We use the FLAG_FILE_SENT flag to indicate when we + * have computed the checksum for an entry. */ + if (!(f->flags & FLAG_FILE_SENT)) { + STRUCT_STAT st; + if (fmid->modtime == f->modtime + && f_name_cmp(fmid, f) == 0) + return -1; /* assume we can't help */ + st.st_size = F_LENGTH(f); + st.st_mtime = f->modtime; + file_checksum(fname, &st, F_SUM(f)); + f->flags |= FLAG_FILE_SENT; + } + diff = u_memcmp(F_SUM(fmid), F_SUM(f), flist_csum_len); + if (diff) { + if (diff < 0) + low = mid + 1; + else + high = mid - 1; + continue; + } + } else { + if (fmid->modtime != f->modtime) { + if (fmid->modtime < f->modtime) + low = mid + 1; + else + high = mid - 1; + continue; + } + } + ok_match = mid; + diff = u_strcmp(fmid->basename, f->basename); + if (diff == 0) { + good_match = mid; + if (fmid->dirname == f->dirname) + return -1; /* file is up-to-date */ + if (!fmid->dirname) { + low = mid + 1; + continue; + } + if (!f->dirname) { + high = mid - 1; + continue; + } + diff = u_strcmp(fmid->dirname, f->dirname); + if (diff == 0) + return -1; /* file is up-to-date */ + } + if (diff < 0) + low = mid + 1; + else + high = mid - 1; + } + + return good_match >= 0 ? good_match : ok_match; } +void look_for_rename(struct file_struct *file, char *fname) +{ + struct file_struct *fp; + char *partialptr, *fn; + STRUCT_STAT st; + int ndx; + + if (!partial_dir || (ndx = fattr_find(file, fname)) < 0) + return; + + fp = the_fattr_list.files[ndx]; + fn = f_name(fp, NULL); + /* We don't provide an alternate-basis file if there is a basis file. */ + if (link_stat(fn, &st, 0) == 0) + return; + + if (!dry_run) { + if ((partialptr = partial_dir_fname(fn)) == NULL + || !handle_partial_dir(partialptr, PDIR_CREATE)) + return; + /* We only use the file if we can hard-link it into our tmp dir. */ + if (link(fname, partialptr) != 0) { + if (errno != EEXIST) + handle_partial_dir(partialptr, PDIR_DELETE); + return; + } + } + + /* I think this falls into the -vv category with "%s is uptodate", etc. */ + if (INFO_GTE(MISC, 2)) + rprintf(FINFO, "found renamed: %s => %s\n", fname, fn); +} + +static inline int mtime_differs(STRUCT_STAT *stp, struct file_struct *file) +{ +#ifdef ST_MTIME_NSEC + return !same_time(stp->st_mtime, stp->ST_MTIME_NSEC, file->modtime, F_MOD_NSEC_or_0(file)); +#else + return !same_time(stp->st_mtime, 0, file->modtime, 0); +#endif +} + +static inline int any_time_differs(stat_x *sxp, struct file_struct *file, UNUSED(const char *fname)) +{ + int differs = mtime_differs(&sxp->st, file); +#ifdef SUPPORT_CRTIMES + if (!differs && crtimes_ndx) { + if (sxp->crtime == 0) + sxp->crtime = get_create_time(fname); + differs = !same_time(sxp->crtime, 0, F_CRTIME(file), 0); + } +#endif + return differs; +} + static inline int perms_differ(struct file_struct *file, stat_x *sxp) { if (preserve_perms) @@ -441,7 +613,7 @@ int unchanged_attrs(const char *fname, struct file_str { if (S_ISLNK(file->mode)) { #ifdef CAN_SET_SYMLINK_TIMES - if (preserve_times & PRESERVE_LINK_TIMES && time_differs(file, sxp)) + if (preserve_times & PRESERVE_LINK_TIMES && any_time_differs(sxp, file, fname)) return 0; #endif #ifdef CAN_CHMOD_SYMLINK @@ -461,10 +633,14 @@ int unchanged_attrs(const char *fname, struct file_str return 0; #endif } else { - if (preserve_times && time_differs(file, sxp)) + if (preserve_times && any_time_differs(sxp, file, fname)) return 0; if (perms_differ(file, sxp)) return 0; +#ifdef SUPPORT_FILEFLAGS + if (preserve_fileflags && sxp->st.st_flags != F_FFLAGS(file)) + return 0; +#endif if (ownership_differs(file, sxp)) return 0; #ifdef SUPPORT_ACLS @@ -485,6 +661,7 @@ void itemize(const char *fnamecmp, struct file_struct const char *xname) { if (statret >= 0) { /* A from-dest-dir statret can == 1! */ + int omit_changes = omit_dir_changes && S_ISDIR(sxp->st.st_mode); int keep_time = !preserve_times ? 0 : S_ISDIR(file->mode) ? preserve_times & PRESERVE_DIR_TIMES : S_ISLNK(file->mode) ? preserve_times & PRESERVE_LINK_TIMES @@ -496,10 +673,21 @@ void itemize(const char *fnamecmp, struct file_struct if (iflags & ITEM_LOCAL_CHANGE) iflags |= symlink_timeset_failed_flags; } else if (keep_time - ? cmp_time(file->modtime, sxp->st.st_mtime) != 0 + ? mtime_differs(&sxp->st, file) : iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !(iflags & ITEM_MATCHED) && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname)) iflags |= ITEM_REPORT_TIME; + if (atimes_ndx && !S_ISDIR(file->mode) && !S_ISLNK(file->mode) + && !same_time(F_ATIME(file), 0, sxp->st.st_atime, 0)) + iflags |= ITEM_REPORT_ATIME; +#ifdef SUPPORT_CRTIMES + if (crtimes_ndx) { + if (sxp->crtime == 0) + sxp->crtime = get_create_time(fnamecmp); + if (!same_time(sxp->crtime, 0, F_CRTIME(file), 0)) + iflags |= ITEM_REPORT_CRTIME; + } +#endif #if !defined HAVE_LCHMOD && !defined HAVE_SETATTRLIST if (S_ISLNK(file->mode)) { ; @@ -511,11 +699,15 @@ void itemize(const char *fnamecmp, struct file_struct } else if (preserve_executability && ((sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0))) iflags |= ITEM_REPORT_PERMS; - if (uid_ndx && am_root && (uid_t)F_OWNER(file) != sxp->st.st_uid) + if (uid_ndx && am_root && !omit_changes && (uid_t)F_OWNER(file) != sxp->st.st_uid) iflags |= ITEM_REPORT_OWNER; - if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP) - && sxp->st.st_gid != (gid_t)F_GROUP(file)) + if (gid_ndx && !omit_changes && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file)) iflags |= ITEM_REPORT_GROUP; +#ifdef SUPPORT_FILEFLAGS + if (preserve_fileflags && !S_ISLNK(file->mode) + && sxp->st.st_flags != F_FFLAGS(file)) + iflags |= ITEM_REPORT_FFLAGS; +#endif #ifdef SUPPORT_ACLS if (preserve_acls && !S_ISLNK(file->mode)) { if (!ACL_READY(*sxp)) @@ -569,8 +761,11 @@ void itemize(const char *fnamecmp, struct file_struct /* Perform our quick-check heuristic for determining if a file is unchanged. */ -int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st) +int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st, int slot) { + if (date_only) + return !mtime_differs(st, file); + if (st->st_size != F_LENGTH(file)) return 0; @@ -578,8 +773,11 @@ int unchanged_file(char *fn, struct file_struct *file, of the file time to determine whether to sync */ if (always_checksum > 0 && S_ISREG(st->st_mode)) { char sum[MAX_DIGEST_LEN]; - file_checksum(fn, st, sum); - return memcmp(sum, F_SUM(file), checksum_len) == 0; + if (checksum_files && slot >= 0) + get_cached_checksum(slot, fn, file, -1, st, sum); + else + file_checksum(fn, st, sum); + return memcmp(sum, F_SUM(file), flist_csum_len) == 0; } if (size_only > 0) @@ -588,7 +786,7 @@ int unchanged_file(char *fn, struct file_struct *file, if (ignore_times) return 0; - return cmp_time(st->st_mtime, file->modtime) == 0; + return !mtime_differs(st, file); } @@ -633,14 +831,14 @@ static void sum_sizes_sqroot(struct sum_struct *sum, i if (c < 0 || c >= max_blength) blength = max_blength; else { - blength = 0; - do { - blength |= c; - if (len < (int64)blength * blength) - blength &= ~c; - c >>= 1; - } while (c >= 8); /* round to multiple of 8 */ - blength = MAX(blength, BLOCK_SIZE); + blength = 0; + do { + blength |= c; + if (len < (int64)blength * blength) + blength &= ~c; + c >>= 1; + } while (c >= 8); /* round to multiple of 8 */ + blength = MAX(blength, BLOCK_SIZE); } } @@ -697,10 +895,12 @@ static int generate_and_send_sums(int fd, OFF_T len, i if (append_mode > 0 && f_copy < 0) return 0; - if (len > 0) + if (len > 0) { mapbuf = map_file(fd, len, MAX_MAP_SIZE, sum.blength); - else + checksum2_enable_prefetch(mapbuf, len, sum.blength); + } else { mapbuf = NULL; + } for (i = 0; i < sum.count; i++) { int32 n1 = (int32)MIN(len, (OFF_T)sum.blength); @@ -718,7 +918,7 @@ static int generate_and_send_sums(int fd, OFF_T len, i } sum1 = get_checksum1(map, n1); - get_checksum2(map, n1, sum2); + get_checksum2(map, n1, sum2, offset - n1); if (DEBUG_GTE(DELTASUM, 3)) { rprintf(FINFO, @@ -730,8 +930,10 @@ static int generate_and_send_sums(int fd, OFF_T len, i write_buf(f_out, sum2, sum.s2length); } - if (mapbuf) + if (mapbuf) { unmap_file(mapbuf); + checksum2_disable_prefetch(); + } return 0; } @@ -765,7 +967,7 @@ static struct file_struct *find_fuzzy(struct file_stru if (!S_ISREG(fp->mode) || !F_LENGTH(fp) || fp->flags & FLAG_FILE_SENT) continue; - if (F_LENGTH(fp) == F_LENGTH(file) && cmp_time(fp->modtime, file->modtime) == 0) { + if (F_LENGTH(fp) == F_LENGTH(file) && same_time(fp->modtime, 0, file->modtime, 0)) { if (DEBUG_GTE(FUZZY, 2)) rprintf(FINFO, "fuzzy size/modtime match for %s\n", f_name(fp, NULL)); *fnamecmp_type_ptr = FNAMECMP_FUZZY + i; @@ -871,27 +1073,22 @@ static int try_dests_reg(struct file_struct *file, cha pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode)) continue; - switch (match_level) { - case 0: + if (match_level == 0) { best_match = j; match_level = 1; - /* FALL THROUGH */ - case 1: - if (!unchanged_file(cmpbuf, file, &sxp->st)) - continue; + } + if (!unchanged_file(cmpbuf, file, &sxp->st, j+1)) + continue; + if (match_level == 1) { best_match = j; match_level = 2; - /* FALL THROUGH */ - case 2: - if (!unchanged_attrs(cmpbuf, file, sxp)) { - free_stat_x(sxp); - continue; - } + } + if (alt_dest_type == CLONE_DEST || unchanged_attrs(cmpbuf, file, sxp)) { best_match = j; match_level = 3; break; } - break; + free_stat_x(sxp); } while (basis_dir[++j] != NULL); if (!match_level) @@ -904,17 +1101,19 @@ static int try_dests_reg(struct file_struct *file, cha goto got_nothing_for_ya; } - if (match_level == 3 && !copy_dest) { + if (match_level == 3 && alt_dest_type != COPY_DEST) { if (find_exact_for_existing) { - if (link_dest && real_st.st_dev == sxp->st.st_dev && real_st.st_ino == sxp->st.st_ino) + if (alt_dest_type == LINK_DEST && real_st.st_dev == sxp->st.st_dev && real_st.st_ino == sxp->st.st_ino) return -1; if (do_unlink(fname) < 0 && errno != ENOENT) goto got_nothing_for_ya; } #ifdef SUPPORT_HARD_LINKS - if (link_dest) { + if (alt_dest_type == LINK_DEST) { if (!hard_link_one(file, fname, cmpbuf, 1)) goto try_a_copy; + if (atimes_ndx) + set_file_attrs(fname, file, sxp, NULL, 0); if (preserve_hard_links && F_IS_HLINKED(file)) finish_hard_link(file, fname, ndx, &sxp->st, itemizing, code, j); if (!maybe_ATTRS_REPORT && (INFO_GTE(NAME, 2) || stdout_format_has_i > 1)) { @@ -924,7 +1123,12 @@ static int try_dests_reg(struct file_struct *file, cha } } else #endif - { + if (alt_dest_type == CLONE_DEST) { + if (do_clone(cmpbuf, fname, file->mode) < 0) { + rsyserr(FERROR_XFER, errno, "failed to clone %s to %s", cmpbuf, fname); + exit_cleanup(RERR_UNSUPPORTED); + } + } else { if (itemizing) itemize(cmpbuf, file, ndx, 0, sxp, 0, 0, NULL); } @@ -1080,7 +1284,7 @@ static int try_dests_non(struct file_struct *file, cha if (match_level == 3) { #ifdef SUPPORT_HARD_LINKS - if (link_dest + if ((alt_dest_type == LINK_DEST || alt_dest_type == CLONE_DEST) #ifndef CAN_HARDLINK_SYMLINK && !S_ISLNK(file->mode) #endif @@ -1101,7 +1305,7 @@ static int try_dests_non(struct file_struct *file, cha match_level = 2; if (itemizing && stdout_format_has_i && (INFO_GTE(NAME, 2) || stdout_format_has_i > 1)) { - int chg = compare_dest && type != TYPE_DIR ? 0 + int chg = alt_dest_type == COMPARE_DEST && type != TYPE_DIR ? 0 : ITEM_LOCAL_CHANGE + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0); char *lp = match_level == 3 ? "" : NULL; itemize(cmpbuf, file, ndx, 0, sxp, chg + ITEM_MATCHED, 0, lp); @@ -1119,38 +1323,46 @@ static int try_dests_non(struct file_struct *file, cha static void list_file_entry(struct file_struct *f) { char permbuf[PERMSTRING_SIZE]; - int64 len; - int colwidth = human_readable ? 14 : 11; + const char *mtime_str = timestring(f->modtime); + int size_width = human_readable ? 14 : 11; + int mtime_width = 1 + strlen(mtime_str); + int atime_width = atimes_ndx ? mtime_width : 0; + int crtime_width = crtimes_ndx ? mtime_width : 0; if (!F_IS_ACTIVE(f)) { /* this can happen if duplicate names were removed */ return; } - permstring(permbuf, f->mode); - len = F_LENGTH(f); - /* TODO: indicate '+' if the entry has an ACL. */ -#ifdef SUPPORT_LINKS - if (preserve_links && S_ISLNK(f->mode)) { - rprintf(FINFO, "%s %*s %s %s -> %s\n", - permbuf, colwidth, human_num(len), - timestring(f->modtime), f_name(f, NULL), - F_SYMLINK(f)); - } else -#endif if (missing_args == 2 && f->mode == 0) { rprintf(FINFO, "%-*s %s\n", - colwidth + 31, "*missing", + 10 + 1 + size_width + mtime_width + atime_width + crtime_width, "*missing", f_name(f, NULL)); } else { - rprintf(FINFO, "%s %*s %s %s\n", - permbuf, colwidth, human_num(len), - timestring(f->modtime), f_name(f, NULL)); + const char *atime_str = atimes_ndx && !S_ISDIR(f->mode) ? timestring(F_ATIME(f)) : ""; + const char *crtime_str = crtimes_ndx ? timestring(F_CRTIME(f)) : ""; + const char *arrow, *lnk; + + permstring(permbuf, f->mode); + +#ifdef SUPPORT_LINKS + if (preserve_links && S_ISLNK(f->mode)) { + arrow = " -> "; + lnk = F_SYMLINK(f); + } else +#endif + arrow = lnk = ""; + + rprintf(FINFO, "%s %*s %s%*s%*s %s%s%s\n", + permbuf, size_width, human_num(F_LENGTH(f)), + timestring(f->modtime), atime_width, atime_str, crtime_width, crtime_str, + f_name(f, NULL), arrow, lnk); } } +static struct bitbag *delayed_bits = NULL; static int phase = 0; static int dflt_perms; @@ -1184,7 +1396,7 @@ static void recv_generator(char *fname, struct file_st * --ignore-non-existing, daemon exclude, or mkdir failure. */ static struct file_struct *skip_dir = NULL; static struct file_list *fuzzy_dirlist[MAX_BASIS_DIRS+1]; - static int need_fuzzy_dirlist = 0; + static int need_new_dirscan = 0; struct file_struct *fuzzy_file = NULL; int fd = -1, f_copy = -1; stat_x sx, real_sx; @@ -1210,6 +1422,8 @@ static void recv_generator(char *fname, struct file_st return; } + maybe_ATTRS_ACCURATE_TIME = always_checksum ? ATTRS_ACCURATE_TIME : 0; + if (skip_dir) { if (is_below(file, skip_dir)) { if (is_dir) @@ -1240,6 +1454,7 @@ static void recv_generator(char *fname, struct file_st return; } } + sx.crtime = 0; if (dry_run > 1 || (dry_missing_dir && is_below(file, dry_missing_dir))) { int i; @@ -1262,18 +1477,29 @@ static void recv_generator(char *fname, struct file_st * this function was asked to process in the file list. */ if (!inc_recurse && (*dn != '.' || dn[1]) /* Avoid an issue with --relative and the "." dir. */ - && (prior_dir_file && strcmp(dn, f_name(prior_dir_file, NULL)) != 0) - && flist_find_name(cur_flist, dn, 1) < 0) { - rprintf(FERROR, - "ABORTING due to invalid path from sender: %s/%s\n", - dn, file->basename); - exit_cleanup(RERR_PROTOCOL); + && (!prior_dir_file || strcmp(dn, f_name(prior_dir_file, NULL)) != 0)) { + int ok = 0, j = flist_find_name(cur_flist, dn, -1); + if (j >= 0) { + struct file_struct *f = cur_flist->sorted[j]; + if (S_ISDIR(f->mode) || (missing_args == 2 && !file->mode && !f->mode)) + ok = 1; + } + /* The --delete-missing-args option can actually put invalid entries into + * the file list, so if that option was specified, we'll just complain about + * it and allow it. */ + if (!ok && missing_args == 2 && file->mode == 0 && j < 0) + rprintf(FERROR, "WARNING: parent dir is absent in the file list: %s\n", dn); + else if (!ok) { + rprintf(FERROR, "ABORTING due to invalid path from sender: %s/%s\n", + dn, file->basename); + exit_cleanup(RERR_PROTOCOL); + } } - if (relative_paths && !implied_dirs + if (relative_paths && !implied_dirs && file->mode != 0 && do_stat(dn, &sx.st) < 0) { if (dry_run) goto parent_is_dry_missing; - if (make_path(fname, MKP_DROP_NAME | MKP_SKIP_SLASH) < 0) { + if (make_path(fname, ACCESSPERMS, MKP_DROP_NAME | MKP_SKIP_SLASH) < 0) { rsyserr(FERROR_XFER, errno, "recv_generator: mkdir %s failed", full_fname(dn)); @@ -1287,8 +1513,9 @@ static void recv_generator(char *fname, struct file_st fuzzy_dirlist[i] = NULL; } } - need_fuzzy_dirlist = 1; - } + need_new_dirscan = 1; + } else if (checksum_files) + need_new_dirscan = 1; #ifdef SUPPORT_ACLS if (!preserve_perms) dflt_perms = default_perms_for_dir(dn); @@ -1296,19 +1523,23 @@ static void recv_generator(char *fname, struct file_st } parent_dirname = dn; - if (need_fuzzy_dirlist && S_ISREG(file->mode)) { + if (need_new_dirscan && S_ISREG(file->mode)) { int i; strlcpy(fnamecmpbuf, dn, sizeof fnamecmpbuf); for (i = 0; i < fuzzy_basis; i++) { if (i && pathjoin(fnamecmpbuf, MAXPATHLEN, basis_dir[i-1], dn) >= MAXPATHLEN) continue; - fuzzy_dirlist[i] = get_dirlist(fnamecmpbuf, -1, GDL_IGNORE_FILTER_RULES); + fuzzy_dirlist[i] = get_dirlist(fnamecmpbuf, -1, GDL_IGNORE_FILTER_RULES | GDL_PERHAPS_DIR); if (fuzzy_dirlist[i] && fuzzy_dirlist[i]->used == 0) { flist_free(fuzzy_dirlist[i]); fuzzy_dirlist[i] = NULL; } } - need_fuzzy_dirlist = 0; + if (checksum_files) { + reset_checksum_cache(started_whole_dir); + started_whole_dir = upcoming_whole_dir; + } + need_new_dirscan = 0; } statret = link_stat(fname, &sx.st, keep_dirlinks && is_dir); @@ -1370,7 +1601,7 @@ static void recv_generator(char *fname, struct file_st added_perms = 0; if (is_dir < 0) { if (!(preserve_times & PRESERVE_DIR_TIMES)) - return; + goto cleanup; /* In inc_recurse mode we want to make sure any missing * directories get created while we're still processing * the parent dir (which allows us to touch the parent @@ -1404,13 +1635,15 @@ static void recv_generator(char *fname, struct file_st real_ret = statret; if (file->flags & FLAG_DIR_CREATED) statret = -1; - if (!preserve_perms) { /* See comment in non-dir code below. */ - file->mode = dest_mode(file->mode, sx.st.st_mode, - dflt_perms, statret == 0); + if (!preserve_perms || omit_dir_changes) { /* See comment in non-dir code below. */ + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, statret == 0); } +#ifdef SUPPORT_FORCE_CHANGE + if (force_change && !preserve_fileflags) + F_FFLAGS(file) = sx.st.st_flags; +#endif if (statret != 0 && basis_dir[0] != NULL) { - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, - itemizing, code); + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, itemizing, code); if (j == -2) { itemizing = 0; code = FNONE; @@ -1426,14 +1659,13 @@ static void recv_generator(char *fname, struct file_st } if (real_ret != 0 && do_mkdir(fname,file->mode|added_perms) < 0 && errno != EEXIST) { if (!relative_paths || errno != ENOENT - || make_path(fname, MKP_DROP_NAME | MKP_SKIP_SLASH) < 0 + || make_path(fname, ACCESSPERMS, MKP_DROP_NAME | MKP_SKIP_SLASH) < 0 || (do_mkdir(fname, file->mode|added_perms) < 0 && errno != EEXIST)) { rsyserr(FERROR_XFER, errno, "recv_generator: mkdir %s failed", full_fname(fname)); skipping_dir_contents: - rprintf(FERROR, - "*** Skipping any contents from this failed directory ***\n"); + rprintf(FERROR, "*** Skipping any contents from this failed directory ***\n"); skip_dir = file; file->flags |= FLAG_MISSING_DIR; goto cleanup; @@ -1445,17 +1677,22 @@ static void recv_generator(char *fname, struct file_st copy_xattrs(fnamecmpbuf, fname); #endif if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, NULL, 0) - && INFO_GTE(NAME, 1) && code != FNONE && f_out != -1) + && INFO_GTE(NAME, 1) && code != FNONE && f_out != -1) rprintf(code, "%s/\n", fname); /* We need to ensure that the dirs in the transfer have both * readable and writable permissions during the time we are * putting files within them. This is then restored to the * former permissions after the transfer is done. */ +#ifdef SUPPORT_FORCE_CHANGE + if (force_change && F_FFLAGS(file) & force_change + && make_mutable(fname, file->mode, F_FFLAGS(file), force_change)) + need_retouch_dir_perms = 1; +#endif #ifdef HAVE_CHMOD if (!am_root && (file->mode & S_IRWXU) != S_IRWXU && dir_tweaking) { mode_t mode = file->mode | S_IRWXU; - if (do_chmod(fname, mode) < 0) { + if (do_chmod(fname, mode, 0) < 0) { rsyserr(FERROR_XFER, errno, "failed to modify permissions on %s", full_fname(fname)); @@ -1475,11 +1712,15 @@ static void recv_generator(char *fname, struct file_st } else if (delete_during && f_out != -1 && !phase && !(file->flags & FLAG_MISSING_DIR)) { - if (file->flags & FLAG_CONTENT_DIR) - delete_in_dir(fname, file, &real_sx.st.st_dev); - else + if (file->flags & FLAG_CONTENT_DIR) { + if (detect_renamed && real_ret != 0) + unexplored_dirs++; + delete_in_dir(fname, file, &real_sx.st.st_dev, + delete_during < 0 ? DEL_NO_DELETIONS : 0); + } else change_local_filter_dir(fname, strlen(fname), F_DEPTH(file)); } + upcoming_whole_dir = file->flags & FLAG_CONTENT_DIR && f_out != -1 ? 1 : 0; prior_dir_file = file; goto cleanup; } @@ -1488,9 +1729,12 @@ static void recv_generator(char *fname, struct file_st * mode based on the local permissions and some heuristics. */ if (!preserve_perms) { int exists = statret == 0 && !S_ISDIR(sx.st.st_mode); - file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, - exists); + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, exists); } +#ifdef SUPPORT_FORCE_CHANGE + if (force_change && !preserve_fileflags) + F_FFLAGS(file) = sx.st.st_flags; +#endif #ifdef SUPPORT_HARD_LINKS if (preserve_hard_links && F_HLINK_NOT_FIRST(file) @@ -1512,7 +1756,7 @@ static void recv_generator(char *fname, struct file_st "ignoring unsafe symlink \"%s\" -> \"%s\"\n", fname, sl); } - return; + goto cleanup; } if (statret == 0) { char lnk[MAXPATHLEN]; @@ -1534,15 +1778,14 @@ static void recv_generator(char *fname, struct file_st goto cleanup; } } else if (basis_dir[0] != NULL) { - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, - itemizing, code); + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, itemizing, code); if (j == -2) { #ifndef CAN_HARDLINK_SYMLINK - if (link_dest) { + if (alt_dest_type == LINK_DEST) { /* Resort to --copy-dest behavior. */ } else #endif - if (!copy_dest) + if (alt_dest_type != COPY_DEST) goto cleanup; itemizing = 0; code = FNONE; @@ -1610,15 +1853,14 @@ static void recv_generator(char *fname, struct file_st goto cleanup; } } else if (basis_dir[0] != NULL) { - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, - itemizing, code); + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, itemizing, code); if (j == -2) { #ifndef CAN_HARDLINK_SPECIAL - if (link_dest) { + if (alt_dest_type == LINK_DEST) { /* Resort to --copy-dest behavior. */ } else #endif - if (!copy_dest) + if (alt_dest_type != COPY_DEST) goto cleanup; itemizing = 0; code = FNONE; @@ -1650,7 +1892,7 @@ static void recv_generator(char *fname, struct file_st goto cleanup; } - if (!S_ISREG(file->mode)) { + if (!(S_ISREG(file->mode) || (copy_devices && IS_DEVICE(file->mode)))) { if (solo_file) fname = f_name(file, NULL); rprintf(FINFO, "skipping non-regular file \"%s\"\n", fname); @@ -1674,8 +1916,7 @@ static void recv_generator(char *fname, struct file_st goto cleanup; } - if (update_only > 0 && statret == 0 - && cmp_time(sx.st.st_mtime, file->modtime) > 0) { + if (update_only > 0 && statret == 0 && file->modtime - sx.st.st_mtime <= modify_window) { if (INFO_GTE(SKIP, 1)) rprintf(FINFO, "%s is newer\n", fname); #ifdef SUPPORT_HARD_LINKS @@ -1685,18 +1926,23 @@ static void recv_generator(char *fname, struct file_st goto cleanup; } + if (downdate_only > 0 && statret == 0 && file->modtime - sx.st.st_mtime >= modify_window) { + if (INFO_GTE(SKIP, 1)) + rprintf(FINFO, "%s is older\n", fname); + return; + } + fnamecmp_type = FNAMECMP_FNAME; - if (statret == 0 && !S_ISREG(sx.st.st_mode)) { + if (statret == 0 && !(S_ISREG(sx.st.st_mode) || (write_devices && IS_DEVICE(sx.st.st_mode)))) { if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_FILE) != 0) goto cleanup; statret = -1; stat_errno = ENOENT; } - if (basis_dir[0] != NULL && (statret != 0 || !copy_dest)) { - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx, - statret == 0, itemizing, code); + if (basis_dir[0] != NULL && (statret != 0 || alt_dest_type != COPY_DEST)) { + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx, statret == 0, itemizing, code); if (j == -2) { if (remove_source_files == 1) goto return_with_success; @@ -1714,8 +1960,8 @@ static void recv_generator(char *fname, struct file_st real_ret = statret; if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL - && link_stat(partialptr, &partial_st, 0) == 0 - && S_ISREG(partial_st.st_mode)) { + && link_stat(partialptr, &partial_st, 0) == 0 + && S_ISREG(partial_st.st_mode)) { if (statret != 0) goto prepare_to_open; } else @@ -1731,6 +1977,14 @@ static void recv_generator(char *fname, struct file_st fname, fnamecmpbuf); } sx.st.st_size = F_LENGTH(fuzzy_file); +#ifdef SUPPORT_HFS_COMPRESSION + if (sx.st.st_flags & UF_COMPRESSED) { + if (preserve_hfs_compression) + sx.st.st_size = 0; + else + sx.st.st_flags &= ~UF_COMPRESSED; + } +#endif statret = 0; fnamecmp = fnamecmpbuf; } @@ -1743,8 +1997,14 @@ static void recv_generator(char *fname, struct file_st goto cleanup; } #endif - if (stat_errno == ENOENT) + if (stat_errno == ENOENT) { + if (detect_renamed && unexplored_dirs > 0 + && F_LENGTH(file)) { + bitbag_set_bit(delayed_bits, ndx); + return; + } goto notify_others; + } rsyserr(FERROR_XFER, stat_errno, "recv_generator: failed to stat %s", full_fname(fname)); goto cleanup; @@ -1752,14 +2012,16 @@ static void recv_generator(char *fname, struct file_st if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH) ; - else if (fnamecmp_type == FNAMECMP_FUZZY) + else if (fnamecmp_type >= FNAMECMP_FUZZY) ; - else if (unchanged_file(fnamecmp, file, &sx.st)) { + else if (unchanged_file(fnamecmp, file, &sx.st, fnamecmp_type == FNAMECMP_FNAME ? 0 : -1)) { if (partialptr) { do_unlink(partialptr); handle_partial_dir(partialptr, PDIR_DELETE); } - set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT); + set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT | maybe_ATTRS_ACCURATE_TIME); + if (checksum_files & CSF_UPDATE) + set_cached_checksum(cur_flist, file); if (itemizing) itemize(fnamecmp, file, ndx, statret, &sx, 0, 0, NULL); #ifdef SUPPORT_HARD_LINKS @@ -1788,13 +2050,28 @@ static void recv_generator(char *fname, struct file_st fnamecmp = partialptr; fnamecmp_type = FNAMECMP_PARTIAL_DIR; statret = 0; + if (detect_renamed > 1 && unchanged_file(fnamecmp, file, &sx.st)) { + /* Adopt the partial file. */ + finish_transfer(fname, fnamecmp, NULL, NULL, file, 1, 1); + handle_partial_dir(partialptr, PDIR_DELETE); + if (itemizing) + itemize(fnamecmp, file, ndx, -1, &sx, + ITEM_LOCAL_CHANGE, fnamecmp_type, NULL); +#ifdef SUPPORT_HARD_LINKS + if (preserve_hard_links && F_IS_HLINKED(file)) + finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1); +#endif + if (remove_source_files == 1) + goto return_with_success; + goto cleanup; + } } if (!do_xfers) goto notify_others; if (read_batch || whole_file) { - if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) { + if (inplace && make_backups > 1 && fnamecmp_type == FNAMECMP_FNAME) { if (!(backupptr = get_backup_name(fname))) goto cleanup; if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) @@ -1830,7 +2107,7 @@ static void recv_generator(char *fname, struct file_st goto notify_others; } - if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) { + if (inplace && make_backups > 1 && fnamecmp_type == FNAMECMP_FNAME) { if (!(backupptr = get_backup_name(fname))) { close(fd); goto cleanup; @@ -1857,6 +2134,9 @@ static void recv_generator(char *fname, struct file_st fnamecmp_type = FNAMECMP_BACKUP; } + if (IS_DEVICE(sx.st.st_mode) && sx.st.st_size == 0) + sx.st.st_size = get_device_size(fd, fnamecmp); + if (DEBUG_GTE(DELTASUM, 3)) { rprintf(FINFO, "gen mapped %s of size %s\n", fnamecmp, big_num(sx.st.st_size)); @@ -1898,6 +2178,18 @@ static void recv_generator(char *fname, struct file_st if (read_batch) goto cleanup; +#ifdef SUPPORT_HFS_COMPRESSION + if (F_FFLAGS(file) & UF_COMPRESSED) { + /* At this point the attrs have already been copied, we don't need to transfer a data fork + * If my filesystem doesn't support HFS compression, the existing file's content + * will not be automatically truncated, so we'll do that manually here */ + if (preserve_hfs_compression && sx.st.st_size > 0) { + if (ftruncate(fd, 0) == 0) + sx.st.st_size = 0; + } + } +#endif + if (statret != 0 || whole_file) write_sum_head(f_out, NULL); else if (sx.st.st_size <= 0) { @@ -1906,8 +2198,8 @@ static void recv_generator(char *fname, struct file_st } else { if (generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy) < 0) { rprintf(FWARNING, - "WARNING: file is too large for checksum sending: %s\n", - fnamecmp); + "WARNING: file is too large for checksum sending: %s\n", + fnamecmp); write_sum_head(f_out, NULL); } close(fd); @@ -1954,7 +2246,7 @@ int atomic_create(struct file_struct *file, char *fnam skip_atomic = 0; if (del_for_flag) { - if (make_backups > 0 && !dir_in_the_way) { + if (make_backups > 1 && !dir_in_the_way) { if (!make_backup(fname, skip_atomic)) return 0; } else if (skip_atomic) { @@ -2059,13 +2351,25 @@ static void touch_up_dirs(struct file_list *flist, int continue; fname = f_name(file, NULL); if (fix_dir_perms) - do_chmod(fname, file->mode); + do_chmod(fname, file->mode, 0); if (need_retouch_dir_times) { STRUCT_STAT st; - if (link_stat(fname, &st, 0) == 0 - && cmp_time(st.st_mtime, file->modtime) != 0) - set_modtime(fname, file->modtime, F_MOD_NSEC(file), file->mode); + if (link_stat(fname, &st, 0) == 0 && mtime_differs(&st, file)) { + st.st_mtime = file->modtime; +#ifdef ST_MTIME_NSEC + st.ST_MTIME_NSEC = F_MOD_NSEC_or_0(file); +#endif +#ifdef SUPPORT_FORCE_CHANGE + st.st_mode = file->mode; + st.st_flags = 0; +#endif + set_times(fname, &st); + } } +#ifdef SUPPORT_FORCE_CHANGE + if (force_change && F_FFLAGS(file) & force_change) + undo_make_mutable(fname, F_FFLAGS(file)); +#endif if (counter >= loopchk_limit) { if (allowed_lull) maybe_send_keepalive(time(NULL), MSK_ALLOW_FLUSH); @@ -2110,6 +2414,8 @@ void check_for_finished_files(int itemizing, enum logc ignore_existing = -ignore_existing; ignore_non_existing = -ignore_non_existing; update_only = -update_only; + downdate_only = -downdate_only; + downdate_only = -downdate_only; always_checksum = -always_checksum; size_only = -size_only; append_mode = -append_mode; @@ -2204,17 +2510,21 @@ void generate_files(int f_out, const char *local_name) if (DEBUG_GTE(GENR, 1)) rprintf(FINFO, "generator starting pid=%d\n", (int)getpid()); + if (detect_renamed) { + delayed_bits = bitbag_create(cur_flist->used); + if (!delete_before && !delete_during) + delete_during = -1; + } + if (delete_before && !solo_file && cur_flist->used > 0) do_delete_pass(); if (delete_during == 2) { deldelay_size = BIGPATHBUFLEN * 4; deldelay_buf = new_array(char, deldelay_size); - if (!deldelay_buf) - out_of_memory("delete-delay"); } info_levels[INFO_FLIST] = info_levels[INFO_PROGRESS] = 0; - if (append_mode > 0 || whole_file < 0) + if (append_mode > 0 || detect_renamed || whole_file < 0) whole_file = 0; if (DEBUG_GTE(FLIST, 1)) { rprintf(FINFO, "delta-transmission %s\n", @@ -2223,6 +2533,13 @@ void generate_files(int f_out, const char *local_name) : "enabled"); } + if (use_db) { + if (always_checksum || (append_mode != 1 && protocol_version >= 30)) + db_connect(0); /* Will reset use_db on error. */ + else + use_db = 0; + } + dflt_perms = (ACCESSPERMS & ~orig_umask); do { @@ -2250,10 +2567,11 @@ void generate_files(int f_out, const char *local_name) dirdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)); } else dirdev = MAKEDEV(0, 0); - delete_in_dir(fbuf, fp, &dirdev); + delete_in_dir(fbuf, fp, &dirdev, 0); } else change_local_filter_dir(fbuf, strlen(fbuf), F_DEPTH(fp)); } + upcoming_whole_dir = fp->flags & FLAG_CONTENT_DIR ? 1 : 0; } for (i = cur_flist->low; i <= cur_flist->high; i++) { struct file_struct *file = cur_flist->sorted[i]; @@ -2297,7 +2615,21 @@ void generate_files(int f_out, const char *local_name) } while ((cur_flist = cur_flist->next) != NULL); if (delete_during) - delete_in_dir(NULL, NULL, &dev_zero); + delete_in_dir(NULL, NULL, &dev_zero, 0); + if (detect_renamed) { + if (delete_during < 0) + delete_during = 0; + detect_renamed = 0; + + for (i = -1; (i = bitbag_next_bit(delayed_bits, i)) >= 0; ) { + struct file_struct *file = cur_flist->files[i]; + if (local_name) + strlcpy(fbuf, local_name, sizeof fbuf); + else + f_name(file, fbuf); + recv_generator(fbuf, file, i, itemizing, code, f_out); + } + } phase++; if (DEBUG_GTE(GENR, 1)) rprintf(FINFO, "generate_files phase=%d\n", phase); @@ -2347,6 +2679,12 @@ void generate_files(int f_out, const char *local_name) while (msgdone_cnt == 2) wait_for_receiver(); } + + if (checksum_files) + reset_checksum_cache(started_whole_dir); + + if (use_db) + db_disconnect(True); info_levels[INFO_FLIST] = save_info_flist; info_levels[INFO_PROGRESS] = save_info_progress;