-int recv_files(int f_in,struct file_list *flist,char *local_name)
-{
- int fd1,fd2;
- struct stat st;
- char *fname;
- char fnametmp[MAXPATHLEN];
- char *buf;
- int i;
-
- if (verbose > 2) {
- fprintf(stderr,"recv_files(%d) starting\n",flist->count);
- }
-
- if (recurse && delete_mode && !local_name && flist->count>0) {
- delete_files(flist);
- }
-
- while (1)
- {
- i = read_int(f_in);
- if (i == -1) break;
-
- fname = flist->files[i].name;
-
- if (local_name)
- fname = local_name;
-
- if (dry_run) {
- if (!am_server && verbose)
- printf("%s\n",fname);
- continue;
- }
-
- if (verbose > 2)
- fprintf(stderr,"recv_files(%s)\n",fname);
-
- /* open the file */
- fd1 = open(fname,O_RDONLY);
-
- if (fd1 != -1 && fstat(fd1,&st) != 0) {
- fprintf(stderr,"fstat %s : %s\n",fname,strerror(errno));
- close(fd1);
- return -1;
- }
-
- if (fd1 != -1 && !S_ISREG(st.st_mode)) {
- fprintf(stderr,"%s : not a regular file\n",fname);
- close(fd1);
- return -1;
- }
-
- if (fd1 != -1 && st.st_size > 0) {
- buf = map_file(fd1,st.st_size);
- } else {
- buf = NULL;
- }
-
- if (verbose > 2)
- fprintf(stderr,"mapped %s of size %d\n",fname,(int)st.st_size);
-
- /* open tmp file */
- sprintf(fnametmp,"%s.XXXXXX",fname);
- if (NULL == mktemp(fnametmp)) {
- fprintf(stderr,"mktemp %s failed\n",fnametmp);
- return -1;
- }
- fd2 = open(fnametmp,O_WRONLY|O_CREAT,flist->files[i].mode);
- if (fd2 == -1) {
- fprintf(stderr,"open %s : %s\n",fnametmp,strerror(errno));
- return -1;
- }
-
- cleanup_fname = fnametmp;
-
- if (!am_server && verbose)
- printf("%s\n",fname);
-
- /* recv file data */
- receive_data(f_in,buf,fd2,fname);
-
- if (fd1 != -1) {
- unmap_file(buf,st.st_size);
- close(fd1);
- }
- close(fd2);
-
- if (verbose > 2)
- fprintf(stderr,"renaming %s to %s\n",fnametmp,fname);
-
- if (make_backups) {
- char fnamebak[MAXPATHLEN];
- sprintf(fnamebak,"%s%s",fname,backup_suffix);
- if (rename(fname,fnamebak) != 0 && errno != ENOENT) {
- fprintf(stderr,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
- exit(1);
+ if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && preserve_times == 1))
+ flags |= ATTRS_SKIP_MTIME;
+ if (!(flags & ATTRS_SKIP_MTIME)
+ && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
+ int ret = set_modtime(fname, file->modtime, F_MOD_NSEC(file), sxp->st.st_mode);
+ if (ret < 0) {
+ rsyserr(FERROR_XFER, errno, "failed to set times on %s",
+ full_fname(fname));
+ goto cleanup;
+ }
+ if (ret == 0) /* ret == 1 if symlink could not be set */
+ updated = 1;
+ else
+ file->flags |= FLAG_TIME_FAILED;
+ }
+
+ 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
+ if (S_ISLNK(sxp->st.st_mode)) {
+ ;
+ } else
+#endif
+ if (change_uid || change_gid) {
+ if (DEBUG_GTE(OWN, 1)) {
+ if (change_uid) {
+ rprintf(FINFO,
+ "set uid of %s from %u to %u\n",
+ fname, (unsigned)sxp->st.st_uid, F_OWNER(file));
+ }
+ if (change_gid) {
+ rprintf(FINFO,
+ "set gid of %s from %u to %u\n",
+ fname, (unsigned)sxp->st.st_gid, F_GROUP(file));
+ }
+ }
+ 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) {
+ /* We shouldn't have attempted to change uid
+ * or gid unless have the privilege. */
+ rsyserr(FERROR_XFER, errno, "%s %s failed",
+ change_uid ? "chown" : "chgrp",
+ full_fname(fname));
+ goto cleanup;
+ }
+ /* 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). */
+ if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
+ link_stat(fname, &sxp->st,
+ keep_dirlinks && S_ISDIR(sxp->st.st_mode));
+ }
+ }
+ updated = 1;