X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/38a4bd432afdb39cca6cccaa671413ffd4d161aa..236adddc18cd4f0e3d91183220af10c11c5cc8a2:/generator.c diff --git a/generator.c b/generator.c index 1d637976..f4f15bb8 100644 --- a/generator.c +++ b/generator.c @@ -27,6 +27,7 @@ extern int dry_run; extern int do_xfers; extern int stdout_format_has_i; extern int logfile_format_has_i; +extern int receiver_symlink_times; extern int am_root; extern int am_server; extern int am_daemon; @@ -41,6 +42,7 @@ extern int preserve_links; extern int preserve_devices; extern int preserve_specials; extern int preserve_hard_links; +extern int preserve_executability; extern int preserve_perms; extern int preserve_times; extern int uid_ndx; @@ -278,7 +280,7 @@ static enum delret delete_dir_contents(char *fname, int flags) } strlcpy(p, fp->basename, remainder); - if (F_OWNER(fp) == our_uid) + if (!uid_ndx || (uid_t)F_OWNER(fp) == our_uid) flags |= DEL_OWNED_BY_US; else flags &= ~DEL_OWNED_BY_US; @@ -503,7 +505,7 @@ static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev) } if (flist_find(cur_flist, fp) < 0) { int flags = DEL_RECURSE - | (F_OWNER(fp) == our_uid ? DEL_OWNED_BY_US : 0); + | (!uid_ndx || (uid_t)F_OWNER(fp) == our_uid ? DEL_OWNED_BY_US : 0); f_name(fp, delbuf); if (delete_during == 2) { if (!remember_delete(fp, delbuf, flags)) @@ -552,7 +554,7 @@ static void do_delete_pass(void) int unchanged_attrs(const char *fname, struct file_struct *file, stat_x *sxp) { -#ifndef HAVE_LUTIMES +#if !defined HAVE_LUTIMES || !defined HAVE_UTIMES if (S_ISLNK(file->mode)) { ; } else @@ -563,6 +565,9 @@ int unchanged_attrs(const char *fname, struct file_struct *file, stat_x *sxp) if (preserve_perms && !BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS)) return 0; + if (preserve_executability && ((sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0))) + return 0; + if (am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file)) return 0; @@ -595,8 +600,11 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre { if (statret >= 0) { /* A from-dest-dir statret can == 1! */ int keep_time = !preserve_times ? 0 - : S_ISDIR(file->mode) ? preserve_times > 1 - : !S_ISLNK(file->mode); + : S_ISDIR(file->mode) ? preserve_times > 1 : +#if defined HAVE_LUTIMES && defined HAVE_UTIMES + (receiver_symlink_times && !(file->flags & FLAG_TIME_FAILED)) || +#endif + !S_ISLNK(file->mode); if (S_ISREG(file->mode) && F_LENGTH(file) != sxp->st.st_size) iflags |= ITEM_REPORT_SIZE; @@ -610,7 +618,8 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre ; } else #endif - if (!BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS)) + if ((preserve_perms || preserve_executability) + && !BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS)) iflags |= ITEM_REPORT_PERMS; if (uid_ndx && am_root && (uid_t)F_OWNER(file) != sxp->st.st_uid) iflags |= ITEM_REPORT_OWNER; @@ -960,7 +969,7 @@ static int try_dests_reg(struct file_struct *file, char *fname, int ndx, goto try_a_copy; if (preserve_hard_links && F_IS_HLINKED(file)) finish_hard_link(file, fname, ndx, &sxp->st, itemizing, code, j); - if (itemizing && (verbose > 1 || stdout_format_has_i > 1)) { + if (!maybe_ATTRS_REPORT && (verbose > 1 || stdout_format_has_i > 1)) { itemize(cmpbuf, file, ndx, 1, sxp, ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0, ""); @@ -1202,38 +1211,40 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, uchar fnamecmp_type; int implied_dirs_are_missing = relative_paths && !implied_dirs && protocol_version < 30; int del_opts = delete_mode || force_delete ? DEL_RECURSE : 0; + int is_dir = !S_ISDIR(file->mode) ? 0 + : inc_recurse && ndx != cur_flist->ndx_start - 1 ? -1 + : 1; if (verbose > 2) rprintf(FINFO, "recv_generator(%s,%d)\n", fname, ndx); if (list_only) { - if (S_ISDIR(file->mode) - && ((!implied_dirs && file->flags & FLAG_IMPLIED_DIR) - || (inc_recurse && ndx != cur_flist->ndx_start - 1))) + if (is_dir < 0 + || (is_dir && !implied_dirs && file->flags & FLAG_IMPLIED_DIR)) return; list_file_entry(file); return; } if (server_filter_list.head) { + int filtered = check_filter(&server_filter_list, fname, is_dir) < 0; + if (is_dir < 0 && filtered) + return; if (excluded_below >= 0) { if (F_DEPTH(file) > excluded_below && (!implied_dirs_are_missing || f_name_has_prefix(file, excluded_dir))) goto skipping; excluded_below = -1; } - if (check_filter(&server_filter_list, fname, - S_ISDIR(file->mode)) < 0) { - if (S_ISDIR(file->mode)) { + if (filtered) { + if (is_dir) { excluded_below = F_DEPTH(file); excluded_dir = file; } skipping: - if (verbose) { - rprintf(FINFO, - "skipping server-excluded file \"%s\"\n", - fname); - } + rprintf(FERROR_XFER, + "skipping daemon-excluded file \"%s\"\n", + fname); return; } } @@ -1245,7 +1256,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, dry_run--; missing_below = -1; } else if (!dry_run) { - if (S_ISDIR(file->mode)) + if (is_dir) file->flags |= FLAG_MISSING_DIR; return; } @@ -1293,18 +1304,14 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, need_fuzzy_dirlist = 0; } - statret = link_stat(fname, &sx.st, - keep_dirlinks && S_ISDIR(file->mode)); + statret = link_stat(fname, &sx.st, keep_dirlinks && is_dir); stat_errno = errno; } if (ignore_non_existing > 0 && statret == -1 && stat_errno == ENOENT) { - if (verbose > 1) { - rprintf(FINFO, "not creating new %s \"%s\"\n", - S_ISDIR(file->mode) ? "directory" : "file", - fname); - } - if (S_ISDIR(file->mode)) { + if (is_dir) { + if (is_dir < 0) + return; if (missing_below < 0) { if (dry_run) dry_run++; @@ -1313,16 +1320,20 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx, } file->flags |= FLAG_MISSING_DIR; } + if (verbose > 1) { + rprintf(FINFO, "not creating new %s \"%s\"\n", + is_dir ? "directory" : "file", fname); + } return; } if (statret == 0 && sx.st.st_uid == our_uid) del_opts |= DEL_OWNED_BY_US; - if (S_ISDIR(file->mode)) { + if (is_dir) { if (!implied_dirs && file->flags & FLAG_IMPLIED_DIR) goto cleanup; - if (inc_recurse && ndx != cur_flist->ndx_start - 1) { + if (is_dir < 0) { /* In inc_recurse mode we want to make sure any missing * directories get created while we're still processing * the parent dir (which allows us to touch the parent