X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/f3d6d4800b35fd65d2395defdb57fed16cea3e85..7a2fa0c2d3ffa9288140b738b65e4eabb7e596c2:/generator.c diff --git a/generator.c b/generator.c index 80ce378d..9c002d96 100644 --- a/generator.c +++ b/generator.c @@ -31,7 +31,7 @@ extern int logfile_format_has_i; extern int am_root; extern int am_server; extern int am_daemon; -extern int incremental; +extern int inc_recurse; extern int do_progress; extern int relative_paths; extern int implied_dirs; @@ -282,10 +282,10 @@ static int start_delete_delay_temp(void) dry_run = 0; if (!get_tmpname(fnametmp, "deldelay") || (deldelay_fd = do_mkstemp(fnametmp, 0600)) < 0) { - rprintf(FINFO, "NOTE: Unable to create delete-delay temp file--" - "switching to --delete-after.\n"); + rprintf(FINFO, "NOTE: Unable to create delete-delay temp file%s.\n", + inc_recurse ? "" : " -- switching to --delete-after"); delete_during = 0; - delete_after = 1; + delete_after = !inc_recurse; dry_run = save_dry_run; return 0; } @@ -554,7 +554,7 @@ void itemize(struct file_struct *file, int ndx, int statret, || stdout_format_has_i > 1 || (xname && *xname)) && !read_batch) { if (protocol_version >= 29) { if (ndx >= 0) - write_int(sock_f_out, ndx + cur_flist->ndx_start); + write_ndx(sock_f_out, ndx + cur_flist->ndx_start); write_shortint(sock_f_out, iflags); if (iflags & ITEM_BASIS_TYPE_FOLLOWS) write_byte(sock_f_out, fnamecmp_type); @@ -1221,7 +1221,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, rprintf(code, "%s/\n", fname); if (real_ret != 0 && one_file_system) real_st.st_dev = filesystem_dev; - if (incremental) { + if (inc_recurse) { if (one_file_system) { uint32 *devp = F_DIRDEV_P(file); DEV_MAJOR(devp) = major(real_st.st_dev); @@ -1599,13 +1599,13 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, notify_others: if (remove_source_files && !delay_updates && !phase) increment_active_files(ndx, itemizing, code); - if (incremental && !dry_run) + if (inc_recurse && !dry_run) cur_flist->in_progress++; #ifdef SUPPORT_HARD_LINKS if (preserve_hard_links && F_IS_HLINKED(file)) file->flags |= FLAG_FILE_SENT; #endif - write_int(f_out, ndx + cur_flist->ndx_start); + write_ndx(f_out, ndx + cur_flist->ndx_start); if (itemizing) { int iflags = ITEM_TRANSFER; if (always_checksum > 0) @@ -1648,6 +1648,40 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, close(fd); } +static void touch_up_dirs(struct file_list *flist, int ndx, + int need_retouch_dir_times, int lull_mod) +{ + struct file_struct *file; + char *fname; + int i, j, start, end; + + if (ndx < 0) { + start = 0; + end = flist->count - 1; + } else + start = end = ndx; + + /* Fix any directory permissions that were modified during the + * transfer and/or re-set any tweaked modified-time values. */ + for (i = start, j = 0; i <= end; i++) { + file = flist->files[i]; + if (!F_IS_ACTIVE(file) || !S_ISDIR(file->mode) + || file->flags & FLAG_MISSING_DIR) + continue; + if (!need_retouch_dir_times && file->mode & S_IWUSR) + continue; + fname = f_name(file, NULL); + if (!(file->mode & S_IWUSR)) + do_chmod(fname, file->mode); + if (need_retouch_dir_times) + set_modtime(fname, file->modtime, file->mode); + if (allowed_lull && !(++j % lull_mod)) + maybe_send_keepalive(); + else if (!(j % 200)) + maybe_flush_socket(); + } +} + void generate_files(int f_out, char *local_name) { int i; @@ -1709,7 +1743,7 @@ void generate_files(int f_out, char *local_name) ignore_timeout = 1; do { - if (incremental && delete_during && cur_flist->ndx_start) { + if (inc_recurse && delete_during && cur_flist->ndx_start) { struct file_struct *fp = dir_flist->files[cur_flist->parent_ndx]; if (BITS_SETnUNSET(fp->flags, FLAG_XFER_DIR, FLAG_MISSING_DIR)) { dev_t dirdev; @@ -1762,7 +1796,7 @@ void generate_files(int f_out, char *local_name) maybe_flush_socket(); } - if (!incremental) { + if (!inc_recurse) { if (delete_during) delete_in_dir(NULL, NULL, NULL, &dev_zero); phase++; @@ -1771,7 +1805,7 @@ void generate_files(int f_out, char *local_name) phase); } - write_int(f_out, NDX_DONE); + write_ndx(f_out, NDX_DONE); } csum_length = SUM_LENGTH; @@ -1795,7 +1829,7 @@ void generate_files(int f_out, char *local_name) check_for_finished_hlinks(itemizing, code); if ((i = get_redo_num()) == -1) { - if (incremental) + if (inc_recurse) break; wait_for_receiver(); continue; @@ -1825,14 +1859,13 @@ void generate_files(int f_out, char *local_name) make_backups = -make_backups; ignore_times--; - if (!incremental) + if (!inc_recurse) break; while (!cur_flist->next && !flist_eof) wait_for_receiver(); next_flist = cur_flist->next; while (first_flist != next_flist) { - struct file_struct *fp; if (first_flist->in_progress || first_flist->to_redo) { if (next_flist) break; @@ -1841,34 +1874,20 @@ void generate_files(int f_out, char *local_name) } cur_flist = first_flist; - if (cur_flist->ndx_start != 0) { - fp = dir_flist->files[cur_flist->parent_ndx]; - if (!(fp->flags & FLAG_MISSING_DIR)) { - f_name(fp, fbuf); - if (!(fp->mode & S_IWUSR)) - do_chmod(fbuf, fp->mode); - if (preserve_times && !omit_dir_times) { - set_modtime(fbuf, fp->modtime, - fp->mode); - } - } - } else if (relative_paths && implied_dirs - && preserve_times && !omit_dir_times) { - /* Set mtime on implied dirs */ - for (i = 0; i < cur_flist->count; i++) { - fp = cur_flist->files[i]; - if (!S_ISDIR(fp->mode) - || fp->flags & (FLAG_XFER_DIR|FLAG_MISSING_DIR)) - continue; - f_name(fp, fbuf); - set_modtime(fbuf, fp->modtime, fp->mode); - } + if (delete_during == 2 || !dir_tweaking) { + /* Skip directory touch-up. */ + } else if (cur_flist->ndx_start != 0) { + touch_up_dirs(dir_flist, cur_flist->parent_ndx, + need_retouch_dir_times, lull_mod); + } else if (relative_paths && implied_dirs) { + touch_up_dirs(cur_flist, -1, + need_retouch_dir_times, lull_mod); } - flist_free(cur_flist); + flist_free(first_flist); /* updates cur_flist & first_flist */ if (!read_batch) - write_int(f_out, NDX_DONE); + write_ndx(f_out, NDX_DONE); } } while ((cur_flist = next_flist) != NULL); @@ -1876,10 +1895,10 @@ void generate_files(int f_out, char *local_name) if (verbose > 2) rprintf(FINFO, "generate_files phase=%d\n", phase); - write_int(f_out, NDX_DONE); + write_ndx(f_out, NDX_DONE); /* Reduce round-trip lag-time for a useless delay-updates phase. */ if (protocol_version >= 29 && !delay_updates) - write_int(f_out, NDX_DONE); + write_ndx(f_out, NDX_DONE); /* Read MSG_DONE for the redo phase (and any prior messages). */ while (done_cnt <= 1) { @@ -1892,7 +1911,7 @@ void generate_files(int f_out, char *local_name) if (verbose > 2) rprintf(FINFO, "generate_files phase=%d\n", phase); if (delay_updates) - write_int(f_out, NDX_DONE); + write_ndx(f_out, NDX_DONE); /* Read MSG_DONE for delay-updates phase & prior messages. */ while (done_cnt == 2) wait_for_receiver(); @@ -1905,34 +1924,9 @@ void generate_files(int f_out, char *local_name) do_delete_pass(cur_flist); if ((need_retouch_dir_perms || need_retouch_dir_times) - && dir_tweaking && !incremental) { - int j = 0; - /* Now we need to fix any directory permissions that were - * modified during the transfer and/or re-set any tweaked - * modified-time values. */ - for (i = 0; i < cur_flist->count; i++) { - struct file_struct *file = cur_flist->files[i]; - if (!F_IS_ACTIVE(file) || !S_ISDIR(file->mode)) - continue; - if (!need_retouch_dir_times && file->mode & S_IWUSR) - continue; - if (file->flags & FLAG_MISSING_DIR) { - int missing = F_DEPTH(file); - while (++i < cur_flist->count) { - file = cur_flist->files[i]; - if (F_DEPTH(file) <= missing) - break; - } - i--; - continue; - } - recv_generator(f_name(file, NULL), file, i, itemizing, - code, -1); - if (allowed_lull && !(++j % lull_mod)) - maybe_send_keepalive(); - else if (!(j % 200)) - maybe_flush_socket(); - } + && dir_tweaking && (!inc_recurse || delete_during == 2)) { + touch_up_dirs(inc_recurse ? dir_flist : cur_flist, -1, + need_retouch_dir_times, lull_mod); } if (max_delete >= 0 && deletion_count > max_delete) {