aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2012-03-29 18:59:11 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2012-03-30 18:30:57 +0100
commit28da33d1363d6b7ff1298da7eccd5f387450fbc3 (patch)
tree82ff6dad75fb52c63aa1354c7d90ddb145ca826a
parent1e382e3bc8282544d898fa711f6d8e64c566b6c6 (diff)
downloadpaludis-28da33d1363d6b7ff1298da7eccd5f387450fbc3.tar.gz
paludis-28da33d1363d6b7ff1298da7eccd5f387450fbc3.tar.xz
Add support for calculating/caching eclass/exlib MD5s
-rw-r--r--paludis/repositories/e/eclass_mtimes.cc20
-rw-r--r--paludis/repositories/e/eclass_mtimes.hh5
2 files changed, 24 insertions, 1 deletions
diff --git a/paludis/repositories/e/eclass_mtimes.cc b/paludis/repositories/e/eclass_mtimes.cc
index 9d6e71a..c247476 100644
--- a/paludis/repositories/e/eclass_mtimes.cc
+++ b/paludis/repositories/e/eclass_mtimes.cc
@@ -2,7 +2,7 @@
/*
* Copyright (c) 2006, 2007, 2008, 2010, 2011 Ciaran McCreesh
- * Copyright (c) 2008 David Leverton
+ * Copyright (c) 2008, 2012 David Leverton
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -28,10 +28,14 @@
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/hashes.hh>
#include <paludis/util/fs_stat.hh>
+#include <paludis/util/md5.hh>
+#include <paludis/util/safe_ifstream.hh>
#include <unordered_map>
using namespace paludis;
+typedef std::unordered_map<FSPath, std::string, Hash<FSPath> > MD5Map;
+
namespace
{
struct Cache
@@ -72,6 +76,7 @@ namespace paludis
const ERepository * repo;
mutable Cache eclasses;
mutable std::unordered_map<QualifiedPackageName, Cache, Hash<QualifiedPackageName> > exlibs;
+ mutable MD5Map md5s;
mutable Mutex mutex;
Imp(const ERepository * r, const std::shared_ptr<const FSPathSequence> & d) :
@@ -108,3 +113,16 @@ EclassMtimes::exlib(const std::string & e, const QualifiedPackageName & qpn) con
return lookup(e + ".exlib", cache->second);
}
+std::string
+EclassMtimes::md5(const FSPath & p) const
+{
+ Lock l(_imp->mutex);
+ MD5Map::const_iterator it(_imp->md5s.find(p));
+ if (_imp->md5s.end() != it)
+ return it->second;
+
+ SafeIFStream s(p);
+ MD5 m(s);
+ return _imp->md5s.insert(std::make_pair(p, m.hexsum())).first->second;
+}
+
diff --git a/paludis/repositories/e/eclass_mtimes.hh b/paludis/repositories/e/eclass_mtimes.hh
index 033bb37..5a2ac3b 100644
--- a/paludis/repositories/e/eclass_mtimes.hh
+++ b/paludis/repositories/e/eclass_mtimes.hh
@@ -61,6 +61,11 @@ namespace paludis
* Fetch the full path of a given exlib, on the path of a given package.
*/
const std::pair<FSPath, FSStat> * exlib(const std::string &, const QualifiedPackageName &) const;
+
+ /**
+ * Fetch the MD5 checksum of a given file.
+ */
+ std::string md5(const FSPath &) const;
};
}