X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/48e1c8c69d9af33fb11f849901150bd4f2ac3eb4..3e870a64440a8244fb60fe69b2401d2dec90ce08:/receiver.c diff --git a/receiver.c b/receiver.c index 3acb7bd0..48937f63 100644 --- a/receiver.c +++ b/receiver.c @@ -21,27 +21,27 @@ #include "rsync.h" extern int verbose; -extern int recurse; +extern int dry_run; +extern int am_daemon; +extern int am_server; +extern int do_progress; +extern int log_before_transfer; +extern int log_format_has_i; +extern int daemon_log_format_has_i; extern int delete_after; extern int csum_length; -extern struct stats stats; -extern int dry_run; extern int read_batch; extern int batch_gen_fd; -extern int am_server; extern int protocol_version; extern int relative_paths; extern int keep_dirlinks; extern int preserve_hard_links; extern int preserve_perms; extern int io_error; -extern char *tmpdir; -extern char *partial_dir; -extern char *basis_dir[]; extern int basis_dir_cnt; extern int make_backups; -extern int do_progress; extern int cleanup_got_literal; +extern int remove_sent_files; extern int module_id; extern int ignore_errors; extern int orig_umask; @@ -49,6 +49,11 @@ extern int keep_partial; extern int checksum_seed; extern int inplace; extern int delay_updates; +extern struct stats stats; +extern char *log_format; +extern char *tmpdir; +extern char *partial_dir; +extern char *basis_dir[]; extern struct filter_list_struct server_filter_list; @@ -61,11 +66,16 @@ void delete_files(struct file_list *flist) int j; for (j = 0; j < flist->count; j++) { - if (!(flist->files[j]->flags & FLAG_DEL_START) - || !S_ISDIR(flist->files[j]->mode)) + struct file_struct *file = flist->files[j]; + + if (!(file->flags & FLAG_DEL_HERE)) continue; - delete_in_dir(flist, f_name_to(flist->files[j], fbuf)); + f_name_to(file, fbuf); + if (verbose > 1 && file->flags & FLAG_TOP_DIR) + rprintf(FINFO, "deleting in %s\n", safe_fname(fbuf)); + + delete_in_dir(flist, fbuf, file); } } @@ -119,7 +129,8 @@ static int get_tmpname(char *fnametmp, char *fname) maxname = MIN(MAXPATHLEN - 7 - length, NAME_MAX - 8); if (maxname < 1) { - rprintf(FERROR, "temporary filename too long: %s\n", fname); + rprintf(FERROR, "temporary filename too long: %s\n", + safe_fname(fname)); fnametmp[0] = '\0'; return 0; } @@ -252,6 +263,36 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r, } +static void read_gen_name(int fd, char *dirname, char *buf) +{ + int dlen; + int len = read_byte(fd); + + if (len & 0x80) { +#if MAXPATHLEN > 32767 + uchar lenbuf[2]; + read_buf(fd, (char *)lenbuf, 2); + len = (len & ~0x80) * 0x10000 + lenbuf[0] * 0x100 + lenbuf[1]; +#else + len = (len & ~0x80) * 0x100 + read_byte(fd); +#endif + } + + if (dirname) { + dlen = strlcpy(buf, dirname, MAXPATHLEN); + buf[dlen++] = '/'; + } else + dlen = 0; + + if (dlen + len >= MAXPATHLEN) { + rprintf(FERROR, "bogus data on generator name pipe\n"); + exit_cleanup(RERR_PROTOCOL); + } + + read_sbuf(fd, buf + dlen, len); +} + + static void discard_receive_data(int f_in, OFF_T length) { receive_data(f_in, NULL, -1, 0, NULL, -1, length); @@ -268,15 +309,18 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, int next_gen_i = -1; int fd1,fd2; STRUCT_STAT st; + int iflags; char *fname, fbuf[MAXPATHLEN]; char template[MAXPATHLEN]; char fnametmp[MAXPATHLEN]; - char *fnamecmp, *partialptr; + char *fnamecmp, *partialptr, numbuf[4]; char fnamecmpbuf[MAXPATHLEN]; uchar *delayed_bits = NULL; struct file_struct *file; struct stats initial_stats; int save_make_backups = make_backups; + int itemizing = am_daemon ? daemon_log_format_has_i + : !am_server && log_format_has_i; int i, recv_ok, phase = 0; if (verbose > 2) @@ -289,7 +333,7 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, if (delay_updates) { int sz = (flist->count + 7) / 8; - if (!(delayed_bits = new_array(char, sz))) + if (!(delayed_bits = new_array(uchar, sz))) out_of_memory("recv_files"); memset(delayed_bits, 0, sz); } @@ -330,28 +374,50 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, } file = flist->files[i]; + fname = local_name ? local_name : f_name_to(file, fbuf); + + if (verbose > 2) + rprintf(FINFO, "recv_files(%s)\n", safe_fname(fname)); + + if (protocol_version >= 29) { + iflags = read_shortint(f_in); + if (!(iflags & ITEM_UPDATING) || !S_ISREG(file->mode)) { + int see_item = itemizing && (iflags || verbose > 1); + if (am_server) { + if (am_daemon && !dry_run && see_item) + log_recv(file, &stats, iflags); + } else if (see_item || iflags & ITEM_UPDATING + || (S_ISDIR(file->mode) + && iflags & ITEM_REPORT_TIME)) + log_recv(file, &stats, iflags); + continue; + } + } else + iflags = ITEM_UPDATING | ITEM_MISSING_DATA; + + if (!S_ISREG(file->mode)) { + rprintf(FERROR, "[%s] got index of non-regular file: %d\n", + who_am_i(), i); + exit_cleanup(RERR_PROTOCOL); + } stats.current_file_index = i; stats.num_transferred_files++; stats.total_transferred_size += file->length; cleanup_got_literal = 0; - if (local_name) - fname = local_name; - else - fname = f_name_to(file, fbuf); + if (server_filter_list.head + && check_filter(&server_filter_list, fname, 0) < 0) { + rprintf(FERROR, "attempt to hack rsync failed.\n"); + exit_cleanup(RERR_PROTOCOL); + } - if (dry_run) { - if (!am_server && verbose) /* log the transfer */ - rprintf(FINFO, "%s\n", safe_fname(fname)); + if (dry_run) { /* log the transfer */ + if (!am_server && log_format) + log_recv(file, &stats, iflags); continue; } - initial_stats = stats; - - if (verbose > 2) - rprintf(FINFO, "recv_files(%s)\n", safe_fname(fname)); - if (read_batch) { while (i > next_gen_i) { if (f_in_name >= 0 && next_gen_i >= 0) @@ -369,13 +435,6 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, next_gen_i = -1; } - if (server_filter_list.head - && check_filter(&server_filter_list, fname, - S_ISDIR(file->mode)) < 0) { - rprintf(FERROR, "attempt to hack rsync failed.\n"); - exit_cleanup(RERR_PROTOCOL); - } - partialptr = partial_dir ? partial_dir_fname(fname) : fname; if (f_in_name >= 0) { @@ -390,6 +449,10 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, case FNAMECMP_BACKUP: fnamecmp = get_backup_name(fname); break; + case FNAMECMP_FUZZY: + read_gen_name(f_in_name, file->dirname, fnamecmpbuf); + fnamecmp = fnamecmpbuf; + break; default: if (j >= basis_dir_cnt) { rprintf(FERROR, @@ -405,6 +468,8 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, } else fnamecmp = fname; + initial_stats = stats; + /* open the file */ fd1 = do_open(fnamecmp, O_RDONLY, 0); @@ -491,14 +556,18 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, cleanup_set(fnametmp, partialptr, file, fd1, fd2); } - if (!am_server && verbose) /* log the transfer */ + /* log the transfer */ + if (log_before_transfer) + log_recv(file, &initial_stats, iflags); + else if (!am_server && verbose && do_progress) rprintf(FINFO, "%s\n", safe_fname(fname)); /* recv file data */ recv_ok = receive_data(f_in, fnamecmp, fd1, st.st_size, fname, fd2, file->length); - log_recv(file, &initial_stats); + if (!log_before_transfer) + log_recv(file, &initial_stats, iflags); if (fd1 != -1) close(fd1); @@ -508,7 +577,7 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, exit_cleanup(RERR_FILEIO); } - if ((recv_ok && !delay_updates) || inplace) { + if ((recv_ok && (!delay_updates || !partialptr)) || inplace) { finish_transfer(fname, fnametmp, file, recv_ok, 1); if (partialptr != fname && fnamecmp == partialptr) { do_unlink(partialptr); @@ -527,7 +596,12 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, cleanup_disable(); - if (!recv_ok) { + if (recv_ok) { + if (remove_sent_files) { + SIVAL(numbuf, 0, i); + send_msg(MSG_SUCCESS, numbuf, 4); + } + } else { int msgtype = csum_length == SUM_LENGTH || read_batch ? FERROR : FINFO; if (msgtype == FERROR || verbose) { @@ -551,9 +625,8 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, keptstr, redostr); } if (csum_length != SUM_LENGTH) { - char buf[4]; - SIVAL(buf, 0, i); - send_msg(MSG_REDO, buf, 4); + SIVAL(numbuf, 0, i); + send_msg(MSG_REDO, numbuf, 4); } } } @@ -572,12 +645,14 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, continue; if (verbose > 2) { rprintf(FINFO, "renaming %s to %s\n", - partialptr, fname); + safe_fname(partialptr), + safe_fname(fname)); } if (do_rename(partialptr, fname) < 0) { rsyserr(FERROR, errno, "rename failed for %s (from %s)", - fname, partialptr); + full_fname(fname), + safe_fname(partialptr)); } else { handle_partial_dir(partialptr, PDIR_DELETE); @@ -586,7 +661,7 @@ int recv_files(int f_in, struct file_list *flist, char *local_name, } } - if (delete_after && recurse && !local_name && flist->count > 0) + if (delete_after && !local_name && flist->count > 0) delete_files(flist); if (verbose > 2)