summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2010-05-31 20:00:16 +0200
committerDavid Kalnischkies <kalnischkies@gmail.com>2010-05-31 20:00:16 +0200
commitbd2fb30a8647293f80b085d0308e66bb9219e662 (patch)
tree57b557e653984d2d7fcb38fc60d75220f9712b14 /apt-pkg
parent093e9f5d30f37164dd28d639fedfb059e105e43e (diff)
* apt-pkg/pkgcache.cc:
- get the best matching arch package from a group with FindPreferredPkg
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/cacheiterators.h5
-rw-r--r--apt-pkg/pkgcache.cc19
2 files changed, 24 insertions, 0 deletions
diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h
index ee852f594..e5b23a818 100644
--- a/apt-pkg/cacheiterators.h
+++ b/apt-pkg/cacheiterators.h
@@ -104,6 +104,11 @@ class pkgCache::GrpIterator: public Iterator<Group, GrpIterator> {
inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;};
inline PkgIterator PackageList() const;
PkgIterator FindPkg(string Arch = "any");
+ /** \brief find the package with the "best" architecture
+
+ The best architecture is either the "native" or the first
+ in the list of Architectures which is not an end-Pointer */
+ PkgIterator FindPreferredPkg();
PkgIterator NextPkg(PkgIterator const &Pkg);
// Constructors
diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc
index a59a06d65..adaae9c89 100644
--- a/apt-pkg/pkgcache.cc
+++ b/apt-pkg/pkgcache.cc
@@ -343,6 +343,25 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) {
return PkgIterator(*Owner, 0);
}
/*}}}*/
+// GrpIterator::FindPreferredPkg - Locate the "best" package /*{{{*/
+// ---------------------------------------------------------------------
+/* Returns an End-Pointer on error, pointer to the package otherwise */
+pkgCache::PkgIterator pkgCache::GrpIterator::FindPreferredPkg() {
+ pkgCache::PkgIterator Pkg = FindPkg("native");
+ if (Pkg.end() == false)
+ return Pkg;
+
+ std::vector<std::string> const archs = APT::Configuration::getArchitectures();
+ for (std::vector<std::string>::const_iterator a = archs.begin();
+ a != archs.end(); ++a) {
+ Pkg = FindPkg(*a);
+ if (Pkg.end() == false)
+ return Pkg;
+ }
+
+ return PkgIterator(*Owner, 0);
+}
+ /*}}}*/
// GrpIterator::NextPkg - Locate the next package in the group /*{{{*/
// ---------------------------------------------------------------------
/* Returns an End-Pointer on error, pointer to the package otherwise.