summaryrefslogtreecommitdiffstats
path: root/Source/cmCacheManager.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-03-14 12:16:05 (GMT)
committerBrad King <brad.king@kitware.com>2012-03-14 12:18:15 (GMT)
commit9eb8e4b22bf56dca81bf2f0507977d4c1fda535e (patch)
tree315e06245586be8bf48bae51bbf9f0b77a54392e /Source/cmCacheManager.cxx
parente8f1d7f031e7300097d347e26251730422c85dc8 (diff)
downloadCMake-9eb8e4b22bf56dca81bf2f0507977d4c1fda535e.zip
CMake-9eb8e4b22bf56dca81bf2f0507977d4c1fda535e.tar.gz
CMake-9eb8e4b22bf56dca81bf2f0507977d4c1fda535e.tar.bz2
Write CMakeCache.txt atomically (#13040)
The write code introduced by commit 0b0d1b1d (add CMakeCache.txt support, 2001-02-22) uses a temporary file but does not replace the original atomically. Use cmGeneratedFileStream to do both copy-if-different and atomic replacement.
Diffstat (limited to 'Source/cmCacheManager.cxx')
-rw-r--r--Source/cmCacheManager.cxx11
1 files changed, 4 insertions, 7 deletions
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index ab0bb79..47a0e85 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -13,6 +13,7 @@
#include "cmCacheManager.h"
#include "cmSystemTools.h"
#include "cmCacheManager.h"
+#include "cmGeneratedFileStream.h"
#include "cmMakefile.h"
#include "cmake.h"
#include "cmVersion.h"
@@ -431,9 +432,8 @@ bool cmCacheManager::SaveCache(const char* path)
{
std::string cacheFile = path;
cacheFile += "/CMakeCache.txt";
- std::string tempFile = cacheFile;
- tempFile += ".tmp";
- std::ofstream fout(tempFile.c_str());
+ cmGeneratedFileStream fout(cacheFile.c_str());
+ fout.SetCopyIfDifferent(true);
if(!fout)
{
cmSystemTools::Error("Unable to open cache file for save. ",
@@ -561,10 +561,7 @@ bool cmCacheManager::SaveCache(const char* path)
}
}
fout << "\n";
- fout.close();
- cmSystemTools::CopyFileIfDifferent(tempFile.c_str(),
- cacheFile.c_str());
- cmSystemTools::RemoveFile(tempFile.c_str());
+ fout.Close();
std::string checkCacheFile = path;
checkCacheFile += cmake::GetCMakeFilesDirectory();
cmSystemTools::MakeDirectory(checkCacheFile.c_str());