]> git.saurik.com Git - apt.git/commitdiff
* apt-pkg/pkgcache.cc:
authorDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 31 May 2010 18:00:16 +0000 (20:00 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 31 May 2010 18:00:16 +0000 (20:00 +0200)
  - get the best matching arch package from a group with FindPreferredPkg

apt-pkg/cacheiterators.h
apt-pkg/pkgcache.cc
debian/changelog

index ee852f594e81c53153780da978e72959748651b3..e5b23a81880a78ca2b94b80500329bcecd8a7c6c 100644 (file)
@@ -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
index a59a06d65411375cad6ceebeea33bc08290d2d9f..adaae9c89139361d94c2bd1deb1be819ffc71d35 100644 (file)
@@ -340,6 +340,25 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string Arch) {
                        break;
        }
 
+       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);
 }
                                                                        /*}}}*/
index 6341484f267a9b1d7f8543603640b14e860edc04..9200034846b7f12a581aa7750a86e999a534ca76 100644 (file)
@@ -28,8 +28,10 @@ apt (0.7.26~exp6) UNRELEASED; urgency=low
     - move cmdline parsing from apt-cache to new FromCommandLine method
   * apt-pkg/contrib/cmdline.cc:
     - fix segfault in SaveInConfig caused by writing over char[] sizes
+  * apt-pkg/pkgcache.cc:
+    - get the best matching arch package from a group with FindPreferredPkg
 
- -- David Kalnischkies <kalnischkies@gmail.com>  Mon, 31 May 2010 17:21:00 +0200
+ -- David Kalnischkies <kalnischkies@gmail.com>  Mon, 31 May 2010 19:59:04 +0200
 
 apt (0.7.26~exp5) experimental; urgency=low