From 9c576a88d95b302882bcb0a021dcf03982a40902 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 22 May 2019 10:14:46 +0200 Subject: Use cmFileTimes instead of cmSystemToolsFileTime interface --- Source/CPack/cmCPackGenerator.cxx | 3 ++- Source/cmFileCommand.cxx | 19 +++++-------------- Source/cmFileCopier.cxx | 24 ++++++++++-------------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 127bcf9..7e07ff4 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -15,6 +15,7 @@ #include "cmCryptoHash.h" #include "cmDuration.h" #include "cmFSPermissions.h" +#include "cmFileTimes.h" #include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" @@ -388,7 +389,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( } /* If it is not a symlink then do a plain copy */ else if (!(cmSystemTools::CopyFileIfDifferent(inFile, filePath) && - cmSystemTools::CopyFileTime(inFile, filePath))) { + cmFileTimes::Copy(inFile, filePath))) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: " << inFile << " -> " << filePath << std::endl); diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index aa8a919..f522d36 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -25,6 +25,7 @@ #include "cmFileCopier.h" #include "cmFileInstaller.h" #include "cmFileLockPool.h" +#include "cmFileTimes.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmHexFileConverter.h" @@ -52,8 +53,6 @@ # include #endif -class cmSystemToolsFileTime; - #if defined(_WIN32) // libcurl doesn't support file:// urls for unicode filenames on Windows. // Convert string from UTF-8 to ACP if this is a file:// URL. @@ -1114,8 +1113,7 @@ bool cmFileCommand::HandleRPathChangeCommand( return false; } bool success = true; - cmSystemToolsFileTime* ft = cmSystemTools::FileTimeNew(); - bool have_ft = cmSystemTools::FileTimeGet(file, ft); + cmFileTimes const ft(file); std::string emsg; bool changed; if (!cmSystemTools::ChangeRPath(file, oldRPath, newRPath, &emsg, &changed)) { @@ -1139,11 +1137,8 @@ bool cmFileCommand::HandleRPathChangeCommand( message += "\""; this->Makefile->DisplayStatus(message, -1); } - if (have_ft) { - cmSystemTools::FileTimeSet(file, ft); - } + ft.Store(file); } - cmSystemTools::FileTimeDelete(ft); return success; } @@ -1182,8 +1177,7 @@ bool cmFileCommand::HandleRPathRemoveCommand( return false; } bool success = true; - cmSystemToolsFileTime* ft = cmSystemTools::FileTimeNew(); - bool have_ft = cmSystemTools::FileTimeGet(file, ft); + cmFileTimes const ft(file); std::string emsg; bool removed; if (!cmSystemTools::RemoveRPath(file, &emsg, &removed)) { @@ -1203,11 +1197,8 @@ bool cmFileCommand::HandleRPathRemoveCommand( message += "\""; this->Makefile->DisplayStatus(message, -1); } - if (have_ft) { - cmSystemTools::FileTimeSet(file, ft); - } + ft.Store(file); } - cmSystemTools::FileTimeDelete(ft); return success; } diff --git a/Source/cmFileCopier.cxx b/Source/cmFileCopier.cxx index 972cd6e..49e8cd5 100644 --- a/Source/cmFileCopier.cxx +++ b/Source/cmFileCopier.cxx @@ -5,6 +5,7 @@ #include "cmFSPermissions.h" #include "cmFileCommand.h" +#include "cmFileTimes.h" #include "cmMakefile.h" #include "cmSystemTools.h" #include "cmsys/Directory.hxx" @@ -75,20 +76,15 @@ bool cmFileCopier::SetPermissions(const std::string& toFile, // 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; + cmFileTimes file_time_orig(toFile); + { + cmsys::ofstream permissionStream(mode_t_adt_filename.c_str()); + if (permissionStream) { + permissionStream << std::oct << permissions << std::endl; + } + permissionStream.close(); } - - permissionStream.close(); - - cmSystemTools::FileTimeSet(toFile, file_time_orig); - - cmSystemTools::FileTimeDelete(file_time_orig); + file_time_orig.Store(toFile); } #endif @@ -614,7 +610,7 @@ bool cmFileCopier::InstallFile(const std::string& fromFile, if (cmSystemTools::GetPermissions(toFile, perm)) { cmSystemTools::SetPermissions(toFile, perm | mode_owner_write); } - if (!cmSystemTools::CopyFileTime(fromFile, toFile)) { + if (!cmFileTimes::Copy(fromFile, toFile)) { std::ostringstream e; e << this->Name << " cannot set modification time on \"" << toFile << "\""; -- cgit v0.12