summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-01-17 12:53:20 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-01-17 12:53:20 +0100
commit8ebabf3d9026d1a738a4e8988e168902af7446e3 (patch)
treefd53dd025b002f418e45749d6cf1be3c20f2aa39
parent25353dc6646e5b9fff55059a5c85183589cf472d (diff)
Allow querying all binaries built by a source package
This adds a simple way to lookup binaries by a source package, but this adds all binaries into one list, even with different source versions. Be careful.
-rw-r--r--apt-pkg/cacheiterators.h12
-rw-r--r--apt-pkg/deb/deblistparser.cc34
-rw-r--r--apt-pkg/pkgcache.h12
3 files changed, 35 insertions, 23 deletions
diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h
index 5c3ad9bbb..ff2b65cdf 100644
--- a/apt-pkg/cacheiterators.h
+++ b/apt-pkg/cacheiterators.h
@@ -116,6 +116,7 @@ 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;
+ inline VerIterator VersionsInSource() const;
PkgIterator FindPkg(APT::StringView Arch = APT::StringView("any", 3)) const;
/** \brief find the package with the "best" architecture
@@ -193,6 +194,13 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
inline VerIterator& operator++() {if (S != Owner->VerP) S = Owner->VerP + S->NextVer; return *this;}
inline VerIterator operator++(int) { VerIterator const tmp(*this); operator++(); return tmp; }
+ inline VerIterator NextInSource()
+ {
+ if (S != Owner->VerP)
+ S = Owner->VerP + S->NextInSource;
+ return *this;
+ }
+
// Comparison
int CompareVer(const VerIterator &B) const;
/** \brief compares two version and returns if they are similar
@@ -494,6 +502,10 @@ class pkgCache::DescFileIterator : public Iterator<DescFile, DescFileIterator> {
// Inlined Begin functions can't be in the class because of order problems /*{{{*/
inline pkgCache::PkgIterator pkgCache::GrpIterator::PackageList() const
{return PkgIterator(*Owner,Owner->PkgP + S->FirstPackage);}
+ inline pkgCache::VerIterator pkgCache::GrpIterator::VersionsInSource() const
+ {
+ return VerIterator(*Owner, Owner->VerP + S->VersionsInSource);
+ }
inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
{return VerIterator(*Owner,Owner->VerP + S->VersionList);}
inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 21d1736e4..7614423df 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -166,8 +166,12 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
}
// Parse the source package name
pkgCache::GrpIterator G = Ver.ParentPkg().Group();
+
+ // Setup the defaults
Ver->SourcePkgName = G->Name;
Ver->SourceVerStr = Ver->VerStr;
+
+ // Parse the name and version str
if (Section.Find(pkgTagSection::Key::Source,Start,Stop) == true)
{
const char * const Space = static_cast<const char *>(memchr(Start, ' ', Stop - Start));
@@ -194,33 +198,19 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
}
APT::StringView const pkgname(Start, Stop - Start);
+ // Oh, our group is the wrong one for the source package. Make a new one.
if (pkgname != G.Name())
{
- for (pkgCache::PkgIterator P = G.PackageList(); P.end() == false; P = G.NextPkg(P))
- {
- for (V = P.VersionList(); V.end() == false; ++V)
- {
- if (pkgname == V.SourcePkgName())
- {
- Ver->SourcePkgName = V->SourcePkgName;
- break;
- }
- }
- if (V.end() == false)
- break;
- }
- if (V.end() == true)
- {
- pkgCache::GrpIterator SG;
- if (not NewGroup(SG, pkgname))
- return false;
-
- G = Ver.ParentPkg().Group();
- Ver->SourcePkgName = SG->Name;
- }
+ if (not NewGroup(G, pkgname))
+ return false;
}
}
+ // Link into by source package group.
+ Ver->SourcePkgName = G->Name;
+ Ver->NextInSource = G->VersionsInSource;
+ G->VersionsInSource = Ver.Index();
+
Ver->MultiArch = ParseMultiArch(true);
// Archive Size
Ver->Size = Section.FindULL(pkgTagSection::Key::Size);
diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h
index 3f77d5eae..52446e8f5 100644
--- a/apt-pkg/pkgcache.h
+++ b/apt-pkg/pkgcache.h
@@ -383,7 +383,11 @@ struct pkgCache::Header
On or more packages with the same name form a group, so we have
a simple way to access a package built for different architectures
Group exists in a singly linked list of group records starting at
- the hash index of the name in the pkgCache::Header::GrpHashTable */
+ the hash index of the name in the pkgCache::Header::GrpHashTable
+
+ They also act as a representation of source packages, allowing you to
+ iterate over all binaries produced by a source package.
+ */
struct pkgCache::Group
{
/** \brief Name of the group */
@@ -394,11 +398,15 @@ struct pkgCache::Group
map_pointer_t FirstPackage; // Package
/** \brief Link to the last package which belongs to the group */
map_pointer_t LastPackage; // Package
+
/** \brief Link to the next Group */
map_pointer_t Next; // Group
/** \brief unique sequel ID */
map_id_t ID;
+ /** \brief List of binary produces by source package with this name. */
+ map_pointer_t VersionsInSource; // Version
+
};
/*}}}*/
// Package structure /*{{{*/
@@ -642,6 +650,8 @@ struct pkgCache::Version
map_id_t ID;
/** \brief parsed priority value */
map_number_t Priority;
+ /** \brief next version in the source package (might be different binary) */
+ map_pointer_t NextInSource; // Version
};
/*}}}*/
// Description structure /*{{{*/