diff options
author | Brad King <brad.king@kitware.com> | 2023-03-07 15:40:19 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-03-07 16:36:25 (GMT) |
commit | a5d6548587f1cf3c57f639fa5671bb6c4e130211 (patch) | |
tree | e467397120494b55b5f2d444c2430feee27dd763 | |
parent | ab7085db359da111a68dcddcbb1e7dbaa84d0173 (diff) | |
download | CMake-a5d6548587f1cf3c57f639fa5671bb6c4e130211.zip CMake-a5d6548587f1cf3c57f639fa5671bb6c4e130211.tar.gz CMake-a5d6548587f1cf3c57f639fa5671bb6c4e130211.tar.bz2 |
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
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 6 |
1 files changed, 6 insertions, 0 deletions
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, |