MCPcopy Create free account
hub / github.com/RsyncProject/rsync / set_file_attrs

Function set_file_attrs

rsync.c:489–682  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487}
488
489int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
490 const char *fnamecmp, int flags)
491{
492 int updated = 0;
493 stat_x sx2;
494 int change_uid, change_gid;
495 mode_t new_mode = file->mode;
496 int inherit;
497
498 if (!sxp) {
499 if (dry_run)
500 return 1;
501 if (link_stat(fname, &sx2.st, 0) < 0) {
502 rsyserr(FERROR_XFER, errno, "stat %s failed",
503 full_fname(fname));
504 return 0;
505 }
506 init_stat_x(&sx2);
507 sxp = &sx2;
508 inherit = !preserve_perms;
509 } else
510 inherit = !preserve_perms && file->flags & FLAG_DIR_CREATED;
511
512 if (inherit && S_ISDIR(new_mode) && sxp->st.st_mode & S_ISGID) {
513 /* We just created this directory and its setgid
514 * bit is on, so make sure it stays on. */
515 new_mode |= S_ISGID;
516 }
517
518 if (daemon_chmod_modes && !S_ISLNK(new_mode))
519 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
520
521#ifdef SUPPORT_ACLS
522 if (preserve_acls && !S_ISLNK(file->mode) && !ACL_READY(*sxp))
523 get_acl(fname, sxp);
524#endif
525
526 change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file);
527 change_gid = gid_ndx && !(file->flags & FLAG_SKIP_GROUP)
528 && sxp->st.st_gid != (gid_t)F_GROUP(file);
529#ifndef CAN_CHOWN_SYMLINK
530 if (S_ISLNK(sxp->st.st_mode)) {
531 ;
532 } else
533#endif
534 if (change_uid || change_gid) {
535 if (DEBUG_GTE(OWN, 1)) {
536 if (change_uid) {
537 rprintf(FINFO,
538 "set uid of %s from %u to %u\n",
539 fname, (unsigned)sxp->st.st_uid, F_OWNER(file));
540 }
541 if (change_gid) {
542 rprintf(FINFO,
543 "set gid of %s from %u to %u\n",
544 fname, (unsigned)sxp->st.st_gid, F_GROUP(file));
545 }
546 }

Callers 6

copy_valid_pathFunction · 0.85
make_backupFunction · 0.85
finish_transferFunction · 0.85
try_dests_regFunction · 0.85
recv_generatorFunction · 0.85
recv_filesFunction · 0.85

Calls 15

link_statFunction · 0.85
full_fnameFunction · 0.85
init_stat_xFunction · 0.85
tweak_modeFunction · 0.85
get_aclFunction · 0.85
do_lchown_atFunction · 0.85
set_stat_xattrFunction · 0.85
set_xattrFunction · 0.85
same_mtimeFunction · 0.85
same_timeFunction · 0.85
get_create_timeFunction · 0.85
do_setattrlist_crtimeFunction · 0.85

Tested by

no test coverage detected