X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/c8ca974634277761d57c0f95274369436bf0fe66..8e3ead09a3768d1b38f65c8e296903af5fbbbc42:/generator.c diff --git a/generator.c b/generator.c index 6cbba4ed..f59a5128 100644 --- a/generator.c +++ b/generator.c @@ -25,11 +25,15 @@ extern int verbose; extern int dry_run; -extern int itemize_changes; +extern int log_format_has_i; +extern int log_format_has_o_or_i; +extern int daemon_log_format_has_i; +extern int am_root; +extern int am_server; +extern int am_daemon; extern int relative_paths; extern int keep_dirlinks; extern int preserve_links; -extern int am_root; extern int preserve_devices; extern int preserve_hard_links; extern int preserve_perms; @@ -62,6 +66,7 @@ extern int only_existing; extern int orig_umask; extern int safe_symlinks; extern long block_size; /* "long" because popt can't set an int32. */ +extern struct stats stats; extern struct filter_list_struct server_filter_list; @@ -81,51 +86,45 @@ static int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st) } -#define SC_CHECKSUM_CHANGED (1<<0) -#define SC_UPDATING (1<<1) -#define SC_NO_DEST_AND_NO_UPDATE (1<<2) -#define SC_SKIP_NL (1<<3) +#define SID_UPDATING ITEM_UPDATING +#define SID_REPORT_CHECKSUM ITEM_REPORT_CHECKSUM +#define SID_NO_DEST_AND_NO_UPDATE (1<<16) -static void showchg(const char *fname, struct file_struct *file, int statret, - STRUCT_STAT *st, int flags) +static void itemize(struct file_struct *file, int statret, STRUCT_STAT *st, + int32 sflags, int f_out, int ndx) { - static char ch[] = "*Xcstpog"; - int keep_time; - char *s; - - ch[0] = flags & SC_UPDATING ? '*' : ' '; - ch[1] = S_ISDIR(file->mode) ? 'd' : IS_DEVICE(file->mode) ? 'D' - : S_ISLNK(file->mode) ? 'L' : 'f'; - - if (statret < 0) { - for (s = ch + 2; *s; ) *s++ = '+'; - goto print_it; - } - - keep_time = !preserve_times ? 0 - : S_ISDIR(file->mode) ? !omit_dir_times : !S_ISLNK(file->mode); - - ch[2] = !(flags & SC_CHECKSUM_CHANGED) ? '-' : 'c'; - ch[3] = !S_ISREG(file->mode) || file->length == st->st_size ? '-' : 's'; - ch[4] = flags & SC_UPDATING && !keep_time ? 'T' - : !keep_time || file->modtime == st->st_mtime ? '-' : 't'; - ch[5] = !preserve_perms || file->mode == st->st_mode ? '-' : 'p'; - ch[6] = !am_root || !preserve_uid || file->uid == st->st_uid ? '-' : 'o'; - ch[7] = preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid ? 'g' : '-'; - - if (flags & SC_NO_DEST_AND_NO_UPDATE) - ch[4] = ch[5] = ch[6] = ch[7] = '-'; + int iflags = sflags & (SID_UPDATING | SID_REPORT_CHECKSUM); + + if (statret >= 0) { + if (S_ISREG(file->mode) && file->length != st->st_size) + iflags |= ITEM_REPORT_SIZE; + if (!(sflags & SID_NO_DEST_AND_NO_UPDATE)) { + int keep_time = !preserve_times ? 0 + : S_ISDIR(file->mode) ? !omit_dir_times + : !S_ISLNK(file->mode); + + if ((iflags & ITEM_UPDATING && !keep_time) + || (keep_time && file->modtime != st->st_mtime)) + iflags |= ITEM_REPORT_TIME; + if (preserve_perms && file->mode != st->st_mode) + iflags |= ITEM_REPORT_PERMS; + if (preserve_uid && am_root && file->uid != st->st_uid) + iflags |= ITEM_REPORT_OWNER; + if (preserve_gid && file->gid != GID_NONE + && st->st_gid != file->gid) + iflags |= ITEM_REPORT_GROUP; + } + } else + iflags |= ITEM_IS_NEW | ITEM_UPDATING; - if (!(flags & SC_UPDATING)) { - for (s = ch + 2; *s == '-'; s++) {} - if (!*s) - return; + if ((iflags || verbose > 1) && !read_batch) { + if (protocol_version >= 29) { + if (ndx >= 0) + write_int(f_out, ndx); + write_shortint(f_out, iflags); + } else if (ndx >= 0) + log_recv(file, &stats, iflags); } - - print_it: - rprintf(FINFO, "%s %s%s%s", ch, safe_fname(fname), - ch[1] == 'd' ? "/" : "", - flags & SC_SKIP_NL ? "" : "\n"); } @@ -345,7 +344,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; @@ -355,11 +354,31 @@ 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_PERMS_REPORT; uchar fnamecmp_type; + enum logcode code; if (list_only) return; + if (protocol_version >= 29) { + itemizing = 1; + code = daemon_log_format_has_i ? 0 : FLOG; + 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_PERMS_REPORT = PERMS_REPORT; + } else if (!am_server) { + itemizing = log_format_has_i; + code = itemizing ? 0 : FINFO; + maybe_PERMS_REPORT = log_format_has_i ? 0 : PERMS_REPORT; + } else { + itemizing = 0; + code = FINFO; + maybe_PERMS_REPORT = PERMS_REPORT; + } + if (!fname) { if (fuzzy_dirlist) { flist_free(fuzzy_dirlist); @@ -378,14 +397,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) { @@ -438,15 +467,15 @@ 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, DEL_TERSE); + delete_file(fname, st.st_mode, DEL_TERSE); statret = -1; } if (dry_run && statret != 0 && missing_below < 0) { missing_below = file->dir.depth; dry_run++; } - if (itemize_changes && f_out != -1) - showchg(fname, file, statret, &st, 0); + if (itemizing && f_out != -1) + itemize(file, statret, &st, 0, f_out, ndx); if (statret != 0 && do_mkdir(fname,file->mode) != 0 && errno != EEXIST) { if (!relative_paths || errno != ENOENT || create_directory_path(fname, orig_umask) < 0 @@ -457,14 +486,14 @@ static void recv_generator(char *fname, struct file_list *flist, } } if (set_perms(fname, file, statret ? NULL : &st, 0) - && verbose && f_out != -1 && !itemize_changes) - rprintf(FINFO, "%s/\n", safe_fname(fname)); + && verbose && code && f_out != -1) + rprintf(code, "%s/\n", safe_fname(fname)); if (delete_during && f_out != -1 && csum_length != SUM_LENGTH && (file->flags & FLAG_DEL_HERE)) delete_in_dir(flist, fname, file); return; } - + if (max_size && file->length > max_size) { if (verbose > 1) { rprintf(FINFO, "%s is over max-size\n", @@ -485,42 +514,46 @@ static void recv_generator(char *fname, struct file_list *flist, return; } if (statret == 0) { - int dflag = S_ISDIR(st.st_mode) ? DEL_DIR : 0; char lnk[MAXPATHLEN]; int len; - if (!dflag + if (!S_ISDIR(st.st_mode) && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) { lnk[len] = 0; /* A link already pointing to the * right place -- no further action * required. */ if (strcmp(lnk, file->u.link) == 0) { - if (itemize_changes) - showchg(fname, file, 0, &st, 0); + if (itemizing) { + itemize(file, 0, &st, 0, + f_out, ndx); + } set_perms(fname, file, &st, - PERMS_REPORT); + maybe_PERMS_REPORT); return; } } /* Not the right symlink (or not a symlink), so * delete it. */ - delete_file(fname, dflag | DEL_TERSE); + if (S_ISLNK(st.st_mode)) + delete_file(fname, st.st_mode, DEL_TERSE); + else { + delete_file(fname, st.st_mode, DEL_TERSE); + statret = -1; + } } if (do_symlink(file->u.link,fname) != 0) { rsyserr(FERROR, errno, "symlink %s -> \"%s\" failed", full_fname(fname), safe_fname(file->u.link)); } else { set_perms(fname,file,NULL,0); - if (itemize_changes) { - showchg(fname, file, statret, &st, - SC_UPDATING - | (verbose ? SC_SKIP_NL : 0)); + if (itemizing) { + itemize(file, statret, &st, SID_UPDATING, + f_out, ndx); } - if (verbose) { - rprintf(FINFO, "%s -> %s\n", - itemize_changes ? "" : safe_fname(fname), - safe_fname(file->u.link)); + if (code && verbose) { + rprintf(code, "%s -> %s\n", safe_fname(fname), + safe_fname(file->u.link)); } } #endif @@ -531,10 +564,12 @@ static void recv_generator(char *fname, struct file_list *flist, if (statret != 0 || st.st_mode != file->mode || st.st_rdev != file->u.rdev) { - int dflag = S_ISDIR(st.st_mode) ? DEL_DIR : 0; - if (itemize_changes) - showchg(fname, file, statret, &st, SC_UPDATING); - delete_file(fname, dflag | DEL_TERSE); + if (IS_DEVICE(st.st_mode)) + delete_file(fname, st.st_mode, DEL_TERSE); + else { + delete_file(fname, st.st_mode, DEL_TERSE); + statret = -1; + } if (verbose > 2) { rprintf(FINFO,"mknod(%s,0%o,0x%x)\n", safe_fname(fname), @@ -545,15 +580,21 @@ static void recv_generator(char *fname, struct file_list *flist, full_fname(fname)); } else { set_perms(fname,file,NULL,0); - if (verbose && !itemize_changes) { - rprintf(FINFO, "%s\n", + if (itemizing) { + itemize(file, statret, &st, SID_UPDATING, + f_out, ndx); + } + if (code && verbose) { + rprintf(code, "%s\n", safe_fname(fname)); } } } else { - if (itemize_changes) - showchg(fname, file, statret, &st, 0); - set_perms(fname, file, &st, PERMS_REPORT); + if (itemizing) { + itemize(file, statret, &st, 0, + f_out, ndx); + } + set_perms(fname, file, &st, maybe_PERMS_REPORT); } return; } @@ -626,8 +667,7 @@ static void recv_generator(char *fname, struct file_list *flist, } if (statret == 0 && !S_ISREG(st.st_mode)) { - int dflag = S_ISDIR(st.st_mode) ? DEL_DIR : 0; - if (delete_file(fname, dflag | DEL_TERSE) != 0) + if (delete_file(fname, st.st_mode, DEL_TERSE) != 0) return; statret = -1; stat_errno = ENOENT; @@ -690,13 +730,14 @@ static void recv_generator(char *fname, struct file_list *flist, else if (fnamecmp_type == FNAMECMP_FUZZY) ; else if (unchanged_file(fnamecmp, file, &st)) { - if (itemize_changes) { - showchg(fname, file, statret, &st, - fnamecmp_type == FNAMECMP_FNAME ? 0 - : SC_NO_DEST_AND_NO_UPDATE); + if (itemizing) { + itemize(file, statret, &st, + fnamecmp_type == FNAMECMP_FNAME + ? 0 : SID_NO_DEST_AND_NO_UPDATE, + f_out, ndx); } if (fnamecmp_type == FNAMECMP_FNAME) - set_perms(fname, file, &st, PERMS_REPORT); + set_perms(fname, file, &st, maybe_PERMS_REPORT); return; } @@ -773,8 +814,13 @@ prepare_to_open: notify_others: write_int(f_out, ndx); - if (protocol_version >= 29 && inplace && !read_batch) - write_byte(f_out, fnamecmp_type); + 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); + } if (f_out_name >= 0) { write_byte(f_out_name, fnamecmp_type); if (fnamecmp_type == FNAMECMP_FUZZY) { @@ -793,11 +839,6 @@ notify_others: write_buf(f_out_name, fuzzy_file->basename, len); } } - if (itemize_changes) { - showchg(fname, file, statret, &st, - (always_checksum ? SC_CHECKSUM_CHANGED : 0) - | SC_UPDATING); - } if (dry_run || read_batch) return;