link_dest checks perms despite no -p -o or -g

Kyle Jones kyle_jones at wonderworks.com
Tue Apr 8 07:54:03 EST 2003


When using --link-dest, this block of code in skip_file causes
new copies of files to be created if source and destination file
permissions differ, even if -p -o and -g haven't been specified.

	if (link_dest) {
		if((st->st_mode & ~_S_IFMT) !=  (file->mode & ~_S_IFMT)) {
			return 0;
		}
		if (st->st_uid != file->uid || st->st_gid != file->gid) {
			return 0;
		}
	}

I think the code should be this instead.

	if (link_dest) {
		if(preserve_perms &&
		   ((st->st_mode & ~_S_IFMT) !=  (file->mode & ~_S_IFMT))) {
			return 0;
		}
		if ((preserve_uid && (st->st_uid != file->uid)) ||
		    (preserve_gid && (st->st_gid != file->gid))) {
			return 0;
		}
	}

Tested lightly here, seems to do the right thing.  Without this change
you pretty much have to be root to use --link-dest.  Otherwise if you
can't sync owner/group/perms for some reason (not file owner, chgrp
fails on remote host, etc.), fresh copies will be created each rsync,
defeating the purpose of using --link-dest.


More information about the rsync mailing list