Blame SOURCES/rsync-3.2.3-xattr.patch

c13468
diff --git a/xattrs.c b/xattrs.c
c13468
index 508649c0..3c549192 100644
c13468
--- a/xattrs.c
c13468
+++ b/xattrs.c
c13468
@@ -1055,7 +1055,7 @@ int set_xattr(const char *fname, const struct file_struct *file, const char *fna
c13468
 {
c13468
 	rsync_xa_list *glst = rsync_xal_l.items;
c13468
 	item_list *lst;
c13468
-	int ndx;
c13468
+	int ndx, added_write_perm = 0;
c13468
 
c13468
 	if (dry_run)
c13468
 		return 1; /* FIXME: --dry-run needs to compute this value */
c13468
@@ -1084,10 +1084,23 @@ int set_xattr(const char *fname, const struct file_struct *file, const char *fna
c13468
 	}
c13468
 #endif
c13468
 
c13468
+	/* If the target file lacks write permission, we try to add it
c13468
+	 * temporarily so we can change the extended attributes. */
c13468
+	if (!am_root
c13468
+#ifdef SUPPORT_LINKS
c13468
+	 && !S_ISLNK(sxp->st.st_mode)
c13468
+#endif
c13468
+	 && access(fname, W_OK) < 0
c13468
+	 && do_chmod(fname, (sxp->st.st_mode & CHMOD_BITS) | S_IWUSR) == 0)
c13468
+		added_write_perm = 1;
c13468
+
c13468
 	ndx = F_XATTR(file);
c13468
 	glst += ndx;
c13468
 	lst = &glst->xa_items;
c13468
-	return rsync_xal_set(fname, lst, fnamecmp, sxp);
c13468
+	int return_value = rsync_xal_set(fname, lst, fnamecmp, sxp);
c13468
+	if (added_write_perm) /* remove the temporary write permission */
c13468
+		do_chmod(fname, sxp->st.st_mode);
c13468
+	return return_value;
c13468
 }
c13468
 
c13468
 #ifdef SUPPORT_ACLS