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.
This commit is contained in:
parent
e8f1d7f031
commit
9eb8e4b22b
@ -13,6 +13,7 @@
|
|||||||
#include "cmCacheManager.h"
|
#include "cmCacheManager.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmCacheManager.h"
|
#include "cmCacheManager.h"
|
||||||
|
#include "cmGeneratedFileStream.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmake.h"
|
#include "cmake.h"
|
||||||
#include "cmVersion.h"
|
#include "cmVersion.h"
|
||||||
@ -431,9 +432,8 @@ bool cmCacheManager::SaveCache(const char* path)
|
|||||||
{
|
{
|
||||||
std::string cacheFile = path;
|
std::string cacheFile = path;
|
||||||
cacheFile += "/CMakeCache.txt";
|
cacheFile += "/CMakeCache.txt";
|
||||||
std::string tempFile = cacheFile;
|
cmGeneratedFileStream fout(cacheFile.c_str());
|
||||||
tempFile += ".tmp";
|
fout.SetCopyIfDifferent(true);
|
||||||
std::ofstream fout(tempFile.c_str());
|
|
||||||
if(!fout)
|
if(!fout)
|
||||||
{
|
{
|
||||||
cmSystemTools::Error("Unable to open cache file for save. ",
|
cmSystemTools::Error("Unable to open cache file for save. ",
|
||||||
@ -561,10 +561,7 @@ bool cmCacheManager::SaveCache(const char* path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fout << "\n";
|
fout << "\n";
|
||||||
fout.close();
|
fout.Close();
|
||||||
cmSystemTools::CopyFileIfDifferent(tempFile.c_str(),
|
|
||||||
cacheFile.c_str());
|
|
||||||
cmSystemTools::RemoveFile(tempFile.c_str());
|
|
||||||
std::string checkCacheFile = path;
|
std::string checkCacheFile = path;
|
||||||
checkCacheFile += cmake::GetCMakeFilesDirectory();
|
checkCacheFile += cmake::GetCMakeFilesDirectory();
|
||||||
cmSystemTools::MakeDirectory(checkCacheFile.c_str());
|
cmSystemTools::MakeDirectory(checkCacheFile.c_str());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user