[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#470210: [API] There should be a way to find meta-information about source packages.



Package: apt
Version: 0.7.11
Severity: wishlist
Tags: patch

  When working with source packages, the standard procedure is to look
the package up via pkgSrcRecords::Find, then read off its information.
However, this doesn't provide any way (that I can find) to retrieve the
archive from which a package came.  The only route to getting this
information seems to be to walk over the pkgSourceList, walk over each
included index file, and read off packages until a match is found.

  The attached patch adds a link from the source-records object to the
meta index.  This is done by adding a new virtual method to indexFile,
which returns NULL for most implementations, but a metaIndex pointer
for source records.  There's no particular reason this isn't
implemented in more cases, and in fact I think probably it should be
implemented for all subclasses of pkgIndexFile (maybe even made a
member variable of pkgIndexFile that subclasses have to pass to the
constructor).

  Daniel
=== modified file 'apt-pkg/deb/debindexfile.cc'
--- apt-pkg/deb/debindexfile.cc	2007-06-08 23:44:03 +0000
+++ apt-pkg/deb/debindexfile.cc	2008-03-09 19:46:29 +0000
@@ -27,8 +27,10 @@
 // SourcesIndex::debSourcesIndex - Constructor				/*{{{*/
 // ---------------------------------------------------------------------
 /* */
-debSourcesIndex::debSourcesIndex(string URI,string Dist,string Section,bool Trusted) :
-     pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section)
+debSourcesIndex::debSourcesIndex(string URI,string Dist,string Section,bool Trusted,
+				 metaIndex *MetaIndex) :
+  pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section),
+  MetaIndex(MetaIndex)
 {
 }
 									/*}}}*/
@@ -101,6 +103,13 @@
    return Info;
 }
 									/*}}}*/
+
+
+metaIndex *debSourcesIndex::GetMetaIndex() const
+{
+  return MetaIndex;
+}
+
 // SourcesIndex::Index* - Return the URI to the index files		/*{{{*/
 // ---------------------------------------------------------------------
 /* */

=== modified file 'apt-pkg/deb/debindexfile.h'
--- apt-pkg/deb/debindexfile.h	2006-12-14 11:39:29 +0000
+++ apt-pkg/deb/debindexfile.h	2008-03-09 19:37:20 +0000
@@ -108,6 +108,8 @@
    string Dist;
    string Section;
 
+   metaIndex *MetaIndex;
+
    string Info(const char *Type) const;
    string IndexFile(const char *Type) const;
    string IndexURI(const char *Type) const;
@@ -131,8 +133,11 @@
    virtual bool Exists() const;
    virtual bool HasPackages() const {return false;};
    virtual unsigned long Size() const;
+
+   virtual metaIndex *GetMetaIndex() const;
    
-   debSourcesIndex(string URI,string Dist,string Section,bool Trusted);
+   debSourcesIndex(string URI,string Dist,string Section,bool Trusted,
+		   metaIndex *IndexRecords);
 };
 
 #endif

=== modified file 'apt-pkg/deb/debmetaindex.cc'
--- apt-pkg/deb/debmetaindex.cc	2008-02-04 09:49:15 +0000
+++ apt-pkg/deb/debmetaindex.cc	2008-03-09 19:35:28 +0000
@@ -198,7 +198,7 @@
    for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin(); 
 	I != SectionEntries.end(); I++) {
       if ((*I)->IsSrc)
-         Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
+	Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted(), this));
       else 
       {
          Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted()));

=== modified file 'apt-pkg/indexfile.h'
--- apt-pkg/indexfile.h	2006-12-14 11:39:29 +0000
+++ apt-pkg/indexfile.h	2008-03-09 19:37:12 +0000
@@ -32,6 +32,7 @@
 
 class pkgAcquire;
 class pkgCacheGenerator;
+class metaIndex;
 class OpProgress;
 class pkgIndexFile
 {
@@ -77,6 +78,11 @@
    virtual bool Merge(pkgCacheGenerator &/*Gen*/,OpProgress &/*Prog*/) const {return false;};
    virtual bool MergeFileProvides(pkgCacheGenerator &/*Gen*/,OpProgress &/*Prog*/) const {return true;};
    virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
+   /** \return the index record containing meta-data (such as suite
+    *  and distribution) about this file, or NULL if there is no
+    *  appropriate record.
+    */
+   virtual metaIndex *GetMetaIndex() const { return 0; }
 
    static bool TranslationsAvailable();
    static bool CheckLanguageCode(const char *Lang);


Reply to: