ENH: Re-implemented cmGeneratedFileStream to look like a real stream and replace the destination file atomically. This will avoid problems with the process being terminated while generating a file.

This commit is contained in:
Brad King
2004-11-03 07:23:18 -05:00
parent 3050e231b3
commit d46d8df0ed
10 changed files with 209 additions and 148 deletions

View File

@@ -120,12 +120,9 @@ void cmLocalKdevelopGenerator::MergeProjectFiles(const std::string& outputDir,
}
oldProjectFile.close();
cmGeneratedFileStream tempFile(filename.c_str());
tempFile.SetAlwaysCopy(true);
std::ostream& fout = tempFile.GetStream();
cmGeneratedFileStream fout(filename.c_str(), false);
if(!fout)
{
cmSystemTools::Error("Error can not open for write: ", filename.c_str());
return;
}
@@ -174,13 +171,9 @@ void cmLocalKdevelopGenerator::CreateNewProjectFile(const std::string& outputDir
const std::string& cmakeFilePattern)
{
cmGeneratedFileStream tempFile(filename.c_str());
tempFile.SetAlwaysCopy(true);
std::ostream& fout = tempFile.GetStream();
cmGeneratedFileStream fout(filename.c_str(), false);
if(!fout)
{
cmSystemTools::Error("Error can not open for write: ", filename.c_str());
return;
}
@@ -371,12 +364,9 @@ bool cmLocalKdevelopGenerator::CreateFilelistFile(const std::string& outputDir,
}
//now write the new filename
cmGeneratedFileStream tempFile(filename.c_str());
tempFile.SetAlwaysCopy(true);
std::ostream& fout = tempFile.GetStream();
cmGeneratedFileStream fout(filename.c_str(), false);
if(!fout)
{
cmSystemTools::Error("Error can not open for write: ", filename.c_str());
return false;
}