2 * Routines that are exclusive to the generator process.
4 * Copyright (C) 1996-2000 Andrew Tridgell
5 * Copyright (C) 1996 Paul Mackerras
6 * Copyright (C) 2002 Martin Pool <mbp@samba.org>
7 * Copyright (C) 2003, 2004, 2005, 2006 Wayne Davison
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
29 extern int stdout_format_has_i;
30 extern int logfile_format_has_i;
34 extern int do_progress;
35 extern int relative_paths;
36 extern int implied_dirs;
37 extern int keep_dirlinks;
38 extern int preserve_links;
39 extern int preserve_devices;
40 extern int preserve_specials;
41 extern int preserve_hard_links;
42 extern int preserve_perms;
43 extern int preserve_uid;
44 extern int preserve_gid;
45 extern int preserve_times;
46 extern int omit_dir_times;
47 extern int delete_mode;
48 extern int delete_before;
49 extern int delete_during;
50 extern int delete_after;
52 extern int ignore_errors;
53 extern int remove_source_files;
54 extern int delay_updates;
55 extern int update_only;
56 extern int ignore_existing;
57 extern int ignore_non_existing;
59 extern int append_mode;
60 extern int make_backups;
61 extern int csum_length;
62 extern int ignore_times;
64 extern OFF_T max_size;
65 extern OFF_T min_size;
67 extern int allowed_lull;
68 extern int sock_f_out;
69 extern int ignore_timeout;
70 extern int protocol_version;
71 extern int fuzzy_basis;
72 extern int always_checksum;
73 extern int checksum_len;
74 extern char *partial_dir;
75 extern char *basis_dir[];
76 extern int compare_dest;
79 extern int whole_file;
81 extern int new_root_dir;
82 extern int read_batch;
83 extern int safe_symlinks;
84 extern long block_size; /* "long" because popt can't set an int32. */
85 extern int max_delete;
86 extern int force_delete;
87 extern int one_file_system;
88 extern struct stats stats;
89 extern dev_t filesystem_dev;
90 extern char *backup_dir;
91 extern char *backup_suffix;
92 extern int backup_suffix_len;
93 extern struct file_list *the_file_list;
94 extern struct filter_list_struct server_filter_list;
96 int ignore_perishable = 0;
97 int non_perishable_cnt = 0;
99 static int deletion_count = 0; /* used to implement --max-delete */
100 static FILE *delete_delay_fp = NULL;
101 static BOOL solo_file = 0;
103 /* For calling delete_item() and delete_dir_contents(). */
104 #define DEL_RECURSE (1<<1) /* recurse */
105 #define DEL_DIR_IS_EMPTY (1<<2) /* internal delete_FUNCTIONS use only */
108 TYPE_DIR, TYPE_SPECIAL, TYPE_DEVICE, TYPE_SYMLINK
112 DR_SUCCESS = 0, DR_FAILURE, DR_AT_LIMIT, DR_NOT_EMPTY
115 /* Forward declaration for delete_item(). */
116 static enum delret delete_dir_contents(char *fname, int flags);
119 static int is_backup_file(char *fn)
121 int k = strlen(fn) - backup_suffix_len;
122 return k > 0 && strcmp(fn+k, backup_suffix) == 0;
125 /* Delete a file or directory. If DEL_RECURSE is set in the flags, this will
126 * delete recursively.
128 * Note that fbuf must point to a MAXPATHLEN buffer if the mode indicates it's
129 * a directory! (The buffer is used for recursion, but returned unchanged.)
131 static enum delret delete_item(char *fbuf, int mode, char *replace, int flags)
138 rprintf(FINFO, "delete_item(%s) mode=%o flags=%d\n",
142 if (S_ISDIR(mode) && !(flags & DEL_DIR_IS_EMPTY)) {
143 ignore_perishable = 1;
144 /* If DEL_RECURSE is not set, this just reports emptiness. */
145 ret = delete_dir_contents(fbuf, flags);
146 ignore_perishable = 0;
147 if (ret == DR_NOT_EMPTY || ret == DR_AT_LIMIT)
149 /* OK: try to delete the directory. */
152 if (!replace && max_delete >= 0 && ++deletion_count > max_delete)
157 ok = do_rmdir(fbuf) == 0;
158 } else if (make_backups && (backup_dir || !is_backup_file(fbuf))) {
159 what = "make_backup";
160 ok = make_backup(fbuf);
163 ok = robust_unlink(fbuf) == 0;
168 log_delete(fbuf, mode);
171 if (S_ISDIR(mode) && errno == ENOTEMPTY) {
172 rprintf(FINFO, "cannot delete non-empty directory: %s\n",
175 } else if (errno != ENOENT) {
176 rsyserr(FERROR, errno, "delete_file: %s(%s) failed",
186 if (replace && ret != DR_SUCCESS) {
187 rprintf(FERROR, "could not make way for new %s: %s\n",
193 /* The directory is about to be deleted: if DEL_RECURSE is given, delete all
194 * its contents, otherwise just checks for content. Returns DR_SUCCESS or
195 * DR_NOT_EMPTY. Note that fname must point to a MAXPATHLEN buffer! (The
196 * buffer is used for recursion, but returned unchanged.)
198 static enum delret delete_dir_contents(char *fname, int flags)
200 struct file_list *dirlist;
208 rprintf(FINFO, "delete_dir_contents(%s) flags=%d\n",
212 dlen = strlen(fname);
213 save_filters = push_local_filters(fname, dlen);
215 non_perishable_cnt = 0;
216 dirlist = get_dirlist(fname, dlen, 0);
217 ret = non_perishable_cnt ? DR_NOT_EMPTY : DR_SUCCESS;
222 if (!(flags & DEL_RECURSE)) {
228 if (dlen != 1 || *fname != '/')
230 remainder = MAXPATHLEN - (p - fname);
232 /* We do our own recursion, so make delete_item() non-recursive. */
233 flags = (flags & ~DEL_RECURSE) | DEL_DIR_IS_EMPTY;
235 for (j = dirlist->count; j--; ) {
236 struct file_struct *fp = dirlist->files[j];
238 if (fp->flags & FLAG_MOUNT_DIR) {
241 "mount point, %s, pins parent directory\n",
248 strlcpy(p, F_BASENAME(fp), remainder);
249 /* Save stack by recursing to ourself directly. */
250 if (S_ISDIR(fp->mode)
251 && delete_dir_contents(fname, flags | DEL_RECURSE) != DR_SUCCESS)
253 if (delete_item(fname, fp->mode, NULL, flags) != DR_SUCCESS)
261 pop_local_filters(save_filters);
263 if (ret == DR_NOT_EMPTY) {
264 rprintf(FINFO, "cannot delete non-empty directory: %s\n",
270 static void start_delete_temp(void)
272 char fnametmp[MAXPATHLEN];
273 int fd, save_dry_run = dry_run;
276 if (!get_tmpname(fnametmp, "deldelay")
277 || (fd = do_mkstemp(fnametmp, 0600)) < 0
278 || !(delete_delay_fp = fdopen(fd, "w+"))) {
279 rprintf(FERROR, "Unable to create delete-delay temp file.\n");
280 exit_cleanup(RERR_FILEIO);
282 dry_run = save_dry_run;
286 static int read_delay_line(FILE *fp, char *buf, int bsize)
290 if ((ch = fgetc(fp)) == EOF)
296 if (ch > '7' || ch < '0') {
297 rprintf(FERROR, "invalid data in delete-delay file.\n");
298 exit_cleanup(RERR_FILEIO);
300 mode = mode*8 + ch - '0';
301 if ((ch = fgetc(fp)) == EOF) {
303 rprintf(FERROR, "unexpected EOF in delete-delay file.\n");
304 exit_cleanup(RERR_FILEIO);
309 if ((ch = fgetc(fp)) == EOF)
312 rprintf(FERROR, "filename too long in delete-delay file.\n");
313 exit_cleanup(RERR_FILEIO);
323 static void delayed_deletions(char *delbuf)
327 fseek(delete_delay_fp, 0, 0);
328 while ((mode = read_delay_line(delete_delay_fp, delbuf, MAXPATHLEN)) >= 0)
329 delete_item(delbuf, mode, NULL, DEL_RECURSE);
330 fclose(delete_delay_fp);
333 /* This function is used to implement per-directory deletion, and is used by
334 * all the --delete-WHEN options. Note that the fbuf pointer must point to a
335 * MAXPATHLEN buffer with the name of the directory in it (the functions we
336 * call will append names onto the end, but the old dir value will be restored
338 static void delete_in_dir(struct file_list *flist, char *fbuf,
339 struct file_struct *file, STRUCT_STAT *stp)
341 static int min_depth = MAXPATHLEN, cur_depth = -1;
342 static void *filt_array[MAXPATHLEN/2+1];
343 static int already_warned = 0;
344 struct file_list *dirlist;
345 char delbuf[MAXPATHLEN];
349 while (cur_depth >= min_depth)
350 pop_local_filters(filt_array[cur_depth--]);
351 min_depth = MAXPATHLEN;
357 rprintf(FINFO, "delete_in_dir(%s)\n", fbuf);
360 maybe_send_keepalive();
362 if (file->dir.depth >= MAXPATHLEN/2+1)
363 return; /* Impossible... */
365 if (io_error && !(lp_ignore_errors(module_id) || ignore_errors)) {
369 "IO error encountered -- skipping file deletion\n");
374 while (cur_depth >= file->dir.depth && cur_depth >= min_depth)
375 pop_local_filters(filt_array[cur_depth--]);
376 cur_depth = file->dir.depth;
377 if (min_depth > cur_depth)
378 min_depth = cur_depth;
380 filt_array[cur_depth] = push_local_filters(fbuf, dlen);
382 if (one_file_system) {
383 if (file->flags & FLAG_TOP_DIR)
384 filesystem_dev = stp->st_dev;
385 else if (filesystem_dev != stp->st_dev)
389 dirlist = get_dirlist(fbuf, dlen, 0);
391 /* If an item in dirlist is not found in flist, delete it
392 * from the filesystem. */
393 for (i = dirlist->count; i--; ) {
394 struct file_struct *fp = dirlist->files[i];
395 if (!F_IS_ACTIVE(fp))
397 if (fp->flags & FLAG_MOUNT_DIR) {
399 rprintf(FINFO, "cannot delete mount point: %s\n",
403 if (flist_find(flist, fp) < 0) {
406 fprintf(delete_delay_fp, "%o %s%c", (short)fp->mode, delbuf, '\0');
408 delete_item(delbuf, fp->mode, NULL, DEL_RECURSE);
415 /* This deletes any files on the receiving side that are not present on the
416 * sending side. This is used by --delete-before and --delete-after. */
417 static void do_delete_pass(struct file_list *flist)
419 char fbuf[MAXPATHLEN];
423 /* dry_run is incremented when the destination doesn't exist yet. */
424 if (dry_run > 1 || list_only)
427 for (j = 0; j < flist->count; j++) {
428 struct file_struct *file = flist->files[j];
430 if (!(file->flags & FLAG_XFER_DIR))
434 if (verbose > 1 && file->flags & FLAG_TOP_DIR)
435 rprintf(FINFO, "deleting in %s\n", fbuf);
437 if (link_stat(fbuf, &st, keep_dirlinks) < 0
438 || !S_ISDIR(st.st_mode))
441 delete_in_dir(flist, fbuf, file, &st);
443 delete_in_dir(NULL, NULL, NULL, NULL);
445 if (do_progress && !am_server)
446 rprintf(FINFO, " \r");
449 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
452 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
455 if (am_root && preserve_uid && st->st_uid != F_UID(file))
458 if (preserve_gid && F_GID(file) != GID_NONE && st->st_gid != F_GID(file))
464 void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
465 int32 iflags, uchar fnamecmp_type, const char *xname)
467 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
468 int keep_time = !preserve_times ? 0
469 : S_ISDIR(file->mode) ? !omit_dir_times
470 : !S_ISLNK(file->mode);
472 if (S_ISREG(file->mode) && F_LENGTH(file) != st->st_size)
473 iflags |= ITEM_REPORT_SIZE;
474 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
475 && !(iflags & ITEM_MATCHED)
476 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
477 || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
478 iflags |= ITEM_REPORT_TIME;
479 if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
480 iflags |= ITEM_REPORT_PERMS;
481 if (preserve_uid && am_root && F_UID(file) != st->st_uid)
482 iflags |= ITEM_REPORT_OWNER;
483 if (preserve_gid && F_GID(file) != GID_NONE
484 && st->st_gid != F_GID(file))
485 iflags |= ITEM_REPORT_GROUP;
487 iflags |= ITEM_IS_NEW;
490 if ((iflags & SIGNIFICANT_ITEM_FLAGS || verbose > 1
491 || stdout_format_has_i > 1 || (xname && *xname)) && !read_batch) {
492 if (protocol_version >= 29) {
494 write_int(sock_f_out, ndx);
495 write_shortint(sock_f_out, iflags);
496 if (iflags & ITEM_BASIS_TYPE_FOLLOWS)
497 write_byte(sock_f_out, fnamecmp_type);
498 if (iflags & ITEM_XNAME_FOLLOWS)
499 write_vstring(sock_f_out, xname, strlen(xname));
500 } else if (ndx >= 0) {
501 enum logcode code = logfile_format_has_i ? FINFO : FCLIENT;
502 log_item(code, file, &stats, iflags, xname);
508 /* Perform our quick-check heuristic for determining if a file is unchanged. */
509 int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
511 if (st->st_size != F_LENGTH(file))
514 /* if always checksum is set then we use the checksum instead
515 of the file time to determine whether to sync */
516 if (always_checksum && S_ISREG(st->st_mode)) {
517 char sum[MD4_SUM_LENGTH];
518 file_checksum(fn, sum, st->st_size);
519 return memcmp(sum, F_SUM(file), checksum_len) == 0;
528 return cmp_time(st->st_mtime, file->modtime) == 0;
533 * set (initialize) the size entries in the per-file sum_struct
534 * calculating dynamic block and checksum sizes.
536 * This is only called from generate_and_send_sums() but is a separate
537 * function to encapsulate the logic.
539 * The block size is a rounded square root of file length.
541 * The checksum size is determined according to:
542 * blocksum_bits = BLOCKSUM_BIAS + 2*log2(file_len) - log2(block_len)
543 * provided by Donovan Baarda which gives a probability of rsync
544 * algorithm corrupting data and falling back using the whole md4
547 * This might be made one of several selectable heuristics.
549 static void sum_sizes_sqroot(struct sum_struct *sum, int64 len)
555 blength = block_size;
556 else if (len <= BLOCK_SIZE * BLOCK_SIZE)
557 blength = BLOCK_SIZE;
562 for (c = 1, l = len, cnt = 0; l >>= 2; c <<= 1, cnt++) {}
563 if (cnt >= 31 || c >= MAX_BLOCK_SIZE)
564 blength = MAX_BLOCK_SIZE;
569 if (len < (int64)blength * blength)
572 } while (c >= 8); /* round to multiple of 8 */
573 blength = MAX(blength, BLOCK_SIZE);
577 if (protocol_version < 27) {
578 s2length = csum_length;
579 } else if (csum_length == SUM_LENGTH) {
580 s2length = SUM_LENGTH;
584 int b = BLOCKSUM_BIAS;
585 for (l = len; l >>= 1; b += 2) {}
586 for (c = blength; (c >>= 1) && b; b--) {}
587 /* add a bit, subtract rollsum, round up. */
588 s2length = (b + 1 - 32 + 7) / 8; /* --optimize in compiler-- */
589 s2length = MAX(s2length, csum_length);
590 s2length = MIN(s2length, SUM_LENGTH);
594 sum->blength = blength;
595 sum->s2length = s2length;
596 sum->remainder = (int32)(len % blength);
597 sum->count = (int32)(len / blength) + (sum->remainder != 0);
599 if (sum->count && verbose > 2) {
601 "count=%.0f rem=%ld blength=%ld s2length=%d flength=%.0f\n",
602 (double)sum->count, (long)sum->remainder, (long)sum->blength,
603 sum->s2length, (double)sum->flength);
609 * Generate and send a stream of signatures/checksums that describe a buffer
611 * Generate approximately one checksum every block_len bytes.
613 static void generate_and_send_sums(int fd, OFF_T len, int f_out, int f_copy)
616 struct map_struct *mapbuf;
617 struct sum_struct sum;
620 sum_sizes_sqroot(&sum, len);
621 write_sum_head(f_out, &sum);
623 if (append_mode > 0 && f_copy < 0)
627 mapbuf = map_file(fd, len, MAX_MAP_SIZE, sum.blength);
631 for (i = 0; i < sum.count; i++) {
632 int32 n1 = (int32)MIN(len, (OFF_T)sum.blength);
633 char *map = map_ptr(mapbuf, offset, n1);
634 char sum2[SUM_LENGTH];
641 full_write(f_copy, map, n1);
646 sum1 = get_checksum1(map, n1);
647 get_checksum2(map, n1, sum2);
651 "chunk[%.0f] offset=%.0f len=%ld sum1=%08lx\n",
652 (double)i, (double)offset - n1, (long)n1,
653 (unsigned long)sum1);
655 write_int(f_out, sum1);
656 write_buf(f_out, sum2, sum.s2length);
664 /* Try to find a filename in the same dir as "fname" with a similar name. */
665 static int find_fuzzy(struct file_struct *file, struct file_list *dirlist)
667 int fname_len, fname_suf_len;
668 const char *fname_suf, *fname = F_BASENAME(file);
669 uint32 lowest_dist = 25 << 16; /* ignore a distance greater than 25 */
670 int j, lowest_j = -1;
672 fname_len = strlen(fname);
673 fname_suf = find_filename_suffix(fname, fname_len, &fname_suf_len);
675 for (j = 0; j < dirlist->count; j++) {
676 struct file_struct *fp = dirlist->files[j];
677 const char *suf, *name;
681 if (!S_ISREG(fp->mode) || !F_LENGTH(fp) || fp->flags & FLAG_SENT)
684 name = F_BASENAME(fp);
686 if (F_LENGTH(fp) == F_LENGTH(file)
687 && cmp_time(fp->modtime, file->modtime) == 0) {
690 "fuzzy size/modtime match for %s\n",
697 suf = find_filename_suffix(name, len, &suf_len);
699 dist = fuzzy_distance(name, len, fname, fname_len);
700 /* Add some extra weight to how well the suffixes match. */
701 dist += fuzzy_distance(suf, suf_len, fname_suf, fname_suf_len)
704 rprintf(FINFO, "fuzzy distance for %s = %d.%05d\n",
705 name, (int)(dist>>16), (int)(dist&0xFFFF));
707 if (dist <= lowest_dist) {
716 #ifdef SUPPORT_HARD_LINKS
717 void check_for_finished_hlinks(int itemizing, enum logcode code)
719 struct file_struct *file;
722 while ((ndx = get_hlink_num()) != -1) {
723 if (ndx < 0 || ndx >= the_file_list->count)
726 file = the_file_list->files[ndx];
727 if (!F_IS_HLINKED(file))
730 hard_link_cluster(file, ndx, itemizing, code, -1);
735 /* This is only called for regular files. We return -2 if we've finished
736 * handling the file, -1 if no dest-linking occurred, or a non-negative
737 * value if we found an alternate basis file. */
738 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
739 char *cmpbuf, STRUCT_STAT *stp, int itemizing,
740 int maybe_ATTRS_REPORT, enum logcode code)
747 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
748 if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
750 switch (match_level) {
756 if (!unchanged_file(cmpbuf, file, stp))
762 if (!unchanged_attrs(file, stp))
764 if (always_checksum && preserve_times
765 && cmp_time(stp->st_mtime, file->modtime))
772 } while (basis_dir[++j] != NULL);
777 if (j != best_match) {
779 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
780 if (link_stat(cmpbuf, stp, 0) < 0)
784 if (match_level == 3 && !copy_dest) {
785 #ifdef SUPPORT_HARD_LINKS
787 int i = itemizing && (verbose > 1 || stdout_format_has_i > 1);
788 if (hard_link_one(file, ndx, fname, 0, stp,
789 cmpbuf, 1, i, code) < 0)
791 if (preserve_hard_links && F_IS_HLINKED(file))
792 hard_link_cluster(file, ndx, itemizing, code, j);
796 itemize(file, ndx, 0, stp, 0, 0, NULL);
797 if (verbose > 1 && maybe_ATTRS_REPORT) {
798 rprintf(FCLIENT, "%s is uptodate\n", fname);
803 if (match_level >= 2) {
804 try_a_copy: /* Copy the file locally. */
805 if (copy_file(cmpbuf, fname, file->mode) < 0) {
807 rsyserr(FINFO, errno, "copy_file %s => %s",
808 full_fname(cmpbuf), fname);
813 itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
814 set_file_attrs(fname, file, NULL, 0);
815 if (maybe_ATTRS_REPORT
816 && ((!itemizing && verbose && match_level == 2)
817 || (verbose > 1 && match_level == 3))) {
818 code = match_level == 3 ? FCLIENT : FINFO;
819 rprintf(code, "%s%s\n", fname,
820 match_level == 3 ? " is uptodate" : "");
822 #ifdef SUPPORT_HARD_LINKS
823 if (preserve_hard_links && F_IS_HLINKED(file))
824 hard_link_cluster(file, ndx, itemizing, code, j);
829 return FNAMECMP_BASIS_DIR_LOW + j;
832 /* This is only called for non-regular files. We return -2 if we've finished
833 * handling the file, or -1 if no dest-linking occurred, or a non-negative
834 * value if we found an alternate basis file. */
835 static int try_dests_non(struct file_struct *file, char *fname, int ndx,
836 char *cmpbuf, STRUCT_STAT *stp, int itemizing,
837 int maybe_ATTRS_REPORT, enum logcode code)
839 char lnk[MAXPATHLEN];
843 enum nonregtype type;
846 #ifndef SUPPORT_LINKS
847 if (S_ISLNK(file->mode))
850 if (S_ISDIR(file->mode)) {
852 } else if (IS_SPECIAL(file->mode))
854 else if (IS_DEVICE(file->mode))
857 else if (S_ISLNK(file->mode))
862 "internal: try_dests_non() called with invalid mode (%o)\n",
864 exit_cleanup(RERR_UNSUPPORTED);
868 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
869 if (link_stat(cmpbuf, stp, 0) < 0)
873 if (!S_ISDIR(stp->st_mode))
877 if (!IS_SPECIAL(stp->st_mode))
881 if (!IS_DEVICE(stp->st_mode))
886 if (!S_ISLNK(stp->st_mode))
891 if (match_level < 1) {
900 devp = F_RDEV_P(file);
901 if (stp->st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)))
906 if ((len = readlink(cmpbuf, lnk, MAXPATHLEN-1)) <= 0)
909 if (strcmp(lnk, F_SYMLINK(file)) != 0)
914 if (match_level < 2) {
918 if (unchanged_attrs(file, stp)) {
923 } while (basis_dir[++j] != NULL);
928 if (j != best_match) {
930 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
931 if (link_stat(cmpbuf, stp, 0) < 0)
935 if (match_level == 3) {
936 #ifdef SUPPORT_HARD_LINKS
938 #ifndef CAN_HARDLINK_SYMLINK
939 && !S_ISLNK(file->mode)
941 #ifndef CAN_HARDLINK_SPECIAL
942 && !IS_SPECIAL(file->mode) && !IS_DEVICE(file->mode)
944 && !S_ISDIR(file->mode)) {
945 if (do_link(cmpbuf, fname) < 0) {
946 rsyserr(FERROR, errno,
947 "failed to hard-link %s with %s",
951 if (preserve_hard_links && F_IS_HLINKED(file))
952 hard_link_cluster(file, ndx, itemizing, code, -1);
956 if (itemizing && stdout_format_has_i
957 && (verbose > 1 || stdout_format_has_i > 1)) {
958 int chg = compare_dest && type != TYPE_DIR ? 0
960 + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0);
961 char *lp = match_level == 3 ? "" : NULL;
962 itemize(file, ndx, 0, stp, chg + ITEM_MATCHED, 0, lp);
964 if (verbose > 1 && maybe_ATTRS_REPORT) {
965 rprintf(FCLIENT, "%s%s is uptodate\n",
966 fname, type == TYPE_DIR ? "/" : "");
974 static int phase = 0;
976 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
977 * make sure it exists, and has the right permissions/timestamp info. For
978 * all other non-regular files (symlinks, etc.) we create them here. For
979 * regular files that have changed, we try to find a basis file and then
980 * start sending checksums.
982 * When fname is non-null, it must point to a MAXPATHLEN buffer!
984 * Note that f_out is set to -1 when doing final directory-permission and
985 * modification-time repair. */
986 static void recv_generator(char *fname, struct file_struct *file, int ndx,
987 int itemizing, int maybe_ATTRS_REPORT,
988 enum logcode code, int f_out)
990 static int missing_below = -1, excluded_below = -1;
991 static const char *parent_dirname = "";
992 static struct file_list *fuzzy_dirlist = NULL;
993 static int need_fuzzy_dirlist = 0;
994 struct file_struct *fuzzy_file = NULL;
995 int fd = -1, f_copy = -1;
996 STRUCT_STAT st, real_st, partial_st;
997 struct file_struct *back_file = NULL;
998 int statret, real_ret, stat_errno;
999 char *fnamecmp, *partialptr, *backupptr = NULL;
1000 char fnamecmpbuf[MAXPATHLEN];
1001 uchar fnamecmp_type;
1002 int del_opts = delete_mode || force_delete ? DEL_RECURSE : 0;
1008 if (fuzzy_dirlist) {
1009 flist_free(fuzzy_dirlist);
1010 fuzzy_dirlist = NULL;
1012 if (missing_below >= 0) {
1017 parent_dirname = "";
1022 rprintf(FINFO, "recv_generator(%s,%d)\n", fname, ndx);
1024 if (server_filter_list.head) {
1025 if (excluded_below >= 0) {
1026 if (file->dir.depth > excluded_below)
1028 excluded_below = -1;
1030 if (check_filter(&server_filter_list, fname,
1031 S_ISDIR(file->mode)) < 0) {
1032 if (S_ISDIR(file->mode))
1033 excluded_below = file->dir.depth;
1037 "skipping server-excluded file \"%s\"\n",
1044 if (missing_below >= 0) {
1045 if (file->dir.depth <= missing_below) {
1049 } else if (!dry_run)
1054 stat_errno = ENOENT;
1056 const char *dn = file->dirname ? file->dirname : ".";
1057 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1058 if (relative_paths && !implied_dirs
1059 && do_stat(dn, &st) < 0
1060 && create_directory_path(fname) < 0) {
1061 rsyserr(FERROR, errno,
1062 "recv_generator: mkdir %s failed",
1065 if (fuzzy_dirlist) {
1066 flist_free(fuzzy_dirlist);
1067 fuzzy_dirlist = NULL;
1070 need_fuzzy_dirlist = 1;
1072 parent_dirname = dn;
1074 if (need_fuzzy_dirlist && S_ISREG(file->mode)) {
1075 strlcpy(fnamecmpbuf, dn, sizeof fnamecmpbuf);
1076 fuzzy_dirlist = get_dirlist(fnamecmpbuf, -1, 1);
1077 need_fuzzy_dirlist = 0;
1080 statret = link_stat(fname, &st,
1081 keep_dirlinks && S_ISDIR(file->mode));
1085 if (ignore_non_existing && statret == -1 && stat_errno == ENOENT) {
1087 rprintf(FINFO, "not creating new %s \"%s\"\n",
1088 S_ISDIR(file->mode) ? "directory" : "file",
1094 /* If we're not preserving permissions, change the file-list's
1095 * mode based on the local permissions and some heuristics. */
1096 if (!preserve_perms) {
1097 int exists = statret == 0
1098 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1099 file->mode = dest_mode(file->mode, st.st_mode, exists);
1102 if (S_ISDIR(file->mode)) {
1103 /* The file to be received is a directory, so we need
1104 * to prepare appropriately. If there is already a
1105 * file of that name and it is *not* a directory, then
1106 * we need to delete it. If it doesn't exist, then
1107 * (perhaps recursively) create it. */
1108 if (statret == 0 && !S_ISDIR(st.st_mode)) {
1109 if (delete_item(fname, st.st_mode, "directory", del_opts) != 0)
1113 if (dry_run && statret != 0 && missing_below < 0) {
1114 missing_below = file->dir.depth;
1120 if (*fname == '.' && fname[1] == '\0')
1124 if (statret != 0 && basis_dir[0] != NULL) {
1125 int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1126 itemizing, maybe_ATTRS_REPORT, code);
1133 if (itemizing && f_out != -1) {
1134 itemize(file, ndx, statret, &st,
1135 statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1137 if (real_ret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1138 if (!relative_paths || errno != ENOENT
1139 || create_directory_path(fname) < 0
1140 || (do_mkdir(fname, file->mode) < 0 && errno != EEXIST)) {
1141 rsyserr(FERROR, errno,
1142 "recv_generator: mkdir %s failed",
1144 file->flags |= FLAG_MISSING_DIR;
1145 if (ndx+1 < the_file_list->count
1146 && the_file_list->files[ndx+1]->dir.depth > file->dir.depth) {
1148 "*** Skipping everything below this failed directory ***\n");
1149 missing_below = file->dir.depth;
1154 if (set_file_attrs(fname, file, real_ret ? NULL : &real_st, 0)
1155 && verbose && code != FNONE && f_out != -1)
1156 rprintf(code, "%s/\n", fname);
1157 if (real_ret != 0 && one_file_system)
1158 real_st.st_dev = filesystem_dev;
1159 if (delete_during && f_out != -1 && !phase && dry_run < 2
1160 && (file->flags & FLAG_XFER_DIR))
1161 delete_in_dir(the_file_list, fname, file, &real_st);
1165 #ifdef SUPPORT_HARD_LINKS
1166 if (preserve_hard_links && F_IS_HLINKED(file)
1167 && hard_link_check(file, ndx, fname, statret, &st,
1168 itemizing, code, HL_CHECK_MASTER))
1172 if (preserve_links && S_ISLNK(file->mode)) {
1173 #ifdef SUPPORT_LINKS
1174 const char *sl = F_SYMLINK(file);
1175 if (safe_symlinks && unsafe_symlink(sl, fname)) {
1178 fname = f_name(file, NULL);
1180 "ignoring unsafe symlink %s -> \"%s\"\n",
1181 full_fname(fname), sl);
1186 char lnk[MAXPATHLEN];
1189 if (!S_ISLNK(st.st_mode))
1191 else if ((len = readlink(fname, lnk, MAXPATHLEN-1)) > 0
1192 && strncmp(lnk, sl, len) == 0 && sl[len] == '\0') {
1193 /* The link is pointing to the right place. */
1195 itemize(file, ndx, 0, &st, 0, 0, NULL);
1196 set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1197 #ifdef SUPPORT_HARD_LINKS
1198 if (preserve_hard_links && F_IS_HLINKED(file))
1199 hard_link_cluster(file, ndx, itemizing, code, -1);
1201 if (remove_source_files == 1)
1202 goto return_with_success;
1205 /* Not the right symlink (or not a symlink), so
1207 if (delete_item(fname, st.st_mode, "symlink", del_opts) != 0)
1209 } else if (basis_dir[0] != NULL) {
1210 int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1211 itemizing, maybe_ATTRS_REPORT, code);
1213 #ifndef CAN_HARDLINK_SYMLINK
1215 /* Resort to --copy-dest behavior. */
1225 #ifdef SUPPORT_HARD_LINKS
1226 if (preserve_hard_links && F_IS_HLINKED(file)
1227 && hard_link_check(file, ndx, fname, -1, &st,
1228 itemizing, code, HL_SKIP))
1231 if (do_symlink(sl, fname) != 0) {
1232 rsyserr(FERROR, errno, "symlink %s -> \"%s\" failed",
1233 full_fname(fname), sl);
1235 set_file_attrs(fname, file, NULL, 0);
1237 itemize(file, ndx, statret, &st,
1238 ITEM_LOCAL_CHANGE, 0, NULL);
1240 if (code != FNONE && verbose)
1241 rprintf(code, "%s -> %s\n", fname, sl);
1242 #ifdef SUPPORT_HARD_LINKS
1243 if (preserve_hard_links && F_IS_HLINKED(file))
1244 hard_link_cluster(file, ndx, itemizing, code, -1);
1246 /* This does not check remove_source_files == 1
1247 * because this is one of the items that the old
1248 * --remove-sent-files option would remove. */
1249 if (remove_source_files)
1250 goto return_with_success;
1256 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1257 || (preserve_specials && IS_SPECIAL(file->mode))) {
1258 uint32 *devp = F_RDEV_P(file);
1259 dev_t rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp));
1262 if (IS_DEVICE(file->mode)) {
1263 if (!IS_DEVICE(st.st_mode))
1267 if (!IS_SPECIAL(st.st_mode))
1272 && (st.st_mode & ~CHMOD_BITS) == (file->mode & ~CHMOD_BITS)
1273 && st.st_rdev == rdev) {
1274 /* The device or special file is identical. */
1276 itemize(file, ndx, 0, &st, 0, 0, NULL);
1277 set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1278 #ifdef SUPPORT_HARD_LINKS
1279 if (preserve_hard_links && F_IS_HLINKED(file))
1280 hard_link_cluster(file, ndx, itemizing, code, -1);
1282 if (remove_source_files == 1)
1283 goto return_with_success;
1286 if (delete_item(fname, st.st_mode, t, del_opts) != 0)
1288 } else if (basis_dir[0] != NULL) {
1289 int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1290 itemizing, maybe_ATTRS_REPORT, code);
1292 #ifndef CAN_HARDLINK_SPECIAL
1294 /* Resort to --copy-dest behavior. */
1304 #ifdef SUPPORT_HARD_LINKS
1305 if (preserve_hard_links && F_IS_HLINKED(file)
1306 && hard_link_check(file, ndx, fname, -1, &st,
1307 itemizing, code, HL_SKIP))
1311 rprintf(FINFO, "mknod(%s, 0%o, [%ld,%ld])\n",
1312 fname, (int)file->mode,
1313 (long)major(rdev), (long)minor(rdev));
1315 if (do_mknod(fname, file->mode, rdev) < 0) {
1316 rsyserr(FERROR, errno, "mknod %s failed",
1319 set_file_attrs(fname, file, NULL, 0);
1321 itemize(file, ndx, statret, &st,
1322 ITEM_LOCAL_CHANGE, 0, NULL);
1324 if (code != FNONE && verbose)
1325 rprintf(code, "%s\n", fname);
1326 #ifdef SUPPORT_HARD_LINKS
1327 if (preserve_hard_links && F_IS_HLINKED(file))
1328 hard_link_cluster(file, ndx, itemizing, code, -1);
1330 if (remove_source_files == 1)
1331 goto return_with_success;
1336 if (!S_ISREG(file->mode)) {
1338 fname = f_name(file, NULL);
1339 rprintf(FINFO, "skipping non-regular file \"%s\"\n", fname);
1343 if (max_size && F_LENGTH(file) > max_size) {
1346 fname = f_name(file, NULL);
1347 rprintf(FINFO, "%s is over max-size\n", fname);
1351 if (min_size && F_LENGTH(file) < min_size) {
1354 fname = f_name(file, NULL);
1355 rprintf(FINFO, "%s is under min-size\n", fname);
1360 if (ignore_existing && statret == 0) {
1362 rprintf(FINFO, "%s exists\n", fname);
1366 if (update_only && statret == 0
1367 && cmp_time(st.st_mtime, file->modtime) > 0) {
1369 rprintf(FINFO, "%s is newer\n", fname);
1374 fnamecmp_type = FNAMECMP_FNAME;
1376 if (statret == 0 && !S_ISREG(st.st_mode)) {
1377 if (delete_item(fname, st.st_mode, "regular file", del_opts) != 0)
1380 stat_errno = ENOENT;
1383 if (statret != 0 && basis_dir[0] != NULL) {
1384 int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1385 itemizing, maybe_ATTRS_REPORT, code);
1387 if (remove_source_files == 1)
1388 goto return_with_success;
1392 fnamecmp = fnamecmpbuf;
1401 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1402 && link_stat(partialptr, &partial_st, 0) == 0
1403 && S_ISREG(partial_st.st_mode)) {
1405 goto prepare_to_open;
1409 if (statret != 0 && fuzzy_dirlist && dry_run <= 1) {
1410 int j = find_fuzzy(file, fuzzy_dirlist);
1412 fuzzy_file = fuzzy_dirlist->files[j];
1413 f_name(fuzzy_file, fnamecmpbuf);
1415 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1416 fname, fnamecmpbuf);
1418 st.st_size = F_LENGTH(fuzzy_file);
1420 fnamecmp = fnamecmpbuf;
1421 fnamecmp_type = FNAMECMP_FUZZY;
1426 #ifdef SUPPORT_HARD_LINKS
1427 if (preserve_hard_links && F_IS_HLINKED(file)
1428 && hard_link_check(file, ndx, fname, statret, &st,
1429 itemizing, code, HL_SKIP))
1432 if (stat_errno == ENOENT)
1434 rsyserr(FERROR, stat_errno, "recv_generator: failed to stat %s",
1439 if (append_mode && st.st_size > F_LENGTH(file))
1442 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
1444 else if (fnamecmp_type == FNAMECMP_FUZZY)
1446 else if (unchanged_file(fnamecmp, file, &st)) {
1448 do_unlink(partialptr);
1449 handle_partial_dir(partialptr, PDIR_DELETE);
1452 itemize(file, ndx, real_ret, &real_st,
1455 set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1456 #ifdef SUPPORT_HARD_LINKS
1457 if (preserve_hard_links && F_IS_HLINKED(file))
1458 hard_link_cluster(file, ndx, itemizing, code, -1);
1460 if (remove_source_files != 1)
1462 return_with_success:
1464 send_msg_int(MSG_SUCCESS, ndx);
1471 fnamecmp = partialptr;
1472 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
1476 if (!do_xfers || read_batch || whole_file)
1479 if (fuzzy_dirlist) {
1480 int j = flist_find(fuzzy_dirlist, file);
1481 if (j >= 0) /* don't use changing file as future fuzzy basis */
1482 fuzzy_dirlist->files[j]->flags |= FLAG_SENT;
1486 fd = do_open(fnamecmp, O_RDONLY, 0);
1489 rsyserr(FERROR, errno, "failed to open %s, continuing",
1490 full_fname(fnamecmp));
1492 /* pretend the file didn't exist */
1493 #ifdef SUPPORT_HARD_LINKS
1494 if (preserve_hard_links && F_IS_HLINKED(file)
1495 && hard_link_check(file, ndx, fname, statret, &st,
1496 itemizing, code, HL_SKIP))
1499 statret = real_ret = -1;
1503 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
1504 if (!(backupptr = get_backup_name(fname))) {
1508 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
1510 goto pretend_missing;
1512 if (robust_unlink(backupptr) && errno != ENOENT) {
1513 rsyserr(FERROR, errno, "unlink %s",
1514 full_fname(backupptr));
1515 unmake_file(back_file);
1519 if ((f_copy = do_open(backupptr,
1520 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
1521 rsyserr(FERROR, errno, "open %s",
1522 full_fname(backupptr));
1523 unmake_file(back_file);
1527 fnamecmp_type = FNAMECMP_BACKUP;
1531 rprintf(FINFO, "gen mapped %s of size %.0f\n",
1532 fnamecmp, (double)st.st_size);
1536 rprintf(FINFO, "generating and sending sums for %d\n", ndx);
1539 if (remove_source_files && !delay_updates && !phase)
1540 increment_active_files(ndx, itemizing, code);
1541 write_int(f_out, ndx);
1543 int iflags = ITEM_TRANSFER;
1544 if (always_checksum)
1545 iflags |= ITEM_REPORT_CHECKSUM;
1546 if (fnamecmp_type != FNAMECMP_FNAME)
1547 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
1548 if (fnamecmp_type == FNAMECMP_FUZZY)
1549 iflags |= ITEM_XNAME_FOLLOWS;
1550 itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
1551 fuzzy_file ? F_BASENAME(fuzzy_file) : NULL);
1555 #ifdef SUPPORT_HARD_LINKS
1556 if (preserve_hard_links && F_IS_HLINKED(file))
1557 hard_link_cluster(file, ndx, itemizing, code, -1);
1564 if (statret != 0 || whole_file) {
1565 write_sum_head(f_out, NULL);
1569 generate_and_send_sums(fd, st.st_size, f_out, f_copy);
1573 set_file_attrs(backupptr, back_file, NULL, 0);
1575 rprintf(FINFO, "backed up %s to %s\n",
1578 unmake_file(back_file);
1584 void generate_files(int f_out, struct file_list *flist, char *local_name)
1587 char fbuf[MAXPATHLEN];
1588 int itemizing, maybe_ATTRS_REPORT;
1590 int lull_mod = allowed_lull * 5;
1591 int need_retouch_dir_times = preserve_times && !omit_dir_times;
1592 int need_retouch_dir_perms = 0;
1593 int save_ignore_existing = ignore_existing;
1594 int save_ignore_non_existing = ignore_non_existing;
1595 int save_do_progress = do_progress;
1596 int save_make_backups = make_backups;
1597 int dir_tweaking = !(list_only || local_name || dry_run);
1599 if (protocol_version >= 29) {
1601 maybe_ATTRS_REPORT = stdout_format_has_i ? 0 : ATTRS_REPORT;
1602 code = logfile_format_has_i ? FNONE : FLOG;
1603 } else if (am_daemon) {
1604 itemizing = logfile_format_has_i && do_xfers;
1605 maybe_ATTRS_REPORT = ATTRS_REPORT;
1606 code = itemizing || !do_xfers ? FCLIENT : FINFO;
1607 } else if (!am_server) {
1608 itemizing = stdout_format_has_i;
1609 maybe_ATTRS_REPORT = stdout_format_has_i ? 0 : ATTRS_REPORT;
1610 code = itemizing ? FNONE : FINFO;
1613 maybe_ATTRS_REPORT = ATTRS_REPORT;
1618 rprintf(FINFO, "generator starting pid=%ld count=%d\n",
1619 (long)getpid(), flist->count);
1622 if (delete_before && !local_name && flist->count > 0)
1623 do_delete_pass(flist);
1624 if (delete_during == 2)
1625 start_delete_temp();
1628 if (append_mode || whole_file < 0)
1631 rprintf(FINFO, "delta-transmission %s\n",
1633 ? "disabled for local transfer or --whole-file"
1637 /* Since we often fill up the outgoing socket and then just sit around
1638 * waiting for the other 2 processes to do their thing, we don't want
1639 * to exit on a timeout. If the data stops flowing, the receiver will
1640 * notice that and let us know via the redo pipe (or its closing). */
1643 for (i = 0; i < flist->count; i++) {
1644 struct file_struct *file = flist->files[i];
1646 if (!F_IS_ACTIVE(file))
1650 strlcpy(fbuf, local_name, sizeof fbuf);
1653 recv_generator(fbuf, file, i, itemizing, maybe_ATTRS_REPORT,
1656 /* We need to ensure that any dirs we create have writeable
1657 * permissions during the time we are putting files within
1658 * them. This is then fixed after the transfer is done. */
1660 if (!am_root && S_ISDIR(file->mode) && !(file->mode & S_IWUSR)
1662 mode_t mode = file->mode | S_IWUSR; /* user write */
1663 char *fname = local_name ? local_name : fbuf;
1664 if (do_chmod(fname, mode) < 0) {
1665 rsyserr(FERROR, errno,
1666 "failed to modify permissions on %s",
1669 need_retouch_dir_perms = 1;
1673 #ifdef SUPPORT_HARD_LINKS
1674 if (preserve_hard_links)
1675 check_for_finished_hlinks(itemizing, code);
1678 if (allowed_lull && !(i % lull_mod))
1679 maybe_send_keepalive();
1680 else if (!(i % 200))
1681 maybe_flush_socket();
1683 recv_generator(NULL, NULL, 0, 0, 0, code, -1);
1685 delete_in_dir(NULL, NULL, NULL, NULL);
1688 csum_length = SUM_LENGTH;
1689 max_size = min_size = ignore_existing = ignore_non_existing = 0;
1690 update_only = always_checksum = size_only = 0;
1692 if (append_mode) /* resend w/o append mode */
1693 append_mode = -1; /* ... but only longer files */
1694 make_backups = 0; /* avoid a duplicate backup for inplace processing */
1697 rprintf(FINFO, "generate_files phase=%d\n", phase);
1699 write_int(f_out, NDX_DONE);
1701 /* files can cycle through the system more than once
1702 * to catch initial checksum errors */
1703 while ((i = get_redo_num(itemizing, code)) != -1) {
1704 struct file_struct *file = flist->files[i];
1706 strlcpy(fbuf, local_name, sizeof fbuf);
1709 recv_generator(fbuf, file, i, itemizing, maybe_ATTRS_REPORT,
1714 ignore_non_existing = save_ignore_non_existing;
1715 ignore_existing = save_ignore_existing;
1716 make_backups = save_make_backups;
1719 rprintf(FINFO, "generate_files phase=%d\n", phase);
1721 write_int(f_out, NDX_DONE);
1722 /* Reduce round-trip lag-time for a useless delay-updates phase. */
1723 if (protocol_version >= 29 && !delay_updates)
1724 write_int(f_out, NDX_DONE);
1726 /* Read MSG_DONE for the redo phase (and any prior messages). */
1727 get_redo_num(itemizing, code);
1729 if (protocol_version >= 29) {
1732 rprintf(FINFO, "generate_files phase=%d\n", phase);
1734 write_int(f_out, NDX_DONE);
1735 /* Read MSG_DONE for delay-updates phase & prior messages. */
1736 get_redo_num(itemizing, code);
1739 do_progress = save_do_progress;
1740 if (delete_delay_fp)
1741 delayed_deletions(fbuf);
1742 if (delete_after && !local_name && flist->count > 0)
1743 do_delete_pass(flist);
1745 if ((need_retouch_dir_perms || need_retouch_dir_times) && dir_tweaking) {
1747 /* Now we need to fix any directory permissions that were
1748 * modified during the transfer and/or re-set any tweaked
1749 * modified-time values. */
1750 for (i = 0; i < flist->count; i++) {
1751 struct file_struct *file = flist->files[i];
1752 if (!F_IS_ACTIVE(file) || !S_ISDIR(file->mode))
1754 if (!need_retouch_dir_times && file->mode & S_IWUSR)
1756 if (file->flags & FLAG_MISSING_DIR) {
1757 int missing = file->dir.depth;
1758 while (++i < flist->count) {
1759 file = flist->files[i];
1760 if (file->dir.depth <= missing)
1766 recv_generator(f_name(file, NULL), file, i, itemizing,
1767 maybe_ATTRS_REPORT, code, -1);
1768 if (allowed_lull && !(++j % lull_mod))
1769 maybe_send_keepalive();
1770 else if (!(j % 200))
1771 maybe_flush_socket();
1774 recv_generator(NULL, NULL, 0, 0, 0, code, -1);
1776 if (max_delete >= 0 && deletion_count > max_delete) {
1778 "Deletions stopped due to --max-delete limit (%d skipped)\n",
1779 deletion_count - max_delete);
1780 io_error |= IOERR_DEL_LIMIT;
1784 rprintf(FINFO, "generate_files finished\n");