X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/a1cbe76e2c572e7762d1e5ce4dad85891a8fba6e..0cc279e0d367b71e86b372ddd8f9ba499a968196:/generator.c diff --git a/generator.c b/generator.c index 552e5c70..6cbba4ed 100644 --- a/generator.c +++ b/generator.c @@ -25,6 +25,7 @@ extern int verbose; extern int dry_run; +extern int itemize_changes; extern int relative_paths; extern int keep_dirlinks; extern int preserve_links; @@ -79,6 +80,55 @@ static int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st) return 1; } + +#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) + +static void showchg(const char *fname, struct file_struct *file, int statret, + STRUCT_STAT *st, int flags) +{ + 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] = '-'; + + if (!(flags & SC_UPDATING)) { + for (s = ch + 2; *s == '-'; s++) {} + if (!*s) + return; + } + + print_it: + rprintf(FINFO, "%s %s%s%s", ch, safe_fname(fname), + ch[1] == 'd' ? "/" : "", + flags & SC_SKIP_NL ? "" : "\n"); +} + + /* Perform our quick-check heuristic for determining if a file is unchanged. */ static int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st) { @@ -228,6 +278,7 @@ static void generate_and_send_sums(int fd, OFF_T len, int f_out, int f_copy) unmap_file(mapbuf); } + /* Try to find a filename in the same dir as "fname" with a similar name. */ static int find_fuzzy(struct file_struct *file, struct file_list *dirlist) { @@ -394,6 +445,8 @@ static void recv_generator(char *fname, struct file_list *flist, missing_below = file->dir.depth; dry_run++; } + if (itemize_changes && f_out != -1) + showchg(fname, file, statret, &st, 0); if (statret != 0 && do_mkdir(fname,file->mode) != 0 && errno != EEXIST) { if (!relative_paths || errno != ENOENT || create_directory_path(fname, orig_umask) < 0 @@ -404,13 +457,15 @@ static void recv_generator(char *fname, struct file_list *flist, } } if (set_perms(fname, file, statret ? NULL : &st, 0) - && verbose && f_out != -1) + && verbose && f_out != -1 && !itemize_changes) rprintf(FINFO, "%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; - } else if (max_size && file->length > max_size) { + } + + if (max_size && file->length > max_size) { if (verbose > 1) { rprintf(FINFO, "%s is over max-size\n", safe_fname(fname)); @@ -441,6 +496,8 @@ static void recv_generator(char *fname, struct file_list *flist, * right place -- no further action * required. */ if (strcmp(lnk, file->u.link) == 0) { + if (itemize_changes) + showchg(fname, file, 0, &st, 0); set_perms(fname, file, &st, PERMS_REPORT); return; @@ -455,9 +512,15 @@ static void recv_generator(char *fname, struct file_list *flist, 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 (verbose) { - rprintf(FINFO, "%s -> %s\n", safe_fname(fname), - safe_fname(file->u.link)); + rprintf(FINFO, "%s -> %s\n", + itemize_changes ? "" : safe_fname(fname), + safe_fname(file->u.link)); } } #endif @@ -469,6 +532,8 @@ static void recv_generator(char *fname, struct file_list *flist, 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 (verbose > 2) { rprintf(FINFO,"mknod(%s,0%o,0x%x)\n", @@ -480,12 +545,14 @@ static void recv_generator(char *fname, struct file_list *flist, full_fname(fname)); } else { set_perms(fname,file,NULL,0); - if (verbose) { + if (verbose && !itemize_changes) { rprintf(FINFO, "%s\n", safe_fname(fname)); } } } else { + if (itemize_changes) + showchg(fname, file, statret, &st, 0); set_perms(fname, file, &st, PERMS_REPORT); } return; @@ -503,7 +570,7 @@ static void recv_generator(char *fname, struct file_list *flist, fnamecmp = fname; fnamecmp_type = FNAMECMP_FNAME; - if (statret == -1 && basis_dir[0] != NULL) { + if (statret != 0 && basis_dir[0] != NULL) { int fallback_match = -1; int match_level = 0; int i = 0; @@ -569,12 +636,12 @@ static void recv_generator(char *fname, struct file_list *flist, if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL && link_stat(partialptr, &partial_st, 0) == 0 && S_ISREG(partial_st.st_mode)) { - if (statret == -1) + if (statret != 0) goto prepare_to_open; } else partialptr = NULL; - if (statret == -1 && fuzzy_basis && dry_run <= 1) { + if (statret != 0 && fuzzy_basis && dry_run <= 1) { int j = find_fuzzy(file, fuzzy_dirlist); if (j >= 0) { fuzzy_file = fuzzy_dirlist->files[j]; @@ -592,7 +659,7 @@ static void recv_generator(char *fname, struct file_list *flist, } } - if (statret == -1) { + if (statret != 0) { if (preserve_hard_links && hard_link_check(file, HL_SKIP)) return; if (stat_errno == ENOENT) @@ -623,6 +690,11 @@ 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 (fnamecmp_type == FNAMECMP_FNAME) set_perms(fname, file, &st, PERMS_REPORT); return; @@ -639,7 +711,8 @@ prepare_to_open: if (dry_run || read_batch) goto notify_others; if (whole_file > 0) { - statret = -1; + if (statret == 0) + statret = 1; goto notify_others; } @@ -720,6 +793,11 @@ 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;