- if (preserve_times && !S_ISLNK(st->st_mode) &&
- st->st_mtime != file->modtime) {
- /* don't complain about not setting times on directories
- because some filesystems can't do it */
- if (set_modtime(fname,file->modtime) != 0 &&
- !S_ISDIR(st->st_mode)) {
- rprintf(FERROR,"failed to set times on %s : %s\n",
- fname,strerror(errno));
+ if (iflags & ITEM_BASIS_TYPE_FOLLOWS)
+ fnamecmp_type = read_byte(f_in);
+ *type_ptr = fnamecmp_type;
+
+ if (iflags & ITEM_XNAME_FOLLOWS) {
+ if ((len = read_vstring(f_in, buf, MAXPATHLEN)) < 0)
+ exit_cleanup(RERR_PROTOCOL);
+ } else {
+ *buf = '\0';
+ len = -1;
+ }
+ *len_ptr = len;
+
+ if (iflags & ITEM_TRANSFER) {
+ int i = ndx - cur_flist->ndx_start;
+ if (i < 0 || !S_ISREG(cur_flist->files[i]->mode)) {
+ rprintf(FERROR,
+ "received request to transfer non-regular file: %d [%s]\n",
+ ndx, who_am_i());
+ exit_cleanup(RERR_PROTOCOL);
+ }
+ }
+
+ *iflag_ptr = iflags;
+ return ndx;
+}
+
+/*
+ free a sums struct
+ */
+void free_sums(struct sum_struct *s)
+{
+ if (s->sums) free(s->sums);
+ free(s);
+}
+
+/* This is only called when we aren't preserving permissions. Figure out what
+ * the permissions should be and return them merged back into the mode. */
+mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms,
+ int exists)
+{
+ int new_mode;
+ /* If the file already exists, we'll return the local permissions,
+ * possibly tweaked by the --executability option. */
+ if (exists) {
+ new_mode = (flist_mode & ~CHMOD_BITS) | (stat_mode & CHMOD_BITS);
+ if (preserve_executability && S_ISREG(flist_mode)) {
+ /* If the source file is executable, grant execute
+ * rights to everyone who can read, but ONLY if the
+ * file isn't already executable. */
+ if (!(flist_mode & 0111))
+ new_mode &= ~0111;
+ else if (!(stat_mode & 0111))
+ new_mode |= (new_mode & 0444) >> 2;
+ }
+ } else {
+ /* Apply destination default permissions and turn
+ * off special permissions. */
+ new_mode = flist_mode & (~CHMOD_BITS | dflt_perms);
+ }
+ return new_mode;
+}
+
+int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
+ const char *fnamecmp, int flags)
+{
+ int updated = 0;
+ stat_x sx2;
+ int change_uid, change_gid;
+ mode_t new_mode = file->mode;
+ int inherit;
+
+ if (!sxp) {
+ if (dry_run)
+ return 1;
+ if (link_stat(fname, &sx2.st, 0) < 0) {
+ rsyserr(FERROR_XFER, errno, "stat %s failed",
+ full_fname(fname));