From 9470879845ae622bda07ff55d158ef212ac1fd83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
Date: Fri, 10 Feb 2023 18:48:05 +0000
Subject: [PATCH] copy: on macOS try COW even if not preserving mode

* src/copy.c (copy_reg): Try fclonefileat() unless we're
explicitly not preserving mode.  Also don't key on timestamp
preservation, as with COW it's more accurate anyway to keep
the same timestamps as we're pointing to the same data.
* NEWS: Mention the change in behavior.
Addresses https://bugs.gnu.org/61386

Tested-by: Georgi Valkov <gvalkov@gmail.com>
---
 src/copy.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/copy.c b/src/copy.c
index dfbb557de..b1fa6e60a 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -1250,9 +1250,11 @@ copy_reg (char const *src_name, char const *dst_name,
 # endif
       int fc_flags = x->preserve_ownership ? 0 : CLONE_NOOWNERCOPY;
       if (data_copy_required && x->reflink_mode
-          && x->preserve_mode && x->preserve_timestamps
+          && ! x->explicit_no_preserve_mode
           && (x->preserve_ownership || CLONE_NOOWNERCOPY))
         {
+          /* Note timestamps will be preserved irrespective of
+             x->preserve_timestamps. */
           if (fclonefileat (source_desc, dst_dirfd, dst_relname, fc_flags) == 0)
             goto close_src_desc;
           else if (! handle_clone_fail (dst_dirfd, dst_relname, src_name,
-- 
2.39.1

