aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-01 13:53:54 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-01 13:53:54 +0000
commit645f12fca8364a42e7a38d67759757c70a89fed4 (patch)
treefa79094c81e9126a9b5a8afe350afd9453739510
parentfba233709810a152bc4377a4e8747de6d3d3eea4 (diff)
downloadpaludis-645f12fca8364a42e7a38d67759757c70a89fed4.tar.gz
paludis-645f12fca8364a42e7a38d67759757c70a89fed4.tar.xz
Implement names cache for VDB
-rw-r--r--paludis/repositories/vdb/vdb_repository.cc103
-rw-r--r--paludis/repositories/vdb/vdb_repository.hh6
-rw-r--r--paludis/repositories/vdb/vdb_repository.sr1
3 files changed, 106 insertions, 4 deletions
diff --git a/paludis/repositories/vdb/vdb_repository.cc b/paludis/repositories/vdb/vdb_repository.cc
index 7b647c6..b653876 100644
--- a/paludis/repositories/vdb/vdb_repository.cc
+++ b/paludis/repositories/vdb/vdb_repository.cc
@@ -45,6 +45,7 @@
#include <functional>
#include <algorithm>
#include <vector>
+#include <list>
/** \file
* Implementation for VDBRepository.
@@ -58,6 +59,8 @@ using namespace paludis;
namespace
{
+ typedef MakeHashedMap<PackageNamePart, std::list<CategoryNamePart> >::Type NameCacheMap;
+
/**
* Holds an entry in a VDB.
*/
@@ -245,10 +248,7 @@ namespace
return ! std::count_if(DirIterator(vdb_dir), DirIterator(),
IsFileWithExtension(".ebuild"));
}
-}
-namespace
-{
/**
* Fetch the contents of a VDB file.
*
@@ -320,6 +320,8 @@ namespace paludis
/// Provides cache
FSEntry provides_cache;
+ FSEntry names_cache;
+
/// Do we have entries loaded?
mutable bool entries_valid;
@@ -335,6 +337,8 @@ namespace paludis
/// Provieds data
mutable RepositoryProvidesInterface::ProvidesCollection::Pointer provides;
+ mutable NameCacheMap name_cache_map;
+
/// Constructor.
Implementation(const VDBRepositoryParams &);
@@ -353,6 +357,7 @@ namespace paludis
buildroot(p.buildroot),
world_file(p.world),
provides_cache(p.provides_cache),
+ names_cache(p.names_cache),
entries_valid(false),
provides(0)
{
@@ -808,6 +813,15 @@ VDBRepository::make_vdb_repository(
provides_cache = "/var/empty";
}
+ std::string names_cache;
+ if (m->end() == m->find("names_cache") || ((names_cache = m->find("names_cache")->second)).empty())
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "The names_cache key is not set in '"
+ + repo_file + "'. You should read http://paludis.berlios.de/CacheFiles.html and select an "
+ "appropriate value.");
+ names_cache = "/var/empty";
+ }
+
std::string buildroot;
if (m->end() == m->find("buildroot") || ((buildroot = m->find("buildroot")->second)).empty())
buildroot = "/var/tmp/paludis";
@@ -819,7 +833,8 @@ VDBRepository::make_vdb_repository(
.root(root)
.world(world)
.buildroot(buildroot)
- .provides_cache(provides_cache)));
+ .provides_cache(provides_cache)
+ .names_cache(names_cache)));
}
VDBRepositoryConfigurationError::VDBRepositoryConfigurationError(
@@ -1301,6 +1316,13 @@ VDBRepository::load_provided_the_slow_way() const
void
VDBRepository::regenerate_cache() const
{
+ regenerate_provides_cache();
+ regenerate_names_cache();
+}
+
+void
+VDBRepository::regenerate_provides_cache() const
+{
if (_imp->provides_cache == FSEntry("/var/empty"))
return;
@@ -1340,6 +1362,79 @@ VDBRepository::regenerate_cache() const
}
}
+void
+VDBRepository::regenerate_names_cache() const
+{
+ if (_imp->names_cache == FSEntry("/var/empty"))
+ return;
+
+ Context context("When generating VDB repository names cache at '"
+ + stringify(_imp->names_cache) + "':");
+
+ if (_imp->names_cache.is_directory())
+ for (DirIterator i(_imp->names_cache, true), i_end ; i != i_end ; ++i)
+ FSEntry(*i).unlink();
+
+ _imp->names_cache.dirname().mkdir();
+ FSEntry(_imp->names_cache).mkdir();
+
+ MakeHashedMap<std::string, std::string>::Type m;
+
+ CategoryNamePartCollection::ConstPointer cats(category_names());
+ for (CategoryNamePartCollection::Iterator c(cats->begin()), c_end(cats->end()) ;
+ c != c_end ; ++c)
+ {
+ QualifiedPackageNameCollection::ConstPointer pkgs(package_names(*c));
+ for (QualifiedPackageNameCollection::Iterator p(pkgs->begin()), p_end(pkgs->end()) ;
+ p != p_end ; ++p)
+ m[stringify(p->package)].append(stringify(*c) + "\n");
+ }
+
+ for (MakeHashedMap<std::string, std::string>::Type::const_iterator e(m.begin()), e_end(m.end()) ;
+ e != e_end ; ++e)
+ {
+ std::ofstream f(stringify(_imp->names_cache / stringify(e->first)).c_str());
+ if (! f)
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Cannot write to '"
+ + stringify(_imp->names_cache) + "'");
+ continue;
+ }
+ f << e->second;
+ }
+
+}
+
+CategoryNamePartCollection::ConstPointer
+VDBRepository::do_category_names_containing_package(const PackageNamePart & p) const
+{
+ if (_imp->names_cache == FSEntry("/var/empty"))
+ return Repository::do_category_names_containing_package(p);
+
+ CategoryNamePartCollection::Pointer result(new CategoryNamePartCollection::Concrete);
+ NameCacheMap::iterator r(_imp->name_cache_map.find(p));
+
+ if (_imp->name_cache_map.end() == r)
+ {
+ r = _imp->name_cache_map.insert(std::make_pair(p, std::list<CategoryNamePart>())).first;
+
+ FSEntry ff(_imp->names_cache / stringify(p));
+ if (ff.exists())
+ {
+ std::ifstream f(stringify(ff).c_str());
+ if (! f)
+ Log::get_instance()->message(ll_warning, lc_context, "Cannot read '" + stringify(ff) + "'");
+ std::string line;
+ while (std::getline(f, line))
+ r->second.push_back(CategoryNamePart(line));
+ }
+ }
+
+ std::copy(r->second.begin(), r->second.end(), result->inserter());
+
+ return result;
+}
+
#ifdef PALUDIS_ENABLE_VISIBILITY
# pragma GCC visibility push(default)
#endif
diff --git a/paludis/repositories/vdb/vdb_repository.hh b/paludis/repositories/vdb/vdb_repository.hh
index 8ff5e8b..64c1375 100644
--- a/paludis/repositories/vdb/vdb_repository.hh
+++ b/paludis/repositories/vdb/vdb_repository.hh
@@ -59,6 +59,9 @@ namespace paludis
bool load_provided_using_cache() const;
void load_provided_the_slow_way() const;
+ void regenerate_provides_cache() const;
+ void regenerate_names_cache() const;
+
protected:
virtual bool do_has_category_named(const CategoryNamePart &) const;
@@ -107,6 +110,9 @@ namespace paludis
/* end of RepositoryUseInterface */
+ virtual CategoryNamePartCollection::ConstPointer do_category_names_containing_package(
+ const PackageNamePart &) const;
+
public:
/**
* Constructor.
diff --git a/paludis/repositories/vdb/vdb_repository.sr b/paludis/repositories/vdb/vdb_repository.sr
index 04928d9..ad407fc 100644
--- a/paludis/repositories/vdb/vdb_repository.sr
+++ b/paludis/repositories/vdb/vdb_repository.sr
@@ -9,6 +9,7 @@ make_class_VDBRepositoryParams()
key root FSEntry
key world FSEntry
key provides_cache FSEntry
+ key names_cache FSEntry
key buildroot FSEntry
doxygen_comment << "END"