diff options
author | André Klitzing <aklitzing@gmail.com> | 2017-07-08 16:42:02 (GMT) |
---|---|---|
committer | André Klitzing <aklitzing@gmail.com> | 2017-07-14 06:57:17 (GMT) |
commit | c4647d84321f4a7b52301237394087065f5df33c (patch) | |
tree | 7fb689a0052667a611020e9d9169afa2160b1ba5 /Source/cmcmd.cxx | |
parent | 501a4feea8d0d007ce292defec1c97d6eb702409 (diff) | |
download | CMake-c4647d84321f4a7b52301237394087065f5df33c.zip CMake-c4647d84321f4a7b52301237394087065f5df33c.tar.gz CMake-c4647d84321f4a7b52301237394087065f5df33c.tar.bz2 |
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
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r-- | Source/cmcmd.cxx | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index d5b0861..70ebd83 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -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; |