X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/b3bf9b9df95137a3a43248be9599d919b04877af..3696674bc62b0c1250027dbeedafdd7ebafdcf8b:/main.c diff --git a/main.c b/main.c index 37496055..75e9a2fe 100644 --- a/main.c +++ b/main.c @@ -77,7 +77,9 @@ extern char *rsync_path; extern char *shell_cmd; extern char *batch_name; extern char *password_file; +extern char *backup_dir; extern char curr_dir[MAXPATHLEN]; +extern char backup_dir_buf[MAXPATHLEN]; extern char *basis_dir[MAX_BASIS_DIRS+1]; extern struct file_list *first_flist; extern struct filter_list_struct daemon_filter_list; @@ -173,8 +175,10 @@ static void wait_process_with_flush(pid_t pid, int *exit_code_ptr) void write_del_stats(int f) { - if (!INFO_GTE(STATS, 2) || protocol_version < 31) - return; + if (read_batch) + write_int(f, NDX_DEL_STATS); + else + send_msg(MSG_DEL_STATS, "", 0, 0); write_varint(f, stats.deleted_files - stats.deleted_dirs - stats.deleted_symlinks - stats.deleted_devices - stats.deleted_specials); @@ -186,8 +190,6 @@ void write_del_stats(int f) void read_del_stats(int f) { - if (!INFO_GTE(STATS, 2) || protocol_version < 31) - return; stats.deleted_files = read_varint(f); stats.deleted_files += stats.deleted_dirs = read_varint(f); stats.deleted_files += stats.deleted_symlinks = read_varint(f); @@ -234,7 +236,6 @@ static void handle_stats(int f) write_varlong30(f, stats.flist_buildtime, 3); write_varlong30(f, stats.flist_xfertime, 3); } - write_del_stats(f); } return; } @@ -253,8 +254,6 @@ static void handle_stats(int f) stats.flist_buildtime = read_varlong30(f, 3); stats.flist_xfertime = read_varlong30(f, 3); } - if (!read_batch) - read_del_stats(f); } else if (write_batch) { /* The --read-batch process is going to be a client * receiver, so we need to give it the stats. */ @@ -265,8 +264,6 @@ static void handle_stats(int f) write_varlong30(batch_fd, stats.flist_buildtime, 3); write_varlong30(batch_fd, stats.flist_xfertime, 3); } - /* We don't write the del stats into the batch file -- they - * come from the generator when reading the batch. */ } } @@ -716,7 +713,7 @@ static void check_alt_basis_dirs(void) } /* This is only called by the sender. */ -static void read_final_goodbye(int f_in) +static void read_final_goodbye(int f_in, int f_out) { int i, iflags, xlen; uchar fnamecmp_type; @@ -725,8 +722,19 @@ static void read_final_goodbye(int f_in) if (protocol_version < 29) i = read_int(f_in); else { - i = read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type, - xname, &xlen); + i = read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type, xname, &xlen); + if (protocol_version >= 31 && i == NDX_DONE) { + if (am_sender) + write_ndx(f_out, NDX_DONE); + else { + if (batch_gen_fd >= 0) { + while (read_int(batch_gen_fd) != NDX_DEL_STATS) {} + read_del_stats(batch_gen_fd); + } + send_msg(MSG_DONE, "", 0, 0); + } + i = read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type, xname, &xlen); + } } if (i != NDX_DONE) { @@ -785,7 +793,7 @@ static void do_server_sender(int f_in, int f_out, int argc, char *argv[]) io_flush(FULL_FLUSH); handle_stats(f_out); if (protocol_version >= 24) - read_final_goodbye(f_in); + read_final_goodbye(f_in, f_out); io_flush(FULL_FLUSH); exit_cleanup(0); } @@ -811,6 +819,18 @@ static int do_recv(int f_in, int f_out, char *local_name) exit_cleanup(RERR_IPC); } + if (backup_dir) { + int ret = make_path(backup_dir_buf, MKP_DROP_NAME); /* drops trailing slash */ + if (ret < 0) + exit_cleanup(RERR_SYNTAX); + if (ret) + rprintf(FINFO, "Created backup_dir %s\n", backup_dir_buf); + else if (INFO_GTE(BACKUP, 1)) { + char *dir = *backup_dir_buf ? backup_dir_buf : "."; + rprintf(FINFO, "backup_dir is %s\n", dir); + } + } + io_flush(NORMAL_FLUSH); if ((pid = do_fork()) == -1) { @@ -846,15 +866,10 @@ static int do_recv(int f_in, int f_out, char *local_name) /* Handle any keep-alive packets from the post-processing work * that the generator does. */ if (protocol_version >= 29) { - int iflags, xlen; - uchar fnamecmp_type; - char xname[MAXPATHLEN]; - kluge_around_eof = -1; /* This should only get stopped via a USR2 signal. */ - read_ndx_and_attrs(f_in, &iflags, &fnamecmp_type, - xname, &xlen); + read_final_goodbye(f_in, f_out); rprintf(FERROR, "Invalid packet at end of run [%s]\n", who_am_i()); @@ -1090,7 +1105,6 @@ int client_run(int f_in, int f_out, pid_t pid, int argc, char *argv[]) if (write_batch && !am_server) start_write_batch(f_out); flist = send_file_list(f_out, argc, argv); - set_msg_fd_in(-1); if (DEBUG_GTE(FLIST, 3)) rprintf(FINFO,"file list sent\n"); @@ -1102,7 +1116,7 @@ int client_run(int f_in, int f_out, pid_t pid, int argc, char *argv[]) io_flush(FULL_FLUSH); handle_stats(-1); if (protocol_version >= 24) - read_final_goodbye(f_in); + read_final_goodbye(f_in, f_out); if (pid != -1) { if (DEBUG_GTE(EXIT, 2)) rprintf(FINFO,"client_run waiting on %d\n", (int) pid);