diff options
author | KWSys Upstream <kwrobot@kitware.com> | 2022-06-09 18:19:13 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-06-09 18:19:27 (GMT) |
commit | 975c44654d2f992bab20f963a70f12fe6a63e1ba (patch) | |
tree | 55ab3c1e6b2d57a9ffe5bb919db1588081a4bb03 | |
parent | 6b88084658c3a751072c3e0f7d70bca3fb234bc5 (diff) | |
download | CMake-975c44654d2f992bab20f963a70f12fe6a63e1ba.zip CMake-975c44654d2f992bab20f963a70f12fe6a63e1ba.tar.gz CMake-975c44654d2f992bab20f963a70f12fe6a63e1ba.tar.bz2 |
KWSys 2022-06-09 (9b65e88d)
Code extracted from:
https://gitlab.kitware.com/utils/kwsys.git
at commit 9b65e88d077e023f5e4e22f31bd0970e4071eb5b (master).
Upstream Shortlog
-----------------
Saleem Abdulrasool (1):
0969597d SystemTools: add a clonefile optimization on macOS
-rw-r--r-- | SystemTools.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/SystemTools.cxx b/SystemTools.cxx index c38b456..5889a4b 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -94,6 +94,13 @@ # include <linux/fs.h> #endif +#if defined(__APPLE__) && \ + (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0 >= 101200) +# define KWSYS_SYSTEMTOOLS_HAVE_MACOS_COPYFILE_CLONE +# include <copyfile.h> +# include <sys/stat.h> +#endif + // Windows API. #if defined(_WIN32) # include <windows.h> @@ -2474,6 +2481,26 @@ Status SystemTools::CloneFileContent(std::string const& source, close(out); return status; +#elif defined(__APPLE__) && \ + defined(KWSYS_SYSTEMTOOLS_HAVE_MACOS_COPYFILE_CLONE) + // 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, + COPYFILE_METADATA | COPYFILE_CLONE) < 0) { + return Status::POSIX_errno(); + } +# if KWSYS_CXX_HAS_UTIMENSAT + // utimensat is only available on newer Unixes and macOS 10.13+ + if (utimensat(AT_FDCWD, destination.c_str(), nullptr, 0) < 0) { + return Status::POSIX_errno(); + } +# else + // fall back to utimes + if (utimes(destination.c_str(), nullptr) < 0) { + return Status::POSIX_errno(); + } +# endif + return Status::Success(); #else (void)source; (void)destination; |