X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/6c3862fae3b6003e0a124c51d84ddb3dff663fc6..8c57732324fb211bc6c3cb0cb5ea2ecb247c8ff2:/generator.c diff --git a/generator.c b/generator.c index fe7f16bc..41cdace8 100644 --- a/generator.c +++ b/generator.c @@ -42,6 +42,7 @@ extern int preserve_gid; extern int preserve_times; extern int omit_dir_times; extern int delete_during; +extern int remove_sent_files; extern int update_only; extern int opt_ignore_existing; extern int inplace; @@ -88,12 +89,14 @@ static int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st) #define SID_UPDATING ITEM_UPDATING #define SID_REPORT_CHECKSUM ITEM_REPORT_CHECKSUM +#define SID_USING_ALT_BASIS ITEM_USING_ALT_BASIS +/* This flag doesn't get sent, so it must be outside 0xffff. */ #define SID_NO_DEST_AND_NO_UPDATE (1<<16) static void itemize(struct file_struct *file, int statret, STRUCT_STAT *st, int32 sflags, int f_out, int ndx) { - int iflags = sflags & (SID_UPDATING | SID_REPORT_CHECKSUM); + int iflags = sflags & 0xffff; if (statret >= 0) { if (S_ISREG(file->mode) && file->length != st->st_size) @@ -344,7 +347,7 @@ static void recv_generator(char *fname, struct file_list *flist, struct file_struct *file, int ndx, int f_out, int f_out_name) { - static int missing_below = -1; + static int missing_below = -1, excluded_below = -1; static char *fuzzy_dirname = NULL; static struct file_list *fuzzy_dirlist = NULL; struct file_struct *fuzzy_file = NULL; @@ -354,7 +357,7 @@ static void recv_generator(char *fname, struct file_list *flist, int statret, stat_errno; char *fnamecmp, *partialptr, *backupptr = NULL; char fnamecmpbuf[MAXPATHLEN]; - int itemizing, maybe_DEL_TERSE, maybe_PERMS_REPORT; + int itemizing, maybe_PERMS_REPORT; uchar fnamecmp_type; enum logcode code; @@ -364,22 +367,18 @@ static void recv_generator(char *fname, struct file_list *flist, if (protocol_version >= 29) { itemizing = 1; code = daemon_log_format_has_i ? 0 : FLOG; - maybe_DEL_TERSE = log_format_has_o_or_i ? 0 : DEL_TERSE; maybe_PERMS_REPORT = log_format_has_i ? 0 : PERMS_REPORT; } else if (am_daemon) { itemizing = daemon_log_format_has_i && !dry_run; code = itemizing || dry_run ? FCLIENT : FINFO; - maybe_DEL_TERSE = DEL_TERSE; maybe_PERMS_REPORT = PERMS_REPORT; } else if (!am_server) { itemizing = log_format_has_i; code = itemizing ? 0 : FINFO; - maybe_DEL_TERSE = log_format_has_o_or_i ? 0 : DEL_TERSE; maybe_PERMS_REPORT = log_format_has_i ? 0 : PERMS_REPORT; } else { itemizing = 0; code = FINFO; - maybe_DEL_TERSE = DEL_TERSE; maybe_PERMS_REPORT = PERMS_REPORT; } @@ -401,14 +400,24 @@ static void recv_generator(char *fname, struct file_list *flist, safe_fname(fname), ndx); } - if (server_filter_list.head - && check_filter(&server_filter_list, fname, - S_ISDIR(file->mode)) < 0) { - if (verbose) { - rprintf(FINFO, "skipping server-excluded file \"%s\"\n", - safe_fname(fname)); + if (server_filter_list.head) { + if (excluded_below >= 0) { + if (file->dir.depth > excluded_below) + goto skipping; + excluded_below = -1; + } + if (check_filter(&server_filter_list, fname, + S_ISDIR(file->mode)) < 0) { + if (S_ISDIR(file->mode)) + excluded_below = file->dir.depth; + skipping: + if (verbose) { + rprintf(FINFO, + "skipping server-excluded file \"%s\"\n", + safe_fname(fname)); + } + return; } - return; } if (missing_below >= 0 && file->dir.depth <= missing_below) { @@ -461,7 +470,7 @@ static void recv_generator(char *fname, struct file_list *flist, * we need to delete it. If it doesn't exist, then * (perhaps recursively) create it. */ if (statret == 0 && !S_ISDIR(st.st_mode)) { - delete_file(fname, st.st_mode, maybe_DEL_TERSE); + delete_file(fname, st.st_mode, DEL_TERSE); statret = -1; } if (dry_run && statret != 0 && missing_below < 0) { @@ -532,7 +541,7 @@ static void recv_generator(char *fname, struct file_list *flist, if (S_ISLNK(st.st_mode)) delete_file(fname, st.st_mode, DEL_TERSE); else { - delete_file(fname, st.st_mode, maybe_DEL_TERSE); + delete_file(fname, st.st_mode, DEL_TERSE); statret = -1; } } @@ -549,6 +558,11 @@ static void recv_generator(char *fname, struct file_list *flist, rprintf(code, "%s -> %s\n", safe_fname(fname), safe_fname(file->u.link)); } + if (remove_sent_files && !dry_run) { + char numbuf[4]; + SIVAL(numbuf, 0, ndx); + send_msg(MSG_SUCCESS, numbuf, 4); + } } #endif return; @@ -561,7 +575,7 @@ static void recv_generator(char *fname, struct file_list *flist, if (IS_DEVICE(st.st_mode)) delete_file(fname, st.st_mode, DEL_TERSE); else { - delete_file(fname, st.st_mode, maybe_DEL_TERSE); + delete_file(fname, st.st_mode, DEL_TERSE); statret = -1; } if (verbose > 2) { @@ -661,7 +675,7 @@ static void recv_generator(char *fname, struct file_list *flist, } if (statret == 0 && !S_ISREG(st.st_mode)) { - if (delete_file(fname, st.st_mode, maybe_DEL_TERSE) != 0) + if (delete_file(fname, st.st_mode, DEL_TERSE) != 0) return; statret = -1; stat_errno = ENOENT; @@ -809,11 +823,12 @@ prepare_to_open: notify_others: write_int(f_out, ndx); if (itemizing) { - itemize(file, statret, &st, SID_UPDATING - | (always_checksum ? SID_REPORT_CHECKSUM : 0), - f_out, -1); - if (inplace && !read_batch) - write_byte(f_out, fnamecmp_type); + int iflags = SID_UPDATING; + if (always_checksum) + iflags |= SID_REPORT_CHECKSUM; + if (inplace && fnamecmp_type != FNAMECMP_FNAME) + iflags |= SID_USING_ALT_BASIS; + itemize(file, statret, &st, iflags, f_out, -1); } if (f_out_name >= 0) { write_byte(f_out_name, fnamecmp_type); @@ -829,7 +844,7 @@ notify_others: #endif } *lb = len; - write_buf(f_out_name, lenbuf, lb - lenbuf + 1); + write_buf(f_out_name, (char*)lenbuf, lb - lenbuf + 1); write_buf(f_out_name, fuzzy_file->basename, len); } } @@ -873,10 +888,10 @@ void generate_files(int f_out, struct file_list *flist, char *local_name, } if (verbose >= 2) { - rprintf(FINFO, + rprintf(FINFO, "delta-transmission %s\n", whole_file > 0 - ? "delta-transmission disabled for local transfer or --whole-file\n" - : "delta transmission enabled\n"); + ? "disabled for local transfer or --whole-file" + : "enabled"); } /* We expect to just sit around now, so don't exit on a timeout.