diff options
author | Yves Frederix <Yves.Frederix@dentsplysirona.com> | 2018-04-20 13:37:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-04-23 15:37:36 (GMT) |
commit | 6dcd1bfa39684c952730904a43e268f42bf98301 (patch) | |
tree | cc80952961f932d6810a03af0527a593bc37bd0d /Source | |
parent | fe0082875aeecead23b2351629abca4990dfba43 (diff) | |
download | CMake-6dcd1bfa39684c952730904a43e268f42bf98301.zip CMake-6dcd1bfa39684c952730904a43e268f42bf98301.tar.gz CMake-6dcd1bfa39684c952730904a43e268f42bf98301.tar.bz2 |
file(INSTALL): Preserve file time when writing NTFS alternate stream
When cross-compiling on a Windows host, we use a `:cmake_mode_t` NTFS
alternate stream to store the file mode for use during packaging.
Writing to this stream changes the file modification time, so save and
restore the original modification time since we are not modifying the
real file content.
Fixes: #17922
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFileCommand.cxx | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 0d31070..6c1a869 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -1129,14 +1129,26 @@ protected: if (permissions) { #ifdef WIN32 if (Makefile->IsOn("CMAKE_CROSSCOMPILING")) { + // Store the mode in an NTFS alternate stream. std::string mode_t_adt_filename = std::string(toFile) + ":cmake_mode_t"; + // Writing to an NTFS alternate stream changes the modification + // time, so we need to save and restore its original value. + cmSystemToolsFileTime* file_time_orig = cmSystemTools::FileTimeNew(); + cmSystemTools::FileTimeGet(toFile, file_time_orig); + cmsys::ofstream permissionStream(mode_t_adt_filename.c_str()); if (permissionStream) { permissionStream << std::oct << permissions << std::endl; } + + permissionStream.close(); + + cmSystemTools::FileTimeSet(toFile, file_time_orig); + + cmSystemTools::FileTimeDelete(file_time_orig); } #endif |