--- syscall.c.orig	2006-01-09 12:35:38.000000000 -0600
+++ syscall.c	2006-01-09 12:35:52.000000000 -0600
@@ -30,10 +30,18 @@
 #include <sys/un.h>
 #endif
 
+#ifdef HAVE_COPYFILE_H
+#include <libgen.h>
+#include <copyfile.h>
+#endif
+
 extern int dry_run;
 extern int read_only;
 extern int list_only;
 extern int preserve_perms;
+#ifdef EA_SUPPORT
+extern int extended_attributes;
+#endif
 
 #define RETURN_ERROR_IF(x,e) \
 	do { \
@@ -148,6 +156,19 @@
 {
 	if (dry_run) return 0;
 	RETURN_ERROR_IF_RO_OR_LO;
+#ifdef HAVE_COPYFILE
+	if(extended_attributes)
+	{
+	    char dst_fname[MAXPATHLEN];
+	    if(!strncmp(basename(fname1), ".._", 3))
+	    {
+		snprintf(dst_fname, MAXPATHLEN, "%s/%s", dirname(fname2), basename(fname2) + 2);
+		if(copyfile(fname1, dst_fname, 0,
+		    COPYFILE_UNPACK | COPYFILE_METADATA) == 0)
+		return unlink(fname1);
+	    }
+	}
+#endif
 	return rename(fname1, fname2);
 }
 
