X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/907e6a32a00ace7cf1e96f9c9132f83f4a208430..b223d96bf0d040cfa445a45213fc517ab8389785:/rsync.c diff --git a/rsync.c b/rsync.c index 3d45d01b..c42d5535 100644 --- a/rsync.c +++ b/rsync.c @@ -36,12 +36,11 @@ extern int preserve_times; extern int am_root; extern int am_server; extern int am_sender; +extern int am_receiver; extern int am_generator; extern int am_starting_up; extern int allow_8bit_chars; extern int protocol_version; -extern int uid_ndx; -extern int gid_ndx; extern int inc_recurse; extern int inplace; extern int flist_eof; @@ -149,7 +148,7 @@ void setup_iconv(void) * can wrap around to the start, and the xbuf may have its ".size" reduced * (presumably by 1 byte) if the iconv code doesn't have space to store a * multi-byte character at the physical end of the ".buf" (though no reducing - * happens if ".pos" is < 1, since there is no room to wrap around). + * happens if ".pos" is <= 1, since there is no room to wrap around). * * If ICB_EXPAND_OUT is set in "flags", the "out" xbuf will be allocated if * empty, and (as long as ICB_CIRCULAR_OUT is not set) expanded if too small. @@ -364,11 +363,10 @@ int read_ndx_and_attrs(int f_in, int f_out, int *iflag_ptr, uchar *type_ptr, iflags = protocol_version >= 29 ? read_shortint(f_in) : ITEM_TRANSFER | ITEM_MISSING_DATA; - /* Honor the old-style keep-alive indicator. */ - if (protocol_version < 30 - && ndx == cur_flist->used && iflags == ITEM_IS_NEW) { + /* Support the protocol-29 keep-alive style. */ + if (protocol_version < 30 && ndx == cur_flist->used && iflags == ITEM_IS_NEW) { if (am_sender) - maybe_send_keepalive(); + maybe_send_keepalive(time(NULL), MSK_ALLOW_FLUSH); goto read_loop; } @@ -489,7 +487,9 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, set_xattr(fname, file, fnamecmp, sxp); #endif - if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && preserve_times == 1)) + if (!preserve_times + || (!(preserve_times & PRESERVE_DIR_TIMES) && S_ISDIR(sxp->st.st_mode)) + || (!(preserve_times & PRESERVE_LINK_TIMES) && S_ISLNK(sxp->st.st_mode))) flags |= ATTRS_SKIP_MTIME; if (!(flags & ATTRS_SKIP_MTIME) && cmp_time(sxp->st.st_mtime, file->modtime) != 0) { @@ -508,7 +508,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file); change_gid = gid_ndx && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file); -#if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK +#ifndef CAN_CHOWN_SYMLINK if (S_ISLNK(sxp->st.st_mode)) { ; } else @@ -527,9 +527,9 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, } } if (am_root >= 0) { - if (do_lchown(fname, - change_uid ? (uid_t)F_OWNER(file) : sxp->st.st_uid, - change_gid ? (gid_t)F_GROUP(file) : sxp->st.st_gid) != 0) { + uid_t uid = change_uid ? (uid_t)F_OWNER(file) : sxp->st.st_uid; + gid_t gid = change_gid ? (gid_t)F_GROUP(file) : sxp->st.st_gid; + if (do_lchown(fname, uid, gid) != 0) { /* We shouldn't have attempted to change uid * or gid unless have the privilege. */ rsyserr(FERROR_XFER, errno, "%s %s failed", @@ -537,6 +537,10 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, full_fname(fname)); goto cleanup; } + if (uid == (uid_t)-1 && sxp->st.st_uid != (uid_t)-1) + rprintf(FERROR_XFER, "uid 4294967295 (-1) is impossible to set on %s\n", full_fname(fname)); + if (gid == (gid_t)-1 && sxp->st.st_gid != (gid_t)-1) + rprintf(FERROR_XFER, "gid 4294967295 (-1) is impossible to set on %s\n", full_fname(fname)); /* A lchown had been done, so we need to re-stat if * the destination had the setuid or setgid bits set * (due to the side effect of the chown call). */ @@ -644,15 +648,13 @@ int finish_transfer(const char *fname, const char *fnametmp, /* move tmp file over real file */ if (DEBUG_GTE(RECV, 1)) rprintf(FINFO, "renaming %s to %s\n", fnametmp, fname); - ret = robust_rename(fnametmp, fname, temp_copy_name, - file->mode & INITACCESSPERMS); + ret = robust_rename(fnametmp, fname, temp_copy_name, file->mode); if (ret < 0) { rsyserr(FERROR_XFER, errno, "%s %s -> \"%s\"", ret == -2 ? "copy" : "rename", full_fname(fnametmp), fname); if (!partialptr || (ret == -2 && temp_copy_name) - || robust_rename(fnametmp, partialptr, NULL, - file->mode & INITACCESSPERMS) < 0) + || robust_rename(fnametmp, partialptr, NULL, file->mode) < 0) do_unlink(fnametmp); return 0; } @@ -719,5 +721,8 @@ const char *who_am_i(void) { if (am_starting_up) return am_server ? "server" : "client"; - return am_sender ? "sender" : am_generator ? "generator" : "receiver"; + return am_sender ? "sender" + : am_generator ? "generator" + : am_receiver ? "receiver" + : "Receiver"; /* pre-forked receiver */ }