Skip to content

Commit b8faa88

Browse files
authored
Merge pull request #1177 from aschnell/master
- make sha256sum match command line tool (for "normal" files)
2 parents d16a1e9 + 0d1c991 commit b8faa88

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

client/snbk/CmdMetaParse.cc

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
*/
2121

2222

23-
#include <iomanip>
24-
#include <iostream>
25-
#include <sstream>
26-
2723
#include <boost/algorithm/string.hpp>
2824
#include <openssl/sha.h>
2925

@@ -61,7 +57,8 @@ namespace snapper
6157
SN_THROW(Exception(_("Failed to load info.xml.")));
6258
}
6359

64-
content = boost::join(cmd.get_stdout(), "\n");
60+
if (!cmd.get_stdout().empty())
61+
content = boost::join(cmd.get_stdout(), "\n") + "\n";
6562

6663
y2mil(*this);
6764
}
@@ -76,17 +73,14 @@ namespace snapper
7673
}
7774

7875
unsigned char hash[SHA256_DIGEST_LENGTH];
79-
SHA256(reinterpret_cast<const unsigned char*>(content.c_str()), content.length(),
80-
hash);
76+
SHA256(reinterpret_cast<const unsigned char*>(content.c_str()), content.length(), hash);
8177

82-
std::stringstream ss;
83-
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
84-
{
85-
ss << std::hex << std::setw(2) << std::setfill('0')
86-
<< static_cast<int>(hash[i]);
87-
}
78+
char buf[2 * SHA256_DIGEST_LENGTH + 1];
8879

89-
return ss.str();
80+
for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i)
81+
snprintf(&buf[2 * i], 3, "%02x", hash[i]);
82+
83+
return buf;
9084
}
9185

9286

@@ -143,6 +137,7 @@ namespace snapper
143137
std::ostream& operator<<(std::ostream& s, const CmdMetaParse& cmd_metaparse)
144138
{
145139
SnapshotMeta meta = cmd_metaparse.get_meta();
140+
146141
s << "path: " << cmd_metaparse.path
147142
<< ", checksum: " << cmd_metaparse.get_checksum()
148143
<< ", state: " << toString(meta.state) << ", date: " << meta.date

client/snbk/CmdMetaParse.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ namespace snapper
8787
private:
8888

8989
const string path;
90-
string content = "";
90+
91+
string content;
92+
9193
};
9294

9395
} // namespace snapper

0 commit comments

Comments
 (0)