From a5d6548587f1cf3c57f639fa5671bb6c4e130211 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 7 Mar 2023 10:40:19 -0500 Subject: file(INSTALL): Fix file ownership regression when running as root on macOS Backport KWSys commit `51272e80e` (SystemTools: Avoid macOS copyfile semantic differences as root, 2023-03-07). Fixes: #24577 --- Source/kwsys/SystemTools.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 5889a4b..6173f23 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -2483,6 +2483,12 @@ Status SystemTools::CloneFileContent(std::string const& source, return status; #elif defined(__APPLE__) && \ defined(KWSYS_SYSTEMTOOLS_HAVE_MACOS_COPYFILE_CLONE) + // When running as root, copyfile() copies more metadata than we + // want, such as ownership. Pretend it is not available. + if (getuid() == 0) { + return Status::POSIX(ENOSYS); + } + // NOTE: we cannot use `clonefile` as the {a,c,m}time for the file needs to // be updated by `copy_file_if_different` and `copy_file`. if (copyfile(source.c_str(), destination.c_str(), nullptr, -- cgit v0.12 From 35f2b1bf5b5593020d4ba0dfdc1cb265c2a3c095 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 7 Mar 2023 10:40:19 -0500 Subject: file(INSTALL): Fix file ownership regression when running as root on macOS Backport KWSys commit `51272e80e` (SystemTools: Avoid macOS copyfile semantic differences as root, 2023-03-07). Fixes: #24577 --- Source/kwsys/SystemTools.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index a3ab51a..573cc6a 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -2528,6 +2528,12 @@ SystemTools::CopyStatus SystemTools::CloneFileContent( return status; #elif defined(__APPLE__) && \ defined(KWSYS_SYSTEMTOOLS_HAVE_MACOS_COPYFILE_CLONE) + // When running as root, copyfile() copies more metadata than we + // want, such as ownership. Pretend it is not available. + if (getuid() == 0) { + return CopyStatus{ Status::POSIX(ENOSYS), CopyStatus::NoPath }; + } + // NOTE: we cannot use `clonefile` as the {a,c,m}time for the file needs to // be updated by `copy_file_if_different` and `copy_file`. if (copyfile(source.c_str(), destination.c_str(), nullptr, -- cgit v0.12 From a87ea777d459462471cfb5a6659e8cb250fb971c Mon Sep 17 00:00:00 2001 From: KWSys Upstream Date: Wed, 8 Mar 2023 07:36:23 -0500 Subject: KWSys 2023-03-08 (a3ff01ab) Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit a3ff01ab80c7bb1e08caceb107f323513efbad47 (master). Upstream Shortlog ----------------- Brad King (1): 51272e80 SystemTools: Avoid macOS copyfile semantic differences as root --- SystemTools.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SystemTools.cxx b/SystemTools.cxx index 6cdd5a3..3bb7869 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -2528,6 +2528,12 @@ SystemTools::CopyStatus SystemTools::CloneFileContent( return status; #elif defined(__APPLE__) && \ defined(KWSYS_SYSTEMTOOLS_HAVE_MACOS_COPYFILE_CLONE) + // When running as root, copyfile() copies more metadata than we + // want, such as ownership. Pretend it is not available. + if (getuid() == 0) { + return CopyStatus{ Status::POSIX(ENOSYS), CopyStatus::NoPath }; + } + // NOTE: we cannot use `clonefile` as the {a,c,m}time for the file needs to // be updated by `copy_file_if_different` and `copy_file`. if (copyfile(source.c_str(), destination.c_str(), nullptr, -- cgit v0.12