summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2016-11-29 22:40:20 -0800
committerSam Bingner <sam@bingner.com>2019-08-17 12:29:11 -1000
commit28b6166f80db429fc04ad9c8821ec7d0c54714b0 (patch)
tree2cc68fdbdcea978f7d2389a31e7c85a1e4889ff5 /apt-pkg
parent7dce4f9a0f7f4cf131dcc585d20663ec57910e61 (diff)
Store tags in the cache (they are very useful :/).
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/cacheiterators.h45
-rw-r--r--apt-pkg/deb/deblistparser.cc42
-rw-r--r--apt-pkg/deb/deblistparser.h1
-rw-r--r--apt-pkg/pkgcache.cc1
-rw-r--r--apt-pkg/pkgcache.h18
-rw-r--r--apt-pkg/pkgcachegen.cc30
-rw-r--r--apt-pkg/pkgcachegen.h2
7 files changed, 139 insertions, 0 deletions
diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h
index 20853061e..22e5574c9 100644
--- a/apt-pkg/cacheiterators.h
+++ b/apt-pkg/cacheiterators.h
@@ -233,6 +233,7 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
DescIterator TranslatedDescription() const;
inline DepIterator DependsList() const;
inline PrvIterator ProvidesList() const;
+ inline TagIterator TagList() const;
inline VerFileIterator FileList() const;
bool Downloadable() const;
inline const char *PriorityType() const {return Owner->Priority(S->Priority);}
@@ -249,6 +250,48 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
inline VerIterator() : Iterator<Version, VerIterator>() {}
};
/*}}}*/
+// Tag Iterator /*{{{*/
+class pkgCache::TagIterator
+{
+ Tag *Tg;
+ pkgCache *Owner;
+
+ void _dummy();
+
+ public:
+
+ // Iteration
+ void operator ++(int) {if (Tg != Owner->TagP) Tg = Owner->TagP + Tg->NextTag;};
+ inline void operator ++() {operator ++(0);};
+ inline bool end() const {return Tg == Owner->TagP?true:false;};
+ inline void operator =(const TagIterator &B) {Tg = B.Tg; Owner = B.Owner;};
+
+ // Comparison
+ inline bool operator ==(const TagIterator &B) const {return Tg == B.Tg;};
+ inline bool operator !=(const TagIterator &B) const {return Tg != B.Tg;};
+ int CompareTag(const TagIterator &B) const;
+
+ // Accessors
+ inline Tag *operator ->() {return Tg;};
+ inline Tag const *operator ->() const {return Tg;};
+ inline Tag &operator *() {return *Tg;};
+ inline Tag const &operator *() const {return *Tg;};
+ inline operator Tag *() {return Tg == Owner->TagP?0:Tg;};
+ inline operator Tag const *() const {return Tg == Owner->TagP?0:Tg;};
+ inline pkgCache *Cache() {return Owner;};
+
+ inline const char *Name() const {return Owner->StrP + Tg->Name;};
+ inline unsigned long Index() const {return Tg - Owner->TagP;};
+
+ inline TagIterator() : Tg(0), Owner(0) {};
+ inline TagIterator(pkgCache &Owner,Tag *Trg = 0) : Tg(Trg),
+ Owner(&Owner)
+ {
+ if (Tg == 0)
+ Tg = Owner.TagP;
+ };
+};
+ /*}}}*/
// Description Iterator /*{{{*/
class pkgCache::DescIterator : public Iterator<Description, DescIterator> {
public:
@@ -519,6 +562,8 @@ inline pkgCache::DescIterator pkgCache::VerIterator::DescriptionList() const
{return DescIterator(*Owner,Owner->DescP + S->DescriptionList);}
inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const
{return PrvIterator(*Owner,Owner->ProvideP + S->ProvidesList,S);}
+inline pkgCache::TagIterator pkgCache::VerIterator::TagList() const
+ {return TagIterator(*Owner,Owner->TagP + S->TagList);};
inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const
{return DepIterator(*Owner,Owner->DepP + S->DependsList,S);}
inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 80ca10e37..3c148dd01 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -254,6 +254,8 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
if (ParseProvides(Ver) == false)
return false;
+ if (ParseTag(Ver) == false)
+ return false;
return true;
}
@@ -989,6 +991,46 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
return true;
}
/*}}}*/
+// ListParser::ParseTag - Parse the tag list /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool debListParser::ParseTag(pkgCache::VerIterator &Ver)
+{
+ const char *Start;
+ const char *Stop;
+ if (Section.Find("Tag",Start,Stop) == false)
+ return true;
+
+ while (1) {
+ while (1) {
+ if (Start == Stop)
+ return true;
+ if (Stop[-1] != ' ' && Stop[-1] != '\t')
+ break;
+ --Stop;
+ }
+
+ const char *Begin = Stop - 1;
+ while (Begin != Start && Begin[-1] != ' ' && Begin[-1] != ',')
+ --Begin;
+
+ if (NewTag(Ver, Begin, Stop - Begin) == false)
+ return false;
+
+ while (1) {
+ if (Begin == Start)
+ return true;
+ if (Begin[-1] == ',')
+ break;
+ --Begin;
+ }
+
+ Stop = Begin - 1;
+ }
+
+ return true;
+}
+ /*}}}*/
// ListParser::GrabWord - Matches a word and returns /*{{{*/
// ---------------------------------------------------------------------
/* Looks for a word in a list of words - for ParseStatus */
diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h
index f02252d58..456548501 100644
--- a/apt-pkg/deb/deblistparser.h
+++ b/apt-pkg/deb/deblistparser.h
@@ -56,6 +56,7 @@ class APT_HIDDEN debListParser : public pkgCacheListParser
bool ParseDepends(pkgCache::VerIterator &Ver, pkgTagSection::Key Key,
unsigned int Type);
bool ParseProvides(pkgCache::VerIterator &Ver);
+ bool ParseTag(pkgCache::VerIterator &Ver);
#ifdef APT_PKG_EXPOSE_STRING_VIEW
APT_HIDDEN static bool GrabWord(APT::StringView Word,const WordList *List,unsigned char &Out);
diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc
index 80dd1d1fa..a23bfa2d5 100644
--- a/apt-pkg/pkgcache.cc
+++ b/apt-pkg/pkgcache.cc
@@ -153,6 +153,7 @@ bool pkgCache::ReMap(bool const &Errorchecks)
VerP = (Version *)Map.Data();
DescP = (Description *)Map.Data();
ProvideP = (Provides *)Map.Data();
+ TagP = (Tag *)Map.Data();
DepP = (Dependency *)Map.Data();
DepDataP = (DependencyData *)Map.Data();
StrP = (char *)Map.Data();
diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h
index 787e3995f..3a7afd50f 100644
--- a/apt-pkg/pkgcache.h
+++ b/apt-pkg/pkgcache.h
@@ -123,6 +123,7 @@ class pkgCache /*{{{*/
struct StringItem;
struct VerFile;
struct DescFile;
+ struct Tag;
// Iterators
template<typename Str, typename Itr> class Iterator;
@@ -136,6 +137,7 @@ class pkgCache /*{{{*/
class PkgFileIterator;
class VerFileIterator;
class DescFileIterator;
+ class TagIterator;
class Namespace;
@@ -216,6 +218,7 @@ class pkgCache /*{{{*/
ReleaseFile *RlsFileP;
PackageFile *PkgFileP;
Version *VerP;
+ Tag *TagP;
Description *DescP;
Provides *ProvideP;
Dependency *DepP;
@@ -322,6 +325,7 @@ struct pkgCache::Header
map_number_t ReleaseFileSz;
map_number_t PackageFileSz;
map_number_t VersionSz;
+ map_number_t TagSz;
map_number_t DescriptionSz;
map_number_t DependencySz;
map_number_t DependencyDataSz;
@@ -337,6 +341,7 @@ struct pkgCache::Header
map_id_t GroupCount;
map_id_t PackageCount;
map_id_t VersionCount;
+ map_id_t TagCount;
map_id_t DescriptionCount;
map_id_t DependsCount;
map_id_t DependsDataCount;
@@ -587,6 +592,16 @@ struct pkgCache::VerFile
map_filesize_t Size;
};
/*}}}*/
+// TagFile structure /*{{{*/
+/** \brief associates a tag with something */
+struct pkgCache::Tag
+{
+ /** \brief name of this tag */
+ map_stringitem_t Name;
+ /** \brief next step in the linked list */
+ map_pointer_t NextTag; // Tag
+};
+ /*}}}*/
// DescFile structure /*{{{*/
/** \brief associates a description with a Translation file */
struct pkgCache::DescFile
@@ -658,6 +673,8 @@ struct pkgCache::Version
map_pointer_t ParentPkg; // Package
/** \brief list of pkgCache::Provides */
map_pointer_t ProvidesList; // Provides
+ /** \brief list of pkgCache::Tag */
+ map_pointer_t TagList; // Tag
/** \brief archive size for this version
@@ -813,6 +830,7 @@ class pkgCache::Namespace /*{{{*/
typedef pkgCache::GrpIterator GrpIterator;
typedef pkgCache::PkgIterator PkgIterator;
typedef pkgCache::VerIterator VerIterator;
+ typedef pkgCache::TagIterator TagIterator;
typedef pkgCache::DescIterator DescIterator;
typedef pkgCache::DepIterator DepIterator;
typedef pkgCache::PrvIterator PrvIterator;
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index 5a3b65b3a..a508644fc 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -1274,6 +1274,36 @@ bool pkgCacheGenerator::SelectReleaseFile(const string &File,const string &Site,
return true;
}
/*}}}*/
+// ListParser::NewTag - Create a Tag element /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgCacheListParser::NewTag(pkgCache::VerIterator &Ver,
+ const char *NameStart,
+ unsigned int NameSize)
+{
+ return Owner->NewTag(Ver, NameStart, NameSize);
+}
+bool pkgCacheGenerator::NewTag(pkgCache::VerIterator &Ver,
+ const char *NameStart,
+ unsigned int NameSize)
+{
+ // Get a structure
+ unsigned long Tagg = AllocateInMap(sizeof(pkgCache::Tag));
+ if (Tagg == 0)
+ return false;
+ Cache.HeaderP->TagCount++;
+
+ // Fill it in
+ pkgCache::TagIterator Tg(Cache,Cache.TagP + Tagg);
+ Tg->Name = WriteStringInMap(NameStart,NameSize);
+ if (Tg->Name == 0)
+ return false;
+ Tg->NextTag = Ver->TagList;
+ Ver->TagList = Tg.Index();
+
+ return true;
+}
+ /*}}}*/
// CacheGenerator::SelectFile - Select the current file being parsed /*{{{*/
// ---------------------------------------------------------------------
/* This is used to select which file is to be associated with all newly
diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h
index e11e97e09..b42912303 100644
--- a/apt-pkg/pkgcachegen.h
+++ b/apt-pkg/pkgcachegen.h
@@ -127,6 +127,7 @@ class APT_HIDDEN pkgCacheGenerator /*{{{*/
uint8_t const Type, map_pointer_t* &OldDepLast);
bool NewProvides(pkgCache::VerIterator &Ver, pkgCache::PkgIterator &Pkg,
map_stringitem_t const ProvidesVersion, uint8_t const Flags);
+ bool NewTag(pkgCache::VerIterator &Ver,const char *NameStart,unsigned int NameSize);
public:
@@ -208,6 +209,7 @@ class APT_HIDDEN pkgCacheListParser
uint8_t const Flags);
bool NewProvidesAllArch(pkgCache::VerIterator &Ver, APT::StringView Package,
APT::StringView Version, uint8_t const Flags);
+ bool NewTag(pkgCache::VerIterator &Ver,const char *NameStart,unsigned int NameSize);
#endif
public: