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
This commit is contained in:
Brad King
2023-03-07 10:40:19 -05:00
parent 5f4dad37f0
commit 35f2b1bf5b

View File

@@ -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,