X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/4079d6a68495a837057f5171b26e45308e9e5681..a8e6e1486960fe2e9ac190ad53e9830f0f3f900a:/generator.c diff --git a/generator.c b/generator.c index 6b127206..1ccb55a2 100644 --- a/generator.c +++ b/generator.c @@ -50,6 +50,7 @@ extern int delete_mode; extern int delete_before; extern int delete_during; extern int delete_after; +extern int missing_args; extern int msgdone_cnt; extern int ignore_errors; extern int remove_source_files; @@ -96,7 +97,7 @@ extern mode_t orig_umask; extern uid_t our_uid; extern char *basis_dir[MAX_BASIS_DIRS+1]; extern struct file_list *cur_flist, *first_flist, *dir_flist; -extern struct filter_list_struct daemon_filter_list; +extern struct filter_list_struct filter_list, daemon_filter_list; int maybe_ATTRS_REPORT = 0; @@ -121,6 +122,9 @@ static void handle_skipped_hlink(struct file_struct *file, int itemizing, enum logcode code, int f_out); #endif +#define EARLY_DELAY_DONE_MSG() (!delay_updates) +#define EARLY_DELETE_DONE_MSG() (!(delete_during == 2 || delete_after)) + static int start_delete_delay_temp(void) { char fnametmp[MAXPATHLEN]; @@ -503,7 +507,7 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre if (iflags & ITEM_XNAME_FOLLOWS) write_vstring(sock_f_out, xname, strlen(xname)); #ifdef SUPPORT_XATTRS - if (preserve_xattrs && !dry_run + if (preserve_xattrs && do_xfers && iflags & (ITEM_REPORT_XATTR|ITEM_TRANSFER)) { send_xattr_request(NULL, file, iflags & ITEM_REPORT_XATTR ? sock_f_out : -1); @@ -752,7 +756,7 @@ static int copy_altdest_file(const char *src, const char *dest, struct file_stru copy_to = buf; } cleanup_set(copy_to, NULL, NULL, -1, -1); - if (copy_file(src, copy_to, fd_w, file->mode, 0) < 0) { + if (copy_file(src, copy_to, fd_w, file->mode) < 0) { if (INFO_GTE(COPY, 1)) { rsyserr(FINFO, errno, "copy_file %s => %s", full_fname(src), copy_to); @@ -927,8 +931,8 @@ static int try_dests_non(struct file_struct *file, char *fname, int ndx, } switch (type) { case TYPE_DIR: - break; case TYPE_SPECIAL: + break; case TYPE_DEVICE: devp = F_RDEV_P(file); if (sxp->st.st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp))) @@ -1027,7 +1031,11 @@ static void list_file_entry(struct file_struct *f) F_SYMLINK(f)); } else #endif - { + if (missing_args == 2 && f->mode == 0) { + rprintf(FINFO, "%-*s %s\n", + colwidth + 31, "*missing", + f_name(f, NULL)); + } else { rprintf(FINFO, "%s %*s %s %s\n", permbuf, colwidth, comma_num(len), timestring(f->modtime), f_name(f, NULL)); @@ -1140,7 +1148,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, && do_stat(dn, &sx.st) < 0) { if (dry_run) goto parent_is_dry_missing; - if (create_directory_path(fname) < 0) { + if (make_path(fname, MKP_DROP_NAME | MKP_SKIP_SLASH) < 0) { rsyserr(FERROR_XFER, errno, "recv_generator: mkdir %s failed", full_fname(dn)); @@ -1169,6 +1177,14 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, stat_errno = errno; } + if (missing_args == 2 && file->mode == 0) { + if (filter_list.head && check_filter(&filter_list, FINFO, fname, is_dir) < 0) + return; + if (statret == 0) + delete_item(fname, sx.st.st_mode, del_opts); + return; + } + if (ignore_non_existing > 0 && statret == -1 && stat_errno == ENOENT) { if (is_dir) { if (is_dir < 0) @@ -1258,8 +1274,8 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, } if (real_ret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) { if (!relative_paths || errno != ENOENT - || create_directory_path(fname) < 0 - || (do_mkdir(fname, file->mode) < 0 && errno != EEXIST)) { + || make_path(fname, MKP_DROP_NAME | MKP_SKIP_SLASH) < 0 + || (do_mkdir(fname, file->mode) < 0 && errno != EEXIST)) { rsyserr(FERROR_XFER, errno, "recv_generator: mkdir %s failed", full_fname(fname)); @@ -1413,8 +1429,12 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, if ((am_root && preserve_devices && IS_DEVICE(file->mode)) || (preserve_specials && IS_SPECIAL(file->mode))) { - uint32 *devp = F_RDEV_P(file); - dev_t rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)); + dev_t rdev; + if (IS_DEVICE(file->mode)) { + uint32 *devp = F_RDEV_P(file); + rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)); + } else + rdev = 0; if (statret == 0) { int del_for_flag; if (IS_DEVICE(file->mode)) { @@ -1428,7 +1448,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, } if (statret == 0 && BITS_EQUAL(sx.st.st_mode, file->mode, _S_IFMT) - && sx.st.st_rdev == rdev) { + && (IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev == rdev)) { /* The device or special file is identical. */ set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT); if (itemizing) @@ -1641,7 +1661,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, goto cleanup; if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) goto pretend_missing; - if (copy_file(fname, backupptr, -1, back_file->mode, 1) < 0) { + if (copy_file(fname, backupptr, -1, back_file->mode) < 0) { unmake_file(back_file); back_file = NULL; goto cleanup; @@ -1690,20 +1710,11 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, goto cleanup; } if ((f_copy = do_open(backupptr, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) { - int save_errno = errno ? errno : EINVAL; /* 0 paranoia */ - if (errno == ENOENT && make_bak_dir(backupptr) == 0) { - if ((f_copy = do_open(backupptr, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) - save_errno = errno ? errno : save_errno; - else - save_errno = 0; - } - if (save_errno) { - rsyserr(FERROR_XFER, save_errno, "open %s", full_fname(backupptr)); - unmake_file(back_file); - back_file = NULL; - close(fd); - goto cleanup; - } + rsyserr(FERROR_XFER, errno, "open %s", full_fname(backupptr)); + unmake_file(back_file); + back_file = NULL; + close(fd); + goto cleanup; } fnamecmp_type = FNAMECMP_BACKUP; } @@ -2103,12 +2114,18 @@ void generate_files(int f_out, const char *local_name) rprintf(FINFO, "generate_files phase=%d\n", phase); write_ndx(f_out, NDX_DONE); - write_del_stats(f_out); /* Reduce round-trip lag-time for a useless delay-updates phase. */ - if (protocol_version >= 29 && !delay_updates) + if (protocol_version >= 29 && EARLY_DELAY_DONE_MSG()) write_ndx(f_out, NDX_DONE); + if (protocol_version >= 31 && EARLY_DELETE_DONE_MSG()) { + if ((INFO_GTE(STATS, 2) && (delete_mode || force_delete)) || read_batch) + write_del_stats(f_out); + if (EARLY_DELAY_DONE_MSG()) /* Can't send this before delay */ + write_ndx(f_out, NDX_DONE); + } + /* Read MSG_DONE for the redo phase (and any prior messages). */ while (1) { check_for_finished_files(itemizing, code, 0); @@ -2121,8 +2138,11 @@ void generate_files(int f_out, const char *local_name) phase++; if (DEBUG_GTE(GENR, 1)) rprintf(FINFO, "generate_files phase=%d\n", phase); - if (delay_updates) + if (!EARLY_DELAY_DONE_MSG()) { write_ndx(f_out, NDX_DONE); + if (protocol_version >= 31 && EARLY_DELETE_DONE_MSG()) + write_ndx(f_out, NDX_DONE); + } /* Read MSG_DONE for delay-updates phase & prior messages. */ while (msgdone_cnt == 2) wait_for_receiver(); @@ -2136,10 +2156,6 @@ void generate_files(int f_out, const char *local_name) if (delete_after && !solo_file && file_total > 0) do_delete_pass(); - if ((need_retouch_dir_perms || need_retouch_dir_times) - && dir_tweaking && (!inc_recurse || delete_during == 2)) - touch_up_dirs(dir_flist, -1); - if (max_delete >= 0 && skipped_deletes) { rprintf(FWARNING, "Deletions stopped due to --max-delete limit (%d skipped)\n", @@ -2147,6 +2163,22 @@ void generate_files(int f_out, const char *local_name) io_error |= IOERR_DEL_LIMIT; } + if (protocol_version >= 31) { + if (!EARLY_DELETE_DONE_MSG()) { + if (INFO_GTE(STATS, 2) || read_batch) + write_del_stats(f_out); + write_ndx(f_out, NDX_DONE); + } + + /* Read MSG_DONE for late-delete phase & prior messages. */ + while (msgdone_cnt == 3) + wait_for_receiver(); + } + + if ((need_retouch_dir_perms || need_retouch_dir_times) + && dir_tweaking && (!inc_recurse || delete_during == 2)) + touch_up_dirs(dir_flist, -1); + if (DEBUG_GTE(GENR, 1)) rprintf(FINFO, "generate_files finished\n"); }