Blame SOURCES/rsync-3.1.3-xattr.patch

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