mirror of
https://github.com/reactos/CMake.git
synced 2025-02-25 22:45:40 +00:00
Change ComputeFileMD5 to ComputeFileHash
* Use a parameter to select hash algorithm * Return a std::string as result or an empty string if it fails * Avoids unnecessary copy of hash value
This commit is contained in:
parent
501a4feea8
commit
c4647d8432
@ -6,6 +6,7 @@
|
||||
#include "cmCPackComponentGroup.h"
|
||||
#include "cmCPackGenerator.h"
|
||||
#include "cmCPackLog.h"
|
||||
#include "cmCryptoHash.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cm_sys_stat.h"
|
||||
@ -527,15 +528,13 @@ int cmCPackDebGenerator::createDeb()
|
||||
continue;
|
||||
}
|
||||
|
||||
char md5sum[33];
|
||||
if (!cmSystemTools::ComputeFileMD5(*fileIt, md5sum)) {
|
||||
std::string output =
|
||||
cmSystemTools::ComputeFileHash(*fileIt, cmCryptoHash::AlgoMD5);
|
||||
if (output.empty()) {
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem computing the md5 of "
|
||||
<< *fileIt << std::endl);
|
||||
}
|
||||
|
||||
md5sum[32] = 0;
|
||||
|
||||
std::string output(md5sum);
|
||||
output += " " + *fileIt + "\n";
|
||||
// debian md5sums entries are like this:
|
||||
// 014f3604694729f3bf19263bac599765 usr/bin/ccmake
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "cmCTest.h"
|
||||
#include "cmCTestCurl.h"
|
||||
#include "cmCTestScriptHandler.h"
|
||||
#include "cmCryptoHash.h"
|
||||
#include "cmCurl.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmProcessOutput.h"
|
||||
@ -428,10 +429,8 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
|
||||
if (cmSystemTools::IsOn(this->GetOption("InternalTest"))) {
|
||||
upload_as += "bad_md5sum";
|
||||
} else {
|
||||
char md5[33];
|
||||
cmSystemTools::ComputeFileMD5(local_file, md5);
|
||||
md5[32] = 0;
|
||||
upload_as += md5;
|
||||
upload_as +=
|
||||
cmSystemTools::ComputeFileHash(local_file, cmCryptoHash::AlgoMD5);
|
||||
}
|
||||
|
||||
if (!cmSystemTools::FileExists(local_file.c_str())) {
|
||||
@ -1058,9 +1057,8 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
|
||||
}
|
||||
}
|
||||
|
||||
char md5sum[33];
|
||||
md5sum[32] = 0;
|
||||
cmSystemTools::ComputeFileMD5(file, md5sum);
|
||||
std::string md5sum =
|
||||
cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5);
|
||||
// 1. request the buildid and check to see if the file
|
||||
// has already been uploaded
|
||||
// TODO I added support for subproject. You would need to add
|
||||
|
@ -934,19 +934,17 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
|
||||
std::string cmSystemTools::ComputeFileHash(const std::string& source,
|
||||
cmCryptoHash::Algo algo)
|
||||
{
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
cmCryptoHash md5(cmCryptoHash::AlgoMD5);
|
||||
std::string const str = md5.HashFile(source);
|
||||
strncpy(md5out, str.c_str(), 32);
|
||||
return !str.empty();
|
||||
cmCryptoHash hash(algo);
|
||||
return hash.HashFile(source);
|
||||
#else
|
||||
(void)source;
|
||||
(void)md5out;
|
||||
cmSystemTools::Message("md5sum not supported in bootstrapping mode",
|
||||
cmSystemTools::Message("hashsum not supported in bootstrapping mode",
|
||||
"Error");
|
||||
return false;
|
||||
return std::string();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "cmConfigure.h"
|
||||
|
||||
#include "cmCryptoHash.h"
|
||||
#include "cmProcessOutput.h"
|
||||
#include "cmsys/Process.h"
|
||||
#include "cmsys/SystemTools.hxx" // IWYU pragma: export
|
||||
@ -179,8 +180,9 @@ public:
|
||||
if possible). */
|
||||
static bool RenameFile(const char* oldname, const char* newname);
|
||||
|
||||
///! Compute the md5sum of a file
|
||||
static bool ComputeFileMD5(const std::string& source, char* md5out);
|
||||
///! Compute the hash of a file
|
||||
static std::string ComputeFileHash(const std::string& source,
|
||||
cmCryptoHash::Algo algo);
|
||||
|
||||
/** Compute the md5sum of a string. */
|
||||
static std::string ComputeStringMD5(const std::string& input);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "cmcmd.h"
|
||||
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmCryptoHash.h"
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmLocalGenerator.h"
|
||||
#include "cmMakefile.h"
|
||||
@ -641,7 +642,6 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
||||
|
||||
// Command to calculate the md5sum of a file
|
||||
if (args[1] == "md5sum" && args.size() >= 3) {
|
||||
char md5out[32];
|
||||
int retval = 0;
|
||||
for (std::string::size_type cc = 2; cc < args.size(); cc++) {
|
||||
const char* filename = args[cc].c_str();
|
||||
@ -649,13 +649,17 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
||||
if (cmSystemTools::FileIsDirectory(filename)) {
|
||||
std::cerr << "Error: " << filename << " is a directory" << std::endl;
|
||||
retval++;
|
||||
} else if (!cmSystemTools::ComputeFileMD5(filename, md5out)) {
|
||||
// To mimic md5sum behavior in a shell:
|
||||
std::cerr << filename << ": No such file or directory" << std::endl;
|
||||
retval++;
|
||||
} else {
|
||||
std::cout << std::string(md5out, 32) << " " << filename
|
||||
<< std::endl;
|
||||
std::string value =
|
||||
cmSystemTools::ComputeFileHash(filename, cmCryptoHash::AlgoMD5);
|
||||
if (value.empty()) {
|
||||
// To mimic "md5sum" behavior in a shell:
|
||||
std::cerr << filename << ": No such file or directory"
|
||||
<< std::endl;
|
||||
retval++;
|
||||
} else {
|
||||
std::cout << value << " " << filename << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
|
Loading…
x
Reference in New Issue
Block a user