1 /* -*- c-file-style: "linux" -*-
3 rsync -- fast file replication program
5 Copyright (C) 1996-2000 by Andrew Tridgell
6 Copyright (C) Paul Mackerras 1996
7 Copyright (C) 2002 by Martin Pool <mbp@samba.org>
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
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 extern int log_format_has_i;
29 extern int log_format_has_o_or_i;
30 extern int daemon_log_format_has_i;
34 extern int relative_paths;
35 extern int keep_dirlinks;
36 extern int preserve_links;
37 extern int preserve_devices;
38 extern int preserve_hard_links;
39 extern int preserve_perms;
40 extern int preserve_uid;
41 extern int preserve_gid;
42 extern int preserve_times;
43 extern int omit_dir_times;
44 extern int delete_during;
45 extern int remove_sent_files;
46 extern int update_only;
47 extern int opt_ignore_existing;
49 extern int make_backups;
50 extern int csum_length;
51 extern int ignore_times;
53 extern OFF_T max_size;
54 extern int io_timeout;
55 extern int protocol_version;
56 extern int fuzzy_basis;
57 extern int always_checksum;
58 extern char *partial_dir;
59 extern char *basis_dir[];
60 extern int compare_dest;
62 extern int whole_file;
63 extern int local_server;
65 extern int read_batch;
66 extern int only_existing;
67 extern int orig_umask;
68 extern int safe_symlinks;
69 extern long block_size; /* "long" because popt can't set an int32. */
70 extern struct stats stats;
72 extern struct filter_list_struct server_filter_list;
74 static int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
77 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
80 if (am_root && preserve_uid && st->st_uid != file->uid)
83 if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
90 #define SID_UPDATING ITEM_UPDATING
91 #define SID_REPORT_CHECKSUM ITEM_REPORT_CHECKSUM
92 #define SID_NO_DEST_AND_NO_UPDATE (1<<16)
94 static void itemize(struct file_struct *file, int statret, STRUCT_STAT *st,
95 int32 sflags, int f_out, int ndx)
97 int iflags = sflags & (SID_UPDATING | SID_REPORT_CHECKSUM);
100 if (S_ISREG(file->mode) && file->length != st->st_size)
101 iflags |= ITEM_REPORT_SIZE;
102 if (!(sflags & SID_NO_DEST_AND_NO_UPDATE)) {
103 int keep_time = !preserve_times ? 0
104 : S_ISDIR(file->mode) ? !omit_dir_times
105 : !S_ISLNK(file->mode);
107 if ((iflags & ITEM_UPDATING && !keep_time)
108 || (keep_time && file->modtime != st->st_mtime))
109 iflags |= ITEM_REPORT_TIME;
110 if (preserve_perms && file->mode != st->st_mode)
111 iflags |= ITEM_REPORT_PERMS;
112 if (preserve_uid && am_root && file->uid != st->st_uid)
113 iflags |= ITEM_REPORT_OWNER;
114 if (preserve_gid && file->gid != GID_NONE
115 && st->st_gid != file->gid)
116 iflags |= ITEM_REPORT_GROUP;
119 iflags |= ITEM_IS_NEW | ITEM_UPDATING;
121 if ((iflags || verbose > 1) && !read_batch) {
122 if (protocol_version >= 29) {
124 write_int(f_out, ndx);
125 write_shortint(f_out, iflags);
127 log_recv(file, &stats, iflags);
132 /* Perform our quick-check heuristic for determining if a file is unchanged. */
133 static int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
135 if (st->st_size != file->length)
138 /* if always checksum is set then we use the checksum instead
139 of the file time to determine whether to sync */
140 if (always_checksum && S_ISREG(st->st_mode)) {
141 char sum[MD4_SUM_LENGTH];
142 file_checksum(fn, sum, st->st_size);
143 return memcmp(sum, file->u.sum, protocol_version < 21 ? 2
144 : MD4_SUM_LENGTH) == 0;
153 return cmp_modtime(st->st_mtime, file->modtime) == 0;
158 * set (initialize) the size entries in the per-file sum_struct
159 * calculating dynamic block and checksum sizes.
161 * This is only called from generate_and_send_sums() but is a separate
162 * function to encapsulate the logic.
164 * The block size is a rounded square root of file length.
166 * The checksum size is determined according to:
167 * blocksum_bits = BLOCKSUM_EXP + 2*log2(file_len) - log2(block_len)
168 * provided by Donovan Baarda which gives a probability of rsync
169 * algorithm corrupting data and falling back using the whole md4
172 * This might be made one of several selectable heuristics.
174 static void sum_sizes_sqroot(struct sum_struct *sum, int64 len)
180 blength = block_size;
181 else if (len <= BLOCK_SIZE * BLOCK_SIZE)
182 blength = BLOCK_SIZE;
187 for (c = 1, l = len, cnt = 0; l >>= 2; c <<= 1, cnt++) {}
188 if (cnt >= 31 || c >= MAX_BLOCK_SIZE)
189 blength = MAX_BLOCK_SIZE;
194 if (len < (int64)blength * blength)
197 } while (c >= 8); /* round to multiple of 8 */
198 blength = MAX(blength, BLOCK_SIZE);
202 if (protocol_version < 27) {
203 s2length = csum_length;
204 } else if (csum_length == SUM_LENGTH) {
205 s2length = SUM_LENGTH;
209 int b = BLOCKSUM_BIAS;
210 for (l = len; l >>= 1; b += 2) {}
211 for (c = blength; c >>= 1 && b; b--) {}
212 /* add a bit, subtract rollsum, round up. */
213 s2length = (b + 1 - 32 + 7) / 8; /* --optimize in compiler-- */
214 s2length = MAX(s2length, csum_length);
215 s2length = MIN(s2length, SUM_LENGTH);
219 sum->blength = blength;
220 sum->s2length = s2length;
221 sum->count = (len + (blength - 1)) / blength;
222 sum->remainder = (len % blength);
224 if (sum->count && verbose > 2) {
226 "count=%.0f rem=%ld blength=%ld s2length=%d flength=%.0f\n",
227 (double)sum->count, (long)sum->remainder, (long)sum->blength,
228 sum->s2length, (double)sum->flength);
234 * Generate and send a stream of signatures/checksums that describe a buffer
236 * Generate approximately one checksum every block_len bytes.
238 static void generate_and_send_sums(int fd, OFF_T len, int f_out, int f_copy)
241 struct map_struct *mapbuf;
242 struct sum_struct sum;
245 sum_sizes_sqroot(&sum, len);
248 mapbuf = map_file(fd, len, MAX_MAP_SIZE, sum.blength);
252 write_sum_head(f_out, &sum);
254 for (i = 0; i < sum.count; i++) {
255 int32 n1 = (int32)MIN(len, (OFF_T)sum.blength);
256 char *map = map_ptr(mapbuf, offset, n1);
257 uint32 sum1 = get_checksum1(map, n1);
258 char sum2[SUM_LENGTH];
261 full_write(f_copy, map, n1);
263 get_checksum2(map, n1, sum2);
267 "chunk[%.0f] offset=%.0f len=%ld sum1=%08lx\n",
268 (double)i, (double)offset, (long)n1,
269 (unsigned long)sum1);
271 write_int(f_out, sum1);
272 write_buf(f_out, sum2, sum.s2length);
282 /* Try to find a filename in the same dir as "fname" with a similar name. */
283 static int find_fuzzy(struct file_struct *file, struct file_list *dirlist)
285 int fname_len, fname_suf_len;
286 const char *fname_suf, *fname = file->basename;
287 uint32 lowest_dist = 0x7FFFFFFF;
288 int j, lowest_j = -1;
290 fname_len = strlen(fname);
291 fname_suf = find_filename_suffix(fname, fname_len, &fname_suf_len);
293 for (j = 0; j < dirlist->count; j++) {
294 struct file_struct *fp = dirlist->files[j];
295 const char *suf, *name;
299 if (!S_ISREG(fp->mode) || !fp->length
300 || fp->flags & FLAG_NO_FUZZY)
305 if (fp->length == file->length
306 && fp->modtime == file->modtime) {
309 "fuzzy size/modtime match for %s\n",
316 suf = find_filename_suffix(name, len, &suf_len);
318 dist = fuzzy_distance(name, len, fname, fname_len);
319 /* Add some extra weight to how well the suffixes match. */
320 dist += fuzzy_distance(suf, suf_len, fname_suf, fname_suf_len)
323 rprintf(FINFO, "fuzzy distance for %s = %d.%05d\n",
324 name, (int)(dist>>16), (int)(dist&0xFFFF));
326 if (dist <= lowest_dist) {
336 /* Acts on flist->file's ndx'th item, whose name is fname. If a directory,
337 * make sure it exists, and has the right permissions/timestamp info. For
338 * all other non-regular files (symlinks, etc.) we create them here. For
339 * regular files that have changed, we try to find a basis file and then
340 * start sending checksums.
342 * Note that f_out is set to -1 when doing final directory-permission and
343 * modification-time repair. */
344 static void recv_generator(char *fname, struct file_list *flist,
345 struct file_struct *file, int ndx,
346 int f_out, int f_out_name)
348 static int missing_below = -1, excluded_below = -1;
349 static char *fuzzy_dirname = NULL;
350 static struct file_list *fuzzy_dirlist = NULL;
351 struct file_struct *fuzzy_file = NULL;
352 int fd = -1, f_copy = -1;
353 STRUCT_STAT st, partial_st;
354 struct file_struct *back_file = NULL;
355 int statret, stat_errno;
356 char *fnamecmp, *partialptr, *backupptr = NULL;
357 char fnamecmpbuf[MAXPATHLEN];
358 int itemizing, maybe_PERMS_REPORT;
365 if (protocol_version >= 29) {
367 code = daemon_log_format_has_i ? 0 : FLOG;
368 maybe_PERMS_REPORT = log_format_has_i ? 0 : PERMS_REPORT;
369 } else if (am_daemon) {
370 itemizing = daemon_log_format_has_i && !dry_run;
371 code = itemizing || dry_run ? FCLIENT : FINFO;
372 maybe_PERMS_REPORT = PERMS_REPORT;
373 } else if (!am_server) {
374 itemizing = log_format_has_i;
375 code = itemizing ? 0 : FINFO;
376 maybe_PERMS_REPORT = log_format_has_i ? 0 : PERMS_REPORT;
380 maybe_PERMS_REPORT = PERMS_REPORT;
385 flist_free(fuzzy_dirlist);
386 fuzzy_dirlist = NULL;
387 fuzzy_dirname = NULL;
389 if (missing_below >= 0) {
397 rprintf(FINFO, "recv_generator(%s,%d)\n",
398 safe_fname(fname), ndx);
401 if (server_filter_list.head) {
402 if (excluded_below >= 0) {
403 if (file->dir.depth > excluded_below)
407 if (check_filter(&server_filter_list, fname,
408 S_ISDIR(file->mode)) < 0) {
409 if (S_ISDIR(file->mode))
410 excluded_below = file->dir.depth;
414 "skipping server-excluded file \"%s\"\n",
421 if (missing_below >= 0 && file->dir.depth <= missing_below) {
429 if (fuzzy_basis && S_ISREG(file->mode)) {
430 char *dn = file->dirname ? file->dirname : ".";
431 /* Yes, identical dirnames are guaranteed to have
432 * identical pointers at this point. */
433 if (fuzzy_dirname != dn) {
435 flist_free(fuzzy_dirlist);
437 fuzzy_dirlist = get_dirlist(fuzzy_dirname, 1);
441 statret = link_stat(fname, &st,
442 keep_dirlinks && S_ISDIR(file->mode));
446 if (only_existing && statret == -1 && stat_errno == ENOENT) {
447 /* we only want to update existing files */
449 rprintf(FINFO, "not creating new file \"%s\"\n",
455 if (statret == 0 && !preserve_perms
456 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode)) {
457 /* if the file exists already and we aren't perserving
458 * permissions then act as though the remote end sent
459 * us the file permissions we already have */
460 file->mode = (file->mode & ~CHMOD_BITS)
461 | (st.st_mode & CHMOD_BITS);
464 if (S_ISDIR(file->mode)) {
465 /* The file to be received is a directory, so we need
466 * to prepare appropriately. If there is already a
467 * file of that name and it is *not* a directory, then
468 * we need to delete it. If it doesn't exist, then
469 * (perhaps recursively) create it. */
470 if (statret == 0 && !S_ISDIR(st.st_mode)) {
471 delete_file(fname, st.st_mode, DEL_TERSE);
474 if (dry_run && statret != 0 && missing_below < 0) {
475 missing_below = file->dir.depth;
478 if (itemizing && f_out != -1)
479 itemize(file, statret, &st, 0, f_out, ndx);
480 if (statret != 0 && do_mkdir(fname,file->mode) != 0 && errno != EEXIST) {
481 if (!relative_paths || errno != ENOENT
482 || create_directory_path(fname, orig_umask) < 0
483 || do_mkdir(fname, file->mode) < 0) {
484 rsyserr(FERROR, errno,
485 "recv_generator: mkdir %s failed",
489 if (set_perms(fname, file, statret ? NULL : &st, 0)
490 && verbose && code && f_out != -1)
491 rprintf(code, "%s/\n", safe_fname(fname));
492 if (delete_during && f_out != -1 && csum_length != SUM_LENGTH
493 && (file->flags & FLAG_DEL_HERE))
494 delete_in_dir(flist, fname, file);
498 if (max_size && file->length > max_size) {
500 rprintf(FINFO, "%s is over max-size\n",
506 if (preserve_links && S_ISLNK(file->mode)) {
508 if (safe_symlinks && unsafe_symlink(file->u.link, fname)) {
511 "ignoring unsafe symlink %s -> \"%s\"\n",
513 safe_fname(file->u.link));
518 char lnk[MAXPATHLEN];
521 if (!S_ISDIR(st.st_mode)
522 && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) {
524 /* A link already pointing to the
525 * right place -- no further action
527 if (strcmp(lnk, file->u.link) == 0) {
529 itemize(file, 0, &st, 0,
532 set_perms(fname, file, &st,
537 /* Not the right symlink (or not a symlink), so
539 if (S_ISLNK(st.st_mode))
540 delete_file(fname, st.st_mode, DEL_TERSE);
542 delete_file(fname, st.st_mode, DEL_TERSE);
546 if (do_symlink(file->u.link,fname) != 0) {
547 rsyserr(FERROR, errno, "symlink %s -> \"%s\" failed",
548 full_fname(fname), safe_fname(file->u.link));
550 set_perms(fname,file,NULL,0);
552 itemize(file, statret, &st, SID_UPDATING,
555 if (code && verbose) {
556 rprintf(code, "%s -> %s\n", safe_fname(fname),
557 safe_fname(file->u.link));
559 if (remove_sent_files && !dry_run) {
561 SIVAL(numbuf, 0, ndx);
562 send_msg(MSG_SUCCESS, numbuf, 4);
569 if (am_root && preserve_devices && IS_DEVICE(file->mode)) {
571 st.st_mode != file->mode ||
572 st.st_rdev != file->u.rdev) {
573 if (IS_DEVICE(st.st_mode))
574 delete_file(fname, st.st_mode, DEL_TERSE);
576 delete_file(fname, st.st_mode, DEL_TERSE);
580 rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
582 (int)file->mode, (int)file->u.rdev);
584 if (do_mknod(fname,file->mode,file->u.rdev) != 0) {
585 rsyserr(FERROR, errno, "mknod %s failed",
588 set_perms(fname,file,NULL,0);
590 itemize(file, statret, &st, SID_UPDATING,
593 if (code && verbose) {
594 rprintf(code, "%s\n",
600 itemize(file, statret, &st, 0,
603 set_perms(fname, file, &st, maybe_PERMS_REPORT);
608 if (preserve_hard_links && hard_link_check(file, HL_CHECK_MASTER))
611 if (!S_ISREG(file->mode)) {
612 rprintf(FINFO, "skipping non-regular file \"%s\"\n",
618 fnamecmp_type = FNAMECMP_FNAME;
620 if (statret != 0 && basis_dir[0] != NULL) {
621 int fallback_match = -1;
625 pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
626 basis_dir[i], fname);
627 if (link_stat(fnamecmpbuf, &st, 0) == 0
628 && S_ISREG(st.st_mode)) {
634 } else if (match_level == 2
635 && !unchanged_attrs(file, &st))
637 if (!unchanged_file(fnamecmpbuf, file, &st))
641 if (!unchanged_attrs(file, &st))
647 } while (basis_dir[++i] != NULL);
649 if (match_level < 3) {
651 pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
652 basis_dir[i], fname);
655 if (link_dest && match_level == 3 && !dry_run) {
656 if (do_link(fnamecmpbuf, fname) < 0) {
658 rsyserr(FINFO, errno,
660 full_fname(fnamecmpbuf),
663 fnamecmp = fnamecmpbuf;
669 fnamecmp = fnamecmpbuf;
675 if (statret == 0 && !S_ISREG(st.st_mode)) {
676 if (delete_file(fname, st.st_mode, DEL_TERSE) != 0)
682 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
683 && link_stat(partialptr, &partial_st, 0) == 0
684 && S_ISREG(partial_st.st_mode)) {
686 goto prepare_to_open;
690 if (statret != 0 && fuzzy_basis && dry_run <= 1) {
691 int j = find_fuzzy(file, fuzzy_dirlist);
693 fuzzy_file = fuzzy_dirlist->files[j];
694 f_name_to(fuzzy_file, fnamecmpbuf);
696 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
697 safe_fname(fname), safe_fname(fnamecmpbuf));
699 st.st_mode = fuzzy_file->mode;
700 st.st_size = fuzzy_file->length;
701 st.st_mtime = fuzzy_file->modtime;
703 fnamecmp = fnamecmpbuf;
704 fnamecmp_type = FNAMECMP_FUZZY;
709 if (preserve_hard_links && hard_link_check(file, HL_SKIP))
711 if (stat_errno == ENOENT)
714 rsyserr(FERROR, stat_errno,
715 "recv_generator: failed to stat %s",
721 if (opt_ignore_existing && fnamecmp_type == FNAMECMP_FNAME) {
723 rprintf(FINFO, "%s exists\n", safe_fname(fname));
727 if (update_only && fnamecmp_type == FNAMECMP_FNAME
728 && cmp_modtime(st.st_mtime, file->modtime) > 0) {
730 rprintf(FINFO, "%s is newer\n", safe_fname(fname));
734 if (!compare_dest && fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
736 else if (fnamecmp_type == FNAMECMP_FUZZY)
738 else if (unchanged_file(fnamecmp, file, &st)) {
740 itemize(file, statret, &st,
741 fnamecmp_type == FNAMECMP_FNAME
742 ? 0 : SID_NO_DEST_AND_NO_UPDATE,
745 if (fnamecmp_type == FNAMECMP_FNAME)
746 set_perms(fname, file, &st, maybe_PERMS_REPORT);
753 fnamecmp = partialptr;
754 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
758 if (dry_run || read_batch)
760 if (whole_file > 0) {
767 int j = flist_find(fuzzy_dirlist, file);
768 if (j >= 0) /* don't use changing file as future fuzzy basis */
769 fuzzy_dirlist->files[j]->flags |= FLAG_NO_FUZZY;
773 fd = do_open(fnamecmp, O_RDONLY, 0);
776 rsyserr(FERROR, errno, "failed to open %s, continuing",
777 full_fname(fnamecmp));
779 /* pretend the file didn't exist */
780 if (preserve_hard_links && hard_link_check(file, HL_SKIP))
786 if (inplace && make_backups) {
787 if (!(backupptr = get_backup_name(fname))) {
791 if (!(back_file = make_file(fname, NULL, NO_FILTERS))) {
793 goto pretend_missing;
795 if (robust_unlink(backupptr) && errno != ENOENT) {
796 rsyserr(FERROR, errno, "unlink %s",
797 full_fname(backupptr));
802 if ((f_copy = do_open(backupptr,
803 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
804 rsyserr(FERROR, errno, "open %s",
805 full_fname(backupptr));
810 fnamecmp_type = FNAMECMP_BACKUP;
814 rprintf(FINFO, "gen mapped %s of size %.0f\n",
815 safe_fname(fnamecmp), (double)st.st_size);
819 rprintf(FINFO, "generating and sending sums for %d\n", ndx);
822 write_int(f_out, ndx);
824 itemize(file, statret, &st, SID_UPDATING
825 | (always_checksum ? SID_REPORT_CHECKSUM : 0),
827 if (inplace && !read_batch)
828 write_byte(f_out, fnamecmp_type);
830 if (f_out_name >= 0) {
831 write_byte(f_out_name, fnamecmp_type);
832 if (fnamecmp_type == FNAMECMP_FUZZY) {
833 uchar lenbuf[3], *lb = lenbuf;
834 int len = strlen(fuzzy_file->basename);
836 #if MAXPATHLEN > 0x7FFF
837 *lb++ = len / 0x10000 + 0x80;
840 *lb++ = len / 0x100 + 0x80;
844 write_buf(f_out_name, lenbuf, lb - lenbuf + 1);
845 write_buf(f_out_name, fuzzy_file->basename, len);
849 if (dry_run || read_batch)
853 generate_and_send_sums(fd, st.st_size, f_out, f_copy);
857 set_perms(backupptr, back_file, NULL, 0);
859 rprintf(FINFO, "backed up %s to %s\n",
860 safe_fname(fname), safe_fname(backupptr));
867 write_sum_head(f_out, NULL);
871 void generate_files(int f_out, struct file_list *flist, char *local_name,
876 char fbuf[MAXPATHLEN];
877 int need_retouch_dir_times = preserve_times && !omit_dir_times;
878 int need_retouch_dir_perms = 0;
879 int save_only_existing = only_existing;
880 int save_opt_ignore_existing = opt_ignore_existing;
883 rprintf(FINFO, "generator starting pid=%ld count=%d\n",
884 (long)getpid(), flist->count);
890 ? "delta-transmission disabled for local transfer or --whole-file\n"
891 : "delta transmission enabled\n");
894 /* We expect to just sit around now, so don't exit on a timeout.
895 * If we really get a timeout then the other process should exit. */
898 for (i = 0; i < flist->count; i++) {
899 struct file_struct *file = flist->files[i];
900 struct file_struct copy;
905 /* We need to ensure that any dirs we create have writeable
906 * permissions during the time we are putting files within
907 * them. This is then fixed after the transfer is done. */
908 if (!am_root && S_ISDIR(file->mode) && !(file->mode & S_IWUSR)) {
910 copy.mode |= S_IWUSR; /* user write */
912 need_retouch_dir_perms = 1;
915 recv_generator(local_name ? local_name : f_name_to(file, fbuf),
916 flist, file, i, f_out, f_out_name);
918 recv_generator(NULL, NULL, NULL, 0, -1, -1);
920 delete_in_dir(NULL, NULL, NULL);
923 csum_length = SUM_LENGTH;
924 only_existing = max_size = opt_ignore_existing = 0;
925 update_only = always_checksum = size_only = 0;
929 rprintf(FINFO,"generate_files phase=%d\n",phase);
931 write_int(f_out, -1);
933 /* files can cycle through the system more than once
934 * to catch initial checksum errors */
935 while ((i = get_redo_num()) != -1) {
936 struct file_struct *file = flist->files[i];
937 recv_generator(local_name ? local_name : f_name_to(file, fbuf),
938 flist, file, i, f_out, f_out_name);
942 only_existing = save_only_existing;
943 opt_ignore_existing = save_opt_ignore_existing;
946 rprintf(FINFO,"generate_files phase=%d\n",phase);
948 write_int(f_out, -1);
950 /* Read post-redo-phase MSG_DONE and any prior messages. */
953 if (preserve_hard_links)
956 if ((need_retouch_dir_perms || need_retouch_dir_times)
957 && !list_only && !local_name && !dry_run) {
958 /* Now we need to fix any directory permissions that were
959 * modified during the transfer and/or re-set any tweaked
960 * modified-time values. */
961 for (i = 0; i < flist->count; i++) {
962 struct file_struct *file = flist->files[i];
963 if (!file->basename || !S_ISDIR(file->mode))
965 if (!need_retouch_dir_times && file->mode & S_IWUSR)
967 recv_generator(local_name ? local_name : f_name(file),
968 flist, file, i, -1, -1);
971 recv_generator(NULL, NULL, NULL, 0, -1, -1);
974 rprintf(FINFO,"generate_files finished\n");