- if (preserve_times && !S_ISLNK(st->st_mode) &&
- st->st_mtime != file->modtime) {
- updated = 1;
- if (set_modtime(fname,file->modtime) != 0) {
- rprintf(FERROR,"failed to set times on %s : %s\n",
- fname,strerror(errno));
- return 0;
- }
- }
+ if (preserve_times && !S_ISLNK(st->st_mode) &&
+ st->st_mtime != file->modtime) {
+ updated = 1;
+ if (set_modtime(fname,file->modtime) != 0) {
+ rprintf(FERROR,"failed to set times on %s : %s\n",
+ fname,strerror(errno));
+ return 0;
+ }
+ }
+
+ if ((am_root || !am_daemon) &&
+ ((am_root && preserve_uid && st->st_uid != file->uid) ||
+ (preserve_gid && st->st_gid != file->gid))) {
+ if (do_lchown(fname,
+ (am_root&&preserve_uid)?file->uid:-1,
+ preserve_gid?file->gid:-1) != 0) {
+ if (preserve_uid && st->st_uid != file->uid)
+ updated = 1;
+ if (verbose>1 || preserve_uid) {
+ rprintf(FERROR,"chown %s : %s\n",
+ fname,strerror(errno));
+ return 0;
+ }
+ }
+ updated = 1;
+ }