aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-29 21:50:27 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-29 21:50:27 +0000
commitc2082f88308b0fe859a8881209285e0deb4d4f91 (patch)
tree6ec6bbb76ccb2063d822701a938ab00c214d6682
parent319fafa72114c3c6089e1ce2a59e8db7beceae62 (diff)
downloadpaludis-c2082f88308b0fe859a8881209285e0deb4d4f91.tar.gz
paludis-c2082f88308b0fe859a8881209285e0deb4d4f91.tar.xz
Make a new MirrorsInterface for Repository classes.
-rw-r--r--paludis/qa/src_uri_check.cc5
-rw-r--r--paludis/repositories/fake/fake_repository.cc9
-rw-r--r--paludis/repositories/fake/fake_repository.hh2
-rw-r--r--paludis/repositories/nothing/nothing_repository.cc9
-rw-r--r--paludis/repositories/nothing/nothing_repository.hh2
-rw-r--r--paludis/repositories/portage/portage_repository.cc49
-rw-r--r--paludis/repositories/portage/portage_repository.hh7
-rw-r--r--paludis/repositories/vdb/vdb_repository.cc9
-rw-r--r--paludis/repositories/vdb/vdb_repository.hh2
-rw-r--r--paludis/repository.hh45
10 files changed, 77 insertions, 62 deletions
diff --git a/paludis/qa/src_uri_check.cc b/paludis/qa/src_uri_check.cc
index 3fdf4c0..1ef96fc 100644
--- a/paludis/qa/src_uri_check.cc
+++ b/paludis/qa/src_uri_check.cc
@@ -78,8 +78,9 @@ namespace
else
{
mirror_host.erase(p);
- if (! env->package_database()->fetch_repository(
- env->package_database()->favourite_repository())->is_mirror(mirror_host))
+ Repository::MirrorInterface * m(env->package_database()->fetch_repository(
+ env->package_database()->favourite_repository())->get_interface<repo_mirrors>());
+ if ((! m) || (! m->is_mirror(mirror_host)))
result << Message(qal_major, "Unknown mirror for '" + a->text() + "'");
}
}
diff --git a/paludis/repositories/fake/fake_repository.cc b/paludis/repositories/fake/fake_repository.cc
index 8cf0d53..10ead5c 100644
--- a/paludis/repositories/fake/fake_repository.cc
+++ b/paludis/repositories/fake/fake_repository.cc
@@ -80,7 +80,8 @@ FakeRepository::FakeRepository(const RepositoryName & name) :
param<repo_uninstallable>(static_cast<UninstallableInterface *>(0)),
param<repo_use>(this),
param<repo_world>(static_cast<WorldInterface *>(0)),
- param<repo_environment_variable>(static_cast<EnvironmentVariableInterface *>(0))
+ param<repo_environment_variable>(static_cast<EnvironmentVariableInterface *>(0)),
+ param<repo_mirrors>(static_cast<MirrorInterface *>(0))
))),
Repository::MaskInterface(),
Repository::UseInterface(),
@@ -251,12 +252,6 @@ FakeRepository::do_is_licence(const std::string &) const
return false;
}
-bool
-FakeRepository::do_is_mirror(const std::string &) const
-{
- return false;
-}
-
void
FakeRepository::invalidate() const
{
diff --git a/paludis/repositories/fake/fake_repository.hh b/paludis/repositories/fake/fake_repository.hh
index ce94dfa..04f8d05 100644
--- a/paludis/repositories/fake/fake_repository.hh
+++ b/paludis/repositories/fake/fake_repository.hh
@@ -83,8 +83,6 @@ namespace paludis
virtual bool do_is_licence(const std::string &) const;
- virtual bool do_is_mirror(const std::string &) const;
-
public:
/**
* Constructor.
diff --git a/paludis/repositories/nothing/nothing_repository.cc b/paludis/repositories/nothing/nothing_repository.cc
index d640a75..e1a18a1 100644
--- a/paludis/repositories/nothing/nothing_repository.cc
+++ b/paludis/repositories/nothing/nothing_repository.cc
@@ -95,7 +95,8 @@ NothingRepository::NothingRepository(const NothingRepositoryParams & p) try :
param<repo_uninstallable>(static_cast<UninstallableInterface *>(0)),
param<repo_use>(static_cast<UseInterface *>(0)),
param<repo_world>(static_cast<WorldInterface *>(0)),
- param<repo_environment_variable>(static_cast<EnvironmentVariableInterface *>(0))
+ param<repo_environment_variable>(static_cast<EnvironmentVariableInterface *>(0)),
+ param<repo_mirrors>(static_cast<MirrorInterface *>(0))
))),
PrivateImplementationPattern<NothingRepository>(new Implementation<NothingRepository>(p))
{
@@ -214,12 +215,6 @@ NothingRepository::do_is_licence(const std::string &) const
}
bool
-NothingRepository::do_is_mirror(const std::string &) const
-{
- return false;
-}
-
-bool
NothingRepository::do_sync() const
{
Context context("When syncing repository '" + stringify(name()) + "':");
diff --git a/paludis/repositories/nothing/nothing_repository.hh b/paludis/repositories/nothing/nothing_repository.hh
index 8cee5c9..a47d60e 100644
--- a/paludis/repositories/nothing/nothing_repository.hh
+++ b/paludis/repositories/nothing/nothing_repository.hh
@@ -106,8 +106,6 @@ namespace paludis
virtual bool do_is_licence(const std::string &) const;
- virtual bool do_is_mirror(const std::string &) const;
-
virtual bool do_sync() const;
public:
diff --git a/paludis/repositories/portage/portage_repository.cc b/paludis/repositories/portage/portage_repository.cc
index f81ee82..2d6307f 100644
--- a/paludis/repositories/portage/portage_repository.cc
+++ b/paludis/repositories/portage/portage_repository.cc
@@ -87,7 +87,7 @@ namespace paludis
typedef MakeHashedMap<QualifiedPackageName, bool>::Type PackagesMap;
/// Map for mirrors.
- typedef MakeHashedMap<std::string, std::list<std::string> >::Type MirrorMap;
+ typedef MakeHashedMultiMap<std::string, std::string>::Type MirrorMap;
/// Map for metadata.
typedef MakeHashedMap<std::pair<QualifiedPackageName, VersionSpec>,
@@ -241,7 +241,8 @@ PortageRepository::PortageRepository(const PortageRepositoryParams & p) :
param<repo_uninstallable>(static_cast<UninstallableInterface *>(0)),
param<repo_use>(this),
param<repo_world>(static_cast<WorldInterface *>(0)),
- param<repo_environment_variable>(this)
+ param<repo_environment_variable>(this),
+ param<repo_mirrors>(this)
))),
PrivateImplementationPattern<PortageRepository>(new Implementation<PortageRepository>(this, p))
{
@@ -854,8 +855,8 @@ PortageRepository::do_is_licence(const std::string & s) const
return l.exists() && l.is_regular_file();
}
-bool
-PortageRepository::do_is_mirror(const std::string & s) const
+void
+PortageRepository::need_mirrors() const
{
if (! _imp->has_mirrors)
{
@@ -873,9 +874,9 @@ PortageRepository::do_is_mirror(const std::string & s) const
std::random_shuffle(next(entries.begin()), entries.end(), r);
if (entries.size() > 6)
entries.resize(6);
- _imp->mirrors.insert(std::make_pair(
- entries.at(0),
- std::list<std::string>(next(entries.begin()), entries.end())));
+ for (std::vector<std::string>::const_iterator e(next(entries.begin())),
+ e_end(entries.end()) ; e != e_end ; ++e)
+ _imp->mirrors.insert(std::make_pair(entries.at(0), *e));
}
}
}
@@ -887,8 +888,6 @@ PortageRepository::do_is_mirror(const std::string & s) const
_imp->has_mirrors = true;
}
-
- return _imp->mirrors.end() != _imp->mirrors.find(s);
}
namespace
@@ -1051,11 +1050,11 @@ PortageRepository::do_install(const QualifiedPackageName & q, const VersionSpec
m != m_end ; ++m)
flat_src_uri.append(m->second + "/" + mirror.substr(q + 1) + " ");
- for (std::list<std::string>::iterator
- m(_imp->mirrors.find(mirror.substr(0, q))->second.begin()),
- m_end(_imp->mirrors.find(mirror.substr(0, q))->second.end()) ;
+ for (MirrorsIterator
+ m(begin_mirrors(mirror.substr(0, q))),
+ m_end(end_mirrors(mirror.substr(0, q))) ;
m != m_end ; ++m)
- flat_src_uri.append(*m + "/" + mirror.substr(q + 1) + " ");
+ flat_src_uri.append(m->second + "/" + mirror.substr(q + 1) + " ");
}
else
flat_src_uri.append((*ff)->text());
@@ -1063,7 +1062,7 @@ PortageRepository::do_install(const QualifiedPackageName & q, const VersionSpec
/* add mirror://gentoo/ entries */
std::string master_mirror(strip_trailing_string(stringify(name()), "x-"));
- if (is_mirror(master_mirror) && ! no_mirror)
+ if (! no_mirror && is_mirror(master_mirror))
{
for (Environment::MirrorIterator
m(_imp->params.get<prpk_environment>()->begin_mirrors(master_mirror)),
@@ -1071,11 +1070,10 @@ PortageRepository::do_install(const QualifiedPackageName & q, const VersionSpec
m != m_end ; ++m)
flat_src_uri.append(m->second + "/" + (*ff)->text().substr(p + 1) + " ");
- for (std::list<std::string>::iterator
- m(_imp->mirrors.find(master_mirror)->second.begin()),
- m_end(_imp->mirrors.find(master_mirror)->second.end()) ;
+ for (MirrorsIterator
+ m(begin_mirrors(master_mirror)), m_end(end_mirrors(master_mirror)) ;
m != m_end ; ++m)
- flat_src_uri.append(*m + "/" + (*ff)->text().substr(p + 1) + " ");
+ flat_src_uri.append(m->second + "/" + (*ff)->text().substr(p + 1) + " ");
}
}
@@ -1420,3 +1418,18 @@ PortageRepository::find_our_virtuals(const QualifiedPackageName & q) const
return OurVirtualsIterator(_imp->our_virtuals.find(q));
}
+PortageRepository::MirrorsIterator
+PortageRepository::begin_mirrors(const std::string & s) const
+{
+ need_mirrors();
+ return MirrorsIterator(_imp->mirrors.equal_range(s).first);
+}
+
+PortageRepository::MirrorsIterator
+PortageRepository::end_mirrors(const std::string & s) const
+{
+ need_mirrors();
+ return MirrorsIterator(_imp->mirrors.equal_range(s).second);
+}
+
+
diff --git a/paludis/repositories/portage/portage_repository.hh b/paludis/repositories/portage/portage_repository.hh
index 2a90520..55709df 100644
--- a/paludis/repositories/portage/portage_repository.hh
+++ b/paludis/repositories/portage/portage_repository.hh
@@ -54,12 +54,14 @@ namespace paludis
public Repository::NewsInterface,
public Repository::SetsInterface,
public Repository::EnvironmentVariableInterface,
+ public Repository::MirrorInterface,
private PrivateImplementationPattern<PortageRepository>
{
private:
void need_category_names() const;
void need_version_names(const QualifiedPackageName &) const;
void need_virtual_names() const;
+ void need_mirrors() const;
PackageDatabaseEntryCollection::Iterator find_best(PackageDatabaseEntryCollection & c,
const PackageDatabaseEntry & e) const;
@@ -109,8 +111,6 @@ namespace paludis
virtual bool do_is_licence(const std::string &) const;
- virtual bool do_is_mirror(const std::string &) const;
-
virtual void do_install(const QualifiedPackageName &, const VersionSpec &,
const InstallOptions &) const;
@@ -151,6 +151,9 @@ namespace paludis
const PackageDatabaseEntry & for_package,
const std::string & var) const;
+ virtual MirrorsIterator begin_mirrors(const std::string & s) const;
+ virtual MirrorsIterator end_mirrors(const std::string & s) const;
+
typedef CountedPtr<PortageRepository, count_policy::InternalCountTag> Pointer;
typedef CountedPtr<const PortageRepository, count_policy::InternalCountTag> ConstPointer;
diff --git a/paludis/repositories/vdb/vdb_repository.cc b/paludis/repositories/vdb/vdb_repository.cc
index d029534..7c30a93 100644
--- a/paludis/repositories/vdb/vdb_repository.cc
+++ b/paludis/repositories/vdb/vdb_repository.cc
@@ -401,7 +401,8 @@ VDBRepository::VDBRepository(const VDBRepositoryParams & p) :
param<repo_uninstallable>(this),
param<repo_use>(this),
param<repo_world>(this),
- param<repo_environment_variable>(this)
+ param<repo_environment_variable>(this),
+ param<repo_mirrors>(static_cast<MirrorInterface *>(0))
))),
PrivateImplementationPattern<VDBRepository>(new Implementation<VDBRepository>(p))
{
@@ -744,12 +745,6 @@ VDBRepository::do_is_licence(const std::string &) const
return false;
}
-bool
-VDBRepository::do_is_mirror(const std::string &) const
-{
- return false;
-}
-
void
VDBRepository::do_uninstall(const QualifiedPackageName & q, const VersionSpec & v, const InstallOptions & o) const
{
diff --git a/paludis/repositories/vdb/vdb_repository.hh b/paludis/repositories/vdb/vdb_repository.hh
index 18bb536..c9d1573 100644
--- a/paludis/repositories/vdb/vdb_repository.hh
+++ b/paludis/repositories/vdb/vdb_repository.hh
@@ -132,8 +132,6 @@ namespace paludis
virtual bool do_is_licence(const std::string &) const;
- virtual bool do_is_mirror(const std::string &) const;
-
virtual void do_uninstall(const QualifiedPackageName &, const VersionSpec &,
const InstallOptions &) const;
diff --git a/paludis/repository.hh b/paludis/repository.hh
index fe12323..4ce3e9f 100644
--- a/paludis/repository.hh
+++ b/paludis/repository.hh
@@ -127,6 +127,7 @@ namespace paludis
repo_use,
repo_world,
repo_environment_variable,
+ repo_mirrors,
last_repo
};
@@ -229,6 +230,7 @@ namespace paludis
class UseInterface;
class WorldInterface;
class EnvironmentVariableInterface;
+ class MirrorInterface;
protected:
/**
@@ -249,6 +251,7 @@ namespace paludis
SmartRecordKey<repo_uninstallable, UninstallableInterface *>,
SmartRecordKey<repo_use, UseInterface *>,
SmartRecordKey<repo_world, WorldInterface *>,
+ SmartRecordKey<repo_mirrors, MirrorInterface *>,
SmartRecordKey<repo_environment_variable, EnvironmentVariableInterface *>
{
};
@@ -331,11 +334,6 @@ namespace paludis
*/
virtual bool do_is_licence(const std::string &) const = 0;
- /**
- * Override in descendents: is this a mirror?
- */
- virtual bool do_is_mirror(const std::string &) const = 0;
-
///}
public:
@@ -445,14 +443,6 @@ namespace paludis
}
/**
- * Query whether the specified item is a mirror.
- */
- bool is_mirror(const std::string & u) const
- {
- return do_is_mirror(u);
- }
-
- /**
* Invalidate any cache.
*/
virtual void invalidate() const = 0;
@@ -834,6 +824,35 @@ namespace paludis
};
/**
+ * Interface for mirror querying for repositories.
+ *
+ * \see Repository
+ * \ingroup grprepository
+ */
+ class Repository::MirrorInterface
+ {
+ public:
+ ///\name Iterate over our mirrors
+ ///\{
+
+ typedef libwrapiter::ForwardIterator<MirrorInterface,
+ const std::pair<const std::string, std::string> > MirrorsIterator;
+
+ virtual MirrorsIterator begin_mirrors(const std::string & s) const = 0;
+ virtual MirrorsIterator end_mirrors(const std::string & s) const = 0;
+
+ /**
+ * Is the named item a mirror?
+ */
+ bool is_mirror(const std::string & s) const
+ {
+ return begin_mirrors(s) != end_mirrors(s);
+ }
+
+ virtual ~MirrorInterface() { }
+ };
+
+ /**
* Thrown if a repository of the specified type does not exist.
*
* \ingroup grpexceptions