mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-01 11:22:21 -06:00
cmSystemTools::RenameFile: Accepts std::string args
This commit is contained in:
@@ -200,7 +200,7 @@ bool cmCPackIFWRepository::PatchUpdatesXml()
|
||||
|
||||
fout.Close();
|
||||
|
||||
return cmSystemTools::RenameFile(updatesPatchXml.data(), updatesXml.data());
|
||||
return cmSystemTools::RenameFile(updatesPatchXml, updatesXml);
|
||||
}
|
||||
|
||||
void cmCPackIFWRepository::WriteRepositoryConfig(cmXMLWriter& xout)
|
||||
|
||||
@@ -538,7 +538,7 @@ void cmCTestMultiProcessHandler::UpdateCostData()
|
||||
fout << f << "\n";
|
||||
}
|
||||
fout.close();
|
||||
cmSystemTools::RenameFile(tmpout.c_str(), fname.c_str());
|
||||
cmSystemTools::RenameFile(tmpout, fname);
|
||||
}
|
||||
|
||||
void cmCTestMultiProcessHandler::ReadCostData()
|
||||
|
||||
@@ -169,7 +169,7 @@ std::string cmFileAPI::WriteJsonFile(
|
||||
// If the final name already exists then assume it has proper content.
|
||||
// Otherwise, atomically place the reply file at its final name
|
||||
if (cmSystemTools::FileExists(file, true) ||
|
||||
!cmSystemTools::RenameFile(tmpFile.c_str(), file.c_str())) {
|
||||
!cmSystemTools::RenameFile(tmpFile, file)) {
|
||||
cmSystemTools::RemoveFile(tmpFile);
|
||||
}
|
||||
|
||||
|
||||
@@ -2461,7 +2461,7 @@ bool cmFileCommand::HandleRename(std::vector<std::string> const& args)
|
||||
newname += "/" + args[2];
|
||||
}
|
||||
|
||||
if (!cmSystemTools::RenameFile(oldname.c_str(), newname.c_str())) {
|
||||
if (!cmSystemTools::RenameFile(oldname, newname)) {
|
||||
std::string err = cmSystemTools::GetLastSystemError();
|
||||
std::ostringstream e;
|
||||
/* clang-format off */
|
||||
|
||||
@@ -210,7 +210,7 @@ int cmGeneratedFileStreamBase::CompressFile(std::string const&,
|
||||
int cmGeneratedFileStreamBase::RenameFile(std::string const& oldname,
|
||||
std::string const& newname)
|
||||
{
|
||||
return cmSystemTools::RenameFile(oldname.c_str(), newname.c_str());
|
||||
return cmSystemTools::RenameFile(oldname, newname);
|
||||
}
|
||||
|
||||
void cmGeneratedFileStream::SetName(const std::string& fname)
|
||||
|
||||
@@ -1028,7 +1028,8 @@ void cmSystemTools::InitializeLibUV()
|
||||
#endif
|
||||
}
|
||||
|
||||
bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
|
||||
bool cmSystemTools::RenameFile(const std::string& oldname,
|
||||
const std::string& newname)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
# ifndef INVALID_FILE_ATTRIBUTES
|
||||
@@ -1066,7 +1067,7 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
|
||||
return retry.Count > 0;
|
||||
#else
|
||||
/* On UNIX we have an OS-provided call to do this atomically. */
|
||||
return rename(oldname, newname) == 0;
|
||||
return rename(oldname.c_str(), newname.c_str()) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +179,8 @@ public:
|
||||
|
||||
/** Rename a file or directory within a single disk volume (atomic
|
||||
if possible). */
|
||||
static bool RenameFile(const char* oldname, const char* newname);
|
||||
static bool RenameFile(const std::string& oldname,
|
||||
const std::string& newname);
|
||||
|
||||
///! Compute the hash of a file
|
||||
static std::string ComputeFileHash(const std::string& source,
|
||||
|
||||
@@ -115,8 +115,10 @@ typedef std::unordered_map<std::string, Json::Value> JsonValueMapType;
|
||||
|
||||
} // namespace
|
||||
|
||||
static bool cmakeCheckStampFile(const char* stampName, bool verbose = true);
|
||||
static bool cmakeCheckStampList(const char* stampList, bool verbose = true);
|
||||
static bool cmakeCheckStampFile(const std::string& stampName,
|
||||
bool verbose = true);
|
||||
static bool cmakeCheckStampList(const std::string& stampList,
|
||||
bool verbose = true);
|
||||
|
||||
void cmWarnUnusedCliWarning(const std::string& variable, int /*unused*/,
|
||||
void* ctx, const char* /*unused*/,
|
||||
@@ -1626,13 +1628,13 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
|
||||
|
||||
// If we are given a stamp list file check if it is really out of date.
|
||||
if (!this->CheckStampList.empty() &&
|
||||
cmakeCheckStampList(this->CheckStampList.c_str())) {
|
||||
cmakeCheckStampList(this->CheckStampList)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If we are given a stamp file check if it is really out of date.
|
||||
if (!this->CheckStampFile.empty() &&
|
||||
cmakeCheckStampFile(this->CheckStampFile.c_str())) {
|
||||
cmakeCheckStampFile(this->CheckStampFile)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2413,7 +2415,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool cmakeCheckStampFile(const char* stampName, bool verbose)
|
||||
static bool cmakeCheckStampFile(const std::string& stampName, bool verbose)
|
||||
{
|
||||
// The stamp file does not exist. Use the stamp dependencies to
|
||||
// determine whether it is really out of date. This works in
|
||||
@@ -2458,12 +2460,11 @@ static bool cmakeCheckStampFile(const char* stampName, bool verbose)
|
||||
// by the VS IDE due to a "rebuild" request. Restore it atomically.
|
||||
std::ostringstream stampTempStream;
|
||||
stampTempStream << stampName << ".tmp" << cmSystemTools::RandomSeed();
|
||||
std::string stampTempString = stampTempStream.str();
|
||||
const char* stampTemp = stampTempString.c_str();
|
||||
std::string stampTemp = stampTempStream.str();
|
||||
{
|
||||
// TODO: Teach cmGeneratedFileStream to use a random temp file (with
|
||||
// multiple tries in unlikely case of conflict) and use that here.
|
||||
cmsys::ofstream stamp(stampTemp);
|
||||
cmsys::ofstream stamp(stampTemp.c_str());
|
||||
stamp << "# CMake generation timestamp file for this directory.\n";
|
||||
}
|
||||
if (cmSystemTools::RenameFile(stampTemp, stampName)) {
|
||||
@@ -2477,11 +2478,11 @@ static bool cmakeCheckStampFile(const char* stampName, bool verbose)
|
||||
return true;
|
||||
}
|
||||
cmSystemTools::RemoveFile(stampTemp);
|
||||
cmSystemTools::Error("Cannot restore timestamp ", stampName);
|
||||
cmSystemTools::Error("Cannot restore timestamp ", stampName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool cmakeCheckStampList(const char* stampList, bool verbose)
|
||||
static bool cmakeCheckStampList(const std::string& stampList, bool verbose)
|
||||
{
|
||||
// If the stamp list does not exist CMake must rerun to generate it.
|
||||
if (!cmSystemTools::FileExists(stampList)) {
|
||||
@@ -2489,7 +2490,7 @@ static bool cmakeCheckStampList(const char* stampList, bool verbose)
|
||||
<< "is missing.\n";
|
||||
return false;
|
||||
}
|
||||
cmsys::ifstream fin(stampList);
|
||||
cmsys::ifstream fin(stampList.c_str());
|
||||
if (!fin) {
|
||||
std::cout << "CMake is re-running because generate.stamp.list "
|
||||
<< "could not be read.\n";
|
||||
@@ -2499,7 +2500,7 @@ static bool cmakeCheckStampList(const char* stampList, bool verbose)
|
||||
// Check each stamp.
|
||||
std::string stampName;
|
||||
while (cmSystemTools::GetLineFromStream(fin, stampName)) {
|
||||
if (!cmakeCheckStampFile(stampName.c_str(), verbose)) {
|
||||
if (!cmakeCheckStampFile(stampName, verbose)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2620,7 +2621,7 @@ int cmake::Build(int jobs, const std::string& dir, const std::string& target,
|
||||
}
|
||||
}
|
||||
|
||||
if (!cmakeCheckStampList(stampList.c_str(), false)) {
|
||||
if (!cmakeCheckStampList(stampList, false)) {
|
||||
// Correctly initialize the home (=source) and home output (=binary)
|
||||
// directories, which is required for running the generation step.
|
||||
std::string homeOrig = this->GetHomeDirectory();
|
||||
|
||||
@@ -530,7 +530,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
||||
|
||||
// Rename a file or directory
|
||||
if (args[1] == "rename" && args.size() == 4) {
|
||||
if (!cmSystemTools::RenameFile(args[2].c_str(), args[3].c_str())) {
|
||||
if (!cmSystemTools::RenameFile(args[2], args[3])) {
|
||||
std::string e = cmSystemTools::GetLastSystemError();
|
||||
std::cerr << "Error renaming from \"" << args[2] << "\" to \""
|
||||
<< args[3] << "\": " << e << "\n";
|
||||
|
||||
Reference in New Issue
Block a user