From f0967282fb44e8739d48b2775ea78c613920491c Mon Sep 17 00:00:00 2001
From: Georgi Valkov <gvalkov@gmail.com>
Date: Mon, 13 Feb 2023 18:34:24 +0200
Subject: [PATCH] cp,mv,install: Disable sparse copy on macOS

Due to a bug in macOS, sparse copies are corrupted on virtual disks
formatted with APFS. HFS is not affected. Affected are coreutils
install, and gcp when compiled with SEEK_HOLE, as well as macOS Finder.

While reading the entire file returns valid data, scanning for
allocated segments may return holes where valid data is present.
In this case a sparse copy does not contain these segments and return
zeroes instead. Once the virtual disk is dismounted and then
mounted again, a sparse copy produces correct results.

This breaks OpenWRT build on macOS. Details:
https://github.com/openwrt/openwrt/pull/11960

Signed-off-by: Georgi Valkov <gvalkov@gmail.com>
---
 src/copy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/copy.c b/src/copy.c
index 8370f55bd..4dad681f9 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -1062,7 +1062,7 @@ infer_scantype (int fd, struct stat const *sb,
          && ST_NBLOCKS (*sb) < sb->st_size / ST_NBLOCKSIZE))
     return PLAIN_SCANTYPE;
 
-#ifdef SEEK_HOLE
+#if defined(SEEK_HOLE) && !defined(__APPLE__)
   off_t ext_start = lseek (fd, 0, SEEK_DATA);
   if (0 <= ext_start || errno == ENXIO)
     {
-- 
2.39.1

