summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmGeneratorTarget.cxx6
-rw-r--r--Source/cmLocalGenerator.cxx3
-rw-r--r--Source/cmSystemTools.cxx12
-rw-r--r--Source/cmSystemTools.h4
-rw-r--r--Source/cmUseMangledMesaCommand.cxx3
5 files changed, 20 insertions, 8 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index fc7589e..e4659b7 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -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;
}
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 5d831c9..8bb3bc1 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -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);
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index b7287d9..074faa5 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -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)
{
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 863db3f..8ca4939 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -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);
diff --git a/Source/cmUseMangledMesaCommand.cxx b/Source/cmUseMangledMesaCommand.cxx
index cfc00e8..1fd386b 100644
--- a/Source/cmUseMangledMesaCommand.cxx
+++ b/Source/cmUseMangledMesaCommand.cxx
@@ -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);
}
}