mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-07 22:59:56 -05:00
Merge topic 'MoveIfDifferent'
5b96fd5b81use cmSystemTools::MoveFileIfDifferent()5eaf1e1be2cmSystemTools: introduce MoveFileIfDifferent() Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3794
This commit is contained in:
@@ -3417,8 +3417,7 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
|
||||
file << pchEpilogue << "\n";
|
||||
}
|
||||
}
|
||||
cmSystemTools::CopyFileIfDifferent(filename_tmp, filename);
|
||||
cmSystemTools::RemoveFile(filename_tmp);
|
||||
cmSystemTools::MoveFileIfDifferent(filename_tmp, filename);
|
||||
}
|
||||
return inserted.first->second;
|
||||
}
|
||||
@@ -3451,8 +3450,7 @@ std::string cmGeneratorTarget::GetPchSource(const std::string& config,
|
||||
cmGeneratedFileStream file(filename_tmp);
|
||||
file << "/* generated by CMake */\n";
|
||||
}
|
||||
cmSystemTools::CopyFileIfDifferent(filename_tmp, filename);
|
||||
cmSystemTools::RemoveFile(filename_tmp);
|
||||
cmSystemTools::MoveFileIfDifferent(filename_tmp, filename);
|
||||
}
|
||||
return inserted.first->second;
|
||||
}
|
||||
|
||||
@@ -2281,8 +2281,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target,
|
||||
}
|
||||
}
|
||||
}
|
||||
cmSystemTools::CopyFileIfDifferent(filename_tmp, filename);
|
||||
cmSystemTools::RemoveFile(filename_tmp);
|
||||
cmSystemTools::MoveFileIfDifferent(filename_tmp, filename);
|
||||
|
||||
target->AddSource(filename, true);
|
||||
|
||||
|
||||
@@ -855,6 +855,18 @@ bool cmSystemTools::RenameFile(const std::string& oldname,
|
||||
#endif
|
||||
}
|
||||
|
||||
void cmSystemTools::MoveFileIfDifferent(const std::string& source,
|
||||
const std::string& destination)
|
||||
{
|
||||
if (FilesDiffer(source, destination)) {
|
||||
if (RenameFile(source, destination)) {
|
||||
return;
|
||||
}
|
||||
CopyFileAlways(source, destination);
|
||||
}
|
||||
RemoveFile(source);
|
||||
}
|
||||
|
||||
std::string cmSystemTools::ComputeFileHash(const std::string& source,
|
||||
cmCryptoHash::Algo algo)
|
||||
{
|
||||
|
||||
@@ -131,6 +131,10 @@ public:
|
||||
static bool RenameFile(const std::string& oldname,
|
||||
const std::string& newname);
|
||||
|
||||
//! Rename a file if contents are different, delete the source otherwise
|
||||
static void MoveFileIfDifferent(const std::string& source,
|
||||
const std::string& destination);
|
||||
|
||||
//! Compute the hash of a file
|
||||
static std::string ComputeFileHash(const std::string& source,
|
||||
cmCryptoHash::Algo algo);
|
||||
|
||||
@@ -98,7 +98,6 @@ void CopyAndFullPathMesaHeader(const std::string& source,
|
||||
// close the files before attempting to copy
|
||||
fin.close();
|
||||
fout.close();
|
||||
cmSystemTools::CopyFileIfDifferent(tempOutputFile, outFile);
|
||||
cmSystemTools::RemoveFile(tempOutputFile);
|
||||
cmSystemTools::MoveFileIfDifferent(tempOutputFile, outFile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user