Bug 5565 - xattrs not set on locked files that already exist on target
Summary: xattrs not set on locked files that already exist on target
Status: ASSIGNED
Alias: None
Product: rsync
Classification: Unclassified
Component: core (show other bugs)
Version: 3.0.3
Hardware: Other Mac OS X
: P3 normal (vote)
Target Milestone: ---
Assignee: Wayne Davison
QA Contact: Rsync QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-25 00:27 UTC by Mike Bombich
Modified: 2014-08-11 15:45 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Bombich 2008-06-25 00:27:06 UTC
It appears that rsync isn't unlocking files before setting the file attributes when those files already exist.  This generates error messages on subsequent backups such as:

rsync: rsync_xal_set: lsetxattr("locked_file","test_xattr") failed: Operation not permitted (1)
rsync: rsync_xal_clear: lremovexattr("locked_file","test_xattr.temp") failed: Operation not permitted (1)

I assume this would also affect ACLs.  Presumably, this is what --force-change is supposed to do, so I extended that functionality to apply to this test case.

Here's the test case (tested on 3.0.3pre3+fileflags+crtime):

######
#!/bin/sh

xattr=/usr/local/bin/xattr
rsync="/Users/bombich/Desktop/rsync-HEAD-20080412-0558GMT/rsync"

src=`mktemp -d /tmp/src.XXXXXX`
tgt=`mktemp -d /tmp/tgt.XXXXXX`
touch $src/locked_file

$xattr -s test_xattr "Test attribute" $src/locked_file
$xattr -s test_xattr.temp "Temp attribute" $src/locked_file
chflags uchg $src/locked_file


## First backup
printf "### Initial backup ###\n\n"
"$rsync" -vaX --fileflags --force-change $src/ $tgt/

## Change the source file
chflags nouchg $src/locked_file
$xattr -s test_xattr "Modified attribute" $src/locked_file
$xattr -d test_xattr.temp $src/locked_file
chflags uchg $src/locked_file


## Second backup
printf "\n### Second backup ###\n\n"
"$rsync" -vaX --fileflags --force-change $src/ $tgt/

# Cleanup
chflags -R nouchg $src
chflags -R nouchg $tgt
rm -rf $src $tgt

######




Example output:

[bombich:~] ~/Desktop/locked_xattrs.sh
### Initial backup ###

sending incremental file list
locked_file

sent 173 bytes  received 32 bytes  410.00 bytes/sec
total size is 0  speedup is 0.00

### Second backup ###

sending incremental file list
rsync: rsync_xal_set: lsetxattr("locked_file","test_xattr") failed: Operation not permitted (1)
rsync: rsync_xal_clear: lremovexattr("locked_file","test_xattr.temp") failed: Operation not permitted (1)

sent 104 bytes  received 16 bytes  240.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files could not be transferred (code 23) at main.c(1031) [sender=3.0.3dev]




PATCH:

diff -Naur rsync-3.0.3pre3_base/rsync.c rsync-3.0.3pre3_patched/rsync.c
--- rsync-3.0.3pre3_base/rsync.c	2008-06-23 22:31:58.000000000 -0700
+++ rsync-3.0.3pre3_patched/rsync.c	2008-06-23 22:59:03.000000000 -0700
@@ -31,6 +31,7 @@
 extern int dry_run;
 extern int preserve_acls;
 extern int preserve_xattrs;
+extern int force_change;
 extern int preserve_perms;
 extern int preserve_fileflags;
 extern int preserve_executability;
@@ -445,6 +446,11 @@
 	if (daemon_chmod_modes && !S_ISLNK(new_mode))
 		new_mode = tweak_mode(new_mode, daemon_chmod_modes);
 
+#ifdef SUPPORT_FORCE_CHANGE
+	if (force_change)
+		make_mutable(fname, sxp->st.st_mode, sxp->st.st_flags, force_change);
+#endif
+
 #ifdef SUPPORT_ACLS
 	if (preserve_acls && !S_ISLNK(file->mode) && !ACL_READY(*sxp))
 		get_acl(fname, sxp);


## Note: I'm not using undo_make_mutable because set_fileflags is called at the end of this method if we care about fileflags.
Comment 1 Wayne Davison 2008-06-29 22:51:39 UTC
Yeah, this is a known issue with immutable files.  I'll be considering your patch for inclusion in an upcoming version.  Thanks!
Comment 2 Ruben Kerkhof 2014-08-11 15:45:31 UTC
Just a friendly reminder to please apply this patch. This is still an issue with 3.1.1 on OSX.