aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2011-10-06 22:29:24 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2011-10-14 23:04:28 +0100
commit38afd6f9261696766d9bd304bd2e8712b5890f2a (patch)
tree7e168f6f5c02c63d88877f7fac85e64e2744c470
parent2ff049ddef190325fac1a1933c71a5884a64478f (diff)
downloadpaludis-38afd6f9261696766d9bd304bd2e8712b5890f2a.tar.gz
paludis-38afd6f9261696766d9bd304bd2e8712b5890f2a.tar.xz
Make MemoisedHashes use DigestRegistry
-rw-r--r--paludis/repositories/e/check_fetched_files_visitor.cc8
-rw-r--r--paludis/repositories/e/e_repository.cc6
-rw-r--r--paludis/repositories/e/memoised_hashes.cc54
-rw-r--r--paludis/repositories/e/memoised_hashes.hh4
4 files changed, 14 insertions, 58 deletions
diff --git a/paludis/repositories/e/check_fetched_files_visitor.cc b/paludis/repositories/e/check_fetched_files_visitor.cc
index 94f4365..d80bd4a 100644
--- a/paludis/repositories/e/check_fetched_files_visitor.cc
+++ b/paludis/repositories/e/check_fetched_files_visitor.cc
@@ -252,7 +252,7 @@ CheckFetchedFilesVisitor::check_distfile_manifest(const FSPath & distfile)
if (! m->rmd160().empty())
{
- std::string rmd160hexsum(hashes->get<RMD160>(distfile, file_stream));
+ std::string rmd160hexsum(hashes->get("RMD160", distfile, file_stream));
if (rmd160hexsum != m->rmd160())
{
@@ -273,7 +273,7 @@ CheckFetchedFilesVisitor::check_distfile_manifest(const FSPath & distfile)
if (! m->sha1().empty())
{
- std::string sha1hexsum(hashes->get<SHA1>(distfile, file_stream));
+ std::string sha1hexsum(hashes->get("SHA1", distfile, file_stream));
if (sha1hexsum != m->sha1())
{
@@ -294,7 +294,7 @@ CheckFetchedFilesVisitor::check_distfile_manifest(const FSPath & distfile)
if (! m->sha256().empty())
{
- std::string sha256hexsum(hashes->get<SHA256>(distfile, file_stream));
+ std::string sha256hexsum(hashes->get("SHA256", distfile, file_stream));
if (sha256hexsum != m->sha256())
{
@@ -315,7 +315,7 @@ CheckFetchedFilesVisitor::check_distfile_manifest(const FSPath & distfile)
if (! m->md5().empty())
{
- std::string md5hexsum(hashes->get<MD5>(distfile, file_stream));
+ std::string md5hexsum(hashes->get("MD5", distfile, file_stream));
if (md5hexsum != m->md5())
{
diff --git a/paludis/repositories/e/e_repository.cc b/paludis/repositories/e/e_repository.cc
index c0ab5ed..c0f72f8 100644
--- a/paludis/repositories/e/e_repository.cc
+++ b/paludis/repositories/e/e_repository.cc
@@ -1091,9 +1091,9 @@ ERepository::make_manifest(const QualifiedPackageName & qpn)
manifest << "DIST " << f.basename() << " "
<< f_stat.file_size()
- << " RMD160 " << hashes->get<RMD160>(f, file_stream)
- << " SHA1 " << hashes->get<SHA1>(f, file_stream)
- << " SHA256 " << hashes->get<SHA256>(f, file_stream)
+ << " RMD160 " << hashes->get("RMD160", f, file_stream)
+ << " SHA1 " << hashes->get("SHA1", f, file_stream)
+ << " SHA256 " << hashes->get("SHA256", f, file_stream)
<< std::endl;
}
}
diff --git a/paludis/repositories/e/memoised_hashes.cc b/paludis/repositories/e/memoised_hashes.cc
index a7215c5..a72c88f 100644
--- a/paludis/repositories/e/memoised_hashes.cc
+++ b/paludis/repositories/e/memoised_hashes.cc
@@ -23,10 +23,7 @@
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/singleton-impl.hh>
#include <paludis/util/safe_ifstream.hh>
-#include <paludis/util/rmd160.hh>
-#include <paludis/util/sha1.hh>
-#include <paludis/util/sha256.hh>
-#include <paludis/util/md5.hh>
+#include <paludis/util/digest_registry.hh>
#include <paludis/util/timestamp.hh>
#include <paludis/util/fs_path.hh>
#include <paludis/util/fs_stat.hh>
@@ -38,7 +35,7 @@ using namespace paludis::erepository;
namespace paludis
{
- typedef std::map<std::pair<std::string, int>, std::pair<Timestamp, std::string> > HashesMap;
+ typedef std::map<std::pair<std::string, std::string>, std::pair<Timestamp, std::string> > HashesMap;
template <>
struct Imp<MemoisedHashes>
@@ -61,45 +58,10 @@ MemoisedHashes::~MemoisedHashes()
{
}
-namespace
-{
- template <typename>
- struct HashIDs;
-
- template <>
- struct HashIDs<RMD160>
- {
- static const int id;
- };
- const int HashIDs<RMD160>::id = 0;
-
- template <>
- struct HashIDs<SHA1>
- {
- static const int id;
- };
- const int HashIDs<SHA1>::id = 1;
-
- template <>
- struct HashIDs<SHA256>
- {
- static const int id;
- };
- const int HashIDs<SHA256>::id = 2;
-
- template <>
- struct HashIDs<MD5>
- {
- static const int id;
- };
- const int HashIDs<MD5>::id = 3;
-}
-
-template <typename H_>
const std::string
-MemoisedHashes::get(const FSPath & file, SafeIFStream & stream) const
+MemoisedHashes::get(const std::string & algo, const FSPath & file, SafeIFStream & stream) const
{
- std::pair<std::string, int> key(stringify(file), HashIDs<H_>::id);
+ std::pair<std::string, std::string> key(stringify(file), algo);
Timestamp mtime(file.stat().mtim());
Lock l(_imp->mutex);
@@ -108,8 +70,7 @@ MemoisedHashes::get(const FSPath & file, SafeIFStream & stream) const
if (i == _imp->hashes.end() || i->second.first != mtime)
{
- H_ hash(stream);
- std::pair<Timestamp, std::string> value(std::make_pair(mtime, hash.hexsum()));
+ std::pair<Timestamp, std::string> value(std::make_pair(mtime, DigestRegistry::get_instance()->get(algo)(stream)));
stream.clear();
stream.seekg(0, std::ios::beg);
@@ -122,11 +83,6 @@ MemoisedHashes::get(const FSPath & file, SafeIFStream & stream) const
return i->second.second;
}
-template const std::string MemoisedHashes::get<RMD160>(const FSPath &, SafeIFStream &) const;
-template const std::string MemoisedHashes::get<SHA1>(const FSPath &, SafeIFStream &) const;
-template const std::string MemoisedHashes::get<SHA256>(const FSPath &, SafeIFStream &) const;
-template const std::string MemoisedHashes::get<MD5>(const FSPath &, SafeIFStream &) const;
-
namespace paludis
{
template class Pimp<MemoisedHashes>;
diff --git a/paludis/repositories/e/memoised_hashes.hh b/paludis/repositories/e/memoised_hashes.hh
index 939d96f..3b59117 100644
--- a/paludis/repositories/e/memoised_hashes.hh
+++ b/paludis/repositories/e/memoised_hashes.hh
@@ -24,6 +24,7 @@
#include <paludis/util/singleton.hh>
#include <paludis/util/fs_path-fwd.hh>
#include <paludis/util/safe_ifstream-fwd.hh>
+#include <string>
namespace paludis
{
@@ -37,8 +38,7 @@ namespace paludis
public:
Pimp<MemoisedHashes> _imp;
- template <typename H_>
- const std::string get(const FSPath & file, SafeIFStream & stream) const;
+ const std::string get(const std::string & algo, const FSPath & file, SafeIFStream & stream) const;
private:
MemoisedHashes();