]>
Commit | Line | Data |
---|---|---|
578bfd0a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
578bfd0a AL |
3 | /* ###################################################################### |
4 | ||
5 | Package Cache Generator - Generator for the cache structure. | |
6 | ||
7 | This builds the cache structure from the abstract package list parser. | |
6fc33863 AL |
8 | Each archive source has it's own list parser that is instantiated by |
9 | the caller to provide data for the generator. | |
10 | ||
11 | Parts of the cache are created by this generator class while other | |
12 | parts are created by the list parser. The list parser is responsible | |
13 | for creating version, depends and provides structures, and some of | |
14 | their contents | |
578bfd0a AL |
15 | |
16 | ##################################################################### */ | |
17 | /*}}}*/ | |
578bfd0a AL |
18 | #ifndef PKGLIB_PKGCACHEGEN_H |
19 | #define PKGLIB_PKGCACHEGEN_H | |
20 | ||
a52f938b | 21 | #include <apt-pkg/md5.h> |
453b82a3 DK |
22 | #include <apt-pkg/mmap.h> |
23 | #include <apt-pkg/pkgcache.h> | |
24 | #include <apt-pkg/cacheiterators.h> | |
5a8e963b | 25 | #include <apt-pkg/macros.h> |
b35d2f5f | 26 | |
7635093c | 27 | #include <vector> |
453b82a3 | 28 | #include <string> |
2837a718 | 29 | #if __cplusplus >= 201103L |
869700d8 | 30 | #include <unordered_set> |
2837a718 | 31 | #endif |
eff0c22e JAK |
32 | #ifdef APT_PKG_EXPOSE_STRING_VIEW |
33 | #include <apt-pkg/string_view.h> | |
34 | #endif | |
a9fe5928 | 35 | |
453b82a3 | 36 | class FileFd; |
b35d2f5f AL |
37 | class pkgSourceList; |
38 | class OpProgress; | |
b2e465d6 | 39 | class pkgIndexFile; |
c9443c01 | 40 | class pkgCacheListParser; |
578bfd0a | 41 | |
dce45dbe | 42 | class APT_HIDDEN pkgCacheGenerator /*{{{*/ |
578bfd0a | 43 | { |
4ad8619b DK |
44 | APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; |
45 | APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String); | |
46 | APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len); | |
47 | APT_HIDDEN map_pointer_t AllocateInMap(const unsigned long &size); | |
7e58ab0c | 48 | |
2837a718 JAK |
49 | // Dirty hack for public users that do not use C++11 yet |
50 | #if __cplusplus >= 201103L | |
869700d8 JAK |
51 | struct string_pointer { |
52 | const char *data_; | |
53 | size_t size; | |
54 | pkgCacheGenerator *generator; | |
55 | map_stringitem_t item; | |
56 | ||
57 | const char *data() const { | |
58 | return data_ != nullptr ? data_ : static_cast<char*>(generator->Map.Data()) + item; | |
59 | } | |
60 | ||
61 | bool operator ==(string_pointer const &other) const { | |
62 | return size == other.size && memcmp(data(), other.data(), size) == 0; | |
63 | } | |
64 | }; | |
65 | struct hash { | |
66 | uint32_t operator()(string_pointer const &that) const { | |
67 | uint32_t Hash = 5381; | |
68 | const char * const end = that.data() + that.size; | |
69 | for (const char *I = that.data(); I != end; ++I) | |
a0e3c0f5 | 70 | Hash = 33 * Hash + *I; |
869700d8 JAK |
71 | return Hash; |
72 | } | |
73 | }; | |
74 | ||
75 | std::unordered_set<string_pointer, hash> strMixed; | |
76 | std::unordered_set<string_pointer, hash> strPkgNames; | |
77 | std::unordered_set<string_pointer, hash> strVersions; | |
78 | std::unordered_set<string_pointer, hash> strSections; | |
2837a718 | 79 | #endif |
78a5476f | 80 | |
c9443c01 DK |
81 | friend class pkgCacheListParser; |
82 | typedef pkgCacheListParser ListParser; | |
83 | ||
578bfd0a | 84 | public: |
a9fe5928 DK |
85 | |
86 | template<typename Iter> class Dynamic { | |
a9fe5928 | 87 | public: |
7635093c | 88 | static std::vector<Iter*> toReMap; |
e8afd168 | 89 | explicit Dynamic(Iter &I) { |
7635093c | 90 | toReMap.push_back(&I); |
a9fe5928 DK |
91 | } |
92 | ||
93 | ~Dynamic() { | |
7635093c | 94 | toReMap.pop_back(); |
a9fe5928 | 95 | } |
96f66f82 JAK |
96 | |
97 | #if __cplusplus >= 201103L | |
98 | Dynamic(const Dynamic&) = delete; | |
99 | void operator=(const Dynamic&) = delete; | |
100 | #endif | |
a9fe5928 DK |
101 | }; |
102 | ||
578bfd0a | 103 | protected: |
a9fe5928 | 104 | |
578bfd0a AL |
105 | DynamicMMap ⤅ |
106 | pkgCache Cache; | |
ddc1d8d0 | 107 | OpProgress *Progress; |
b07aeb1a DK |
108 | |
109 | std::string RlsFileName; | |
110 | pkgCache::ReleaseFile *CurrentRlsFile; | |
8f3ba4e8 | 111 | std::string PkgFileName; |
578bfd0a | 112 | pkgCache::PackageFile *CurrentFile; |
45415543 | 113 | |
eff0c22e JAK |
114 | #ifdef APT_PKG_EXPOSE_STRING_VIEW |
115 | bool NewGroup(pkgCache::GrpIterator &Grp, APT::StringView Name); | |
116 | bool NewPackage(pkgCache::PkgIterator &Pkg, APT::StringView Name, APT::StringView Arch); | |
117 | #endif | |
f55a958f | 118 | bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); |
a52f938b | 119 | bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); |
9c44383f | 120 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
8c7af4d4 DK |
121 | map_pointer_t const Version, uint8_t const Op, |
122 | uint8_t const Type, map_pointer_t* &OldDepLast); | |
4ad8619b | 123 | map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,map_pointer_t const Next) APT_DEPRECATED |
885594fc | 124 | { return NewVersion(Ver, VerStr, 0, 0, Next); } |
4ad8619b DK |
125 | map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr, |
126 | map_pointer_t const ParentPkg, unsigned short const Hash, | |
127 | map_pointer_t const Next); | |
128 | map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_stringitem_t const idxmd5str); | |
ecc138f8 DK |
129 | bool NewProvides(pkgCache::VerIterator &Ver, pkgCache::PkgIterator &Pkg, |
130 | map_stringitem_t const ProvidesVersion, uint8_t const Flags); | |
578bfd0a | 131 | |
b2e465d6 AL |
132 | public: |
133 | ||
30b45652 DK |
134 | enum StringType { MIXED, PKGNAME, VERSIONNUMBER, SECTION }; |
135 | map_stringitem_t StoreString(StringType const type, const char * S, unsigned int const Size); | |
dd592790 JAK |
136 | |
137 | #ifdef APT_PKG_EXPOSE_STRING_VIEW | |
138 | inline map_stringitem_t StoreString(enum StringType const type, APT::StringView S) {return StoreString(type, S.data(),S.length());}; | |
139 | #endif | |
813c8eea | 140 | |
ddc1d8d0 | 141 | void DropProgress() {Progress = 0;}; |
e185d8b3 | 142 | bool SelectFile(const std::string &File,pkgIndexFile const &Index, std::string const &Architecture, std::string const &Component, unsigned long Flags = 0); |
b07aeb1a | 143 | bool SelectReleaseFile(const std::string &File, const std::string &Site, unsigned long Flags = 0); |
ddc1d8d0 | 144 | bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0); |
ad00ae81 | 145 | inline pkgCache &GetCache() {return Cache;}; |
1d3eea5c | 146 | inline pkgCache::PkgFileIterator GetCurFile() |
b0b4efb9 | 147 | {return pkgCache::PkgFileIterator(Cache,CurrentFile);}; |
1d3eea5c | 148 | inline pkgCache::RlsFileIterator GetCurRlsFile() |
b07aeb1a | 149 | {return pkgCache::RlsFileIterator(Cache,CurrentRlsFile);}; |
45415543 | 150 | |
dce45dbe | 151 | APT_PUBLIC static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, |
2e5f4e45 | 152 | MMap **OutMap = 0,bool AllowMem = false); |
f1616039 JAK |
153 | APT_HIDDEN static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, |
154 | MMap **OutMap,pkgCache **OutCache, bool AllowMem = false); | |
dce45dbe | 155 | APT_PUBLIC static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); |
25396fb0 | 156 | |
19819ac5 | 157 | void ReMap(void const * const oldMap, void const * const newMap, size_t oldSize); |
a9fe5928 | 158 | |
b2e465d6 | 159 | pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress); |
c8a4ce6c | 160 | virtual ~pkgCacheGenerator(); |
99a2ea5a DK |
161 | |
162 | private: | |
6c55f07a | 163 | void * const d; |
ce62f1de DK |
164 | APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName); |
165 | APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); | |
166 | APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, | |
99a2ea5a | 167 | std::string const &Version, pkgCache::VerIterator* &OutVer); |
5a8e963b | 168 | |
ce62f1de | 169 | APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, |
5a8e963b | 170 | pkgCache::VerIterator &V); |
ce62f1de | 171 | APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D); |
ffe3c68e DK |
172 | |
173 | APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver, | |
4ad8619b | 174 | std::string const &lang, MD5SumValue const &CurMd5, map_stringitem_t &md5idx); |
578bfd0a | 175 | }; |
92fcbfc1 DK |
176 | /*}}}*/ |
177 | // This is the abstract package list parser class. /*{{{*/ | |
c9443c01 | 178 | class APT_HIDDEN pkgCacheListParser |
f55ece0e AL |
179 | { |
180 | pkgCacheGenerator *Owner; | |
b2e465d6 | 181 | friend class pkgCacheGenerator; |
c9443c01 | 182 | |
f9eec0e7 AL |
183 | // Some cache items |
184 | pkgCache::VerIterator OldDepVer; | |
4ad8619b | 185 | map_pointer_t *OldDepLast; |
45415543 | 186 | |
6c55f07a | 187 | void * const d; |
c8a4ce6c | 188 | |
f55ece0e | 189 | protected: |
813c8eea | 190 | |
78a5476f | 191 | inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);}; |
dd592790 JAK |
192 | #ifdef APT_PKG_EXPOSE_STRING_VIEW |
193 | inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, APT::StringView S) {return Owner->StoreString(type, S);}; | |
194 | #endif | |
78a5476f | 195 | |
4ad8619b DK |
196 | inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);}; |
197 | inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; | |
eff0c22e JAK |
198 | #ifdef APT_PKG_EXPOSE_STRING_VIEW |
199 | bool NewDepends(pkgCache::VerIterator &Ver,APT::StringView Package, APT::StringView Arch, | |
200 | APT::StringView Version,uint8_t const Op, | |
8c7af4d4 | 201 | uint8_t const Type); |
eff0c22e JAK |
202 | bool NewProvides(pkgCache::VerIterator &Ver,APT::StringView PkgName, |
203 | APT::StringView PkgArch, APT::StringView Version, | |
8c7af4d4 | 204 | uint8_t const Flags); |
eff0c22e JAK |
205 | bool NewProvidesAllArch(pkgCache::VerIterator &Ver, APT::StringView Package, |
206 | APT::StringView Version, uint8_t const Flags); | |
207 | #endif | |
f55ece0e AL |
208 | public: |
209 | ||
210 | // These all operate against the current section | |
8f3ba4e8 DK |
211 | virtual std::string Package() = 0; |
212 | virtual std::string Architecture() = 0; | |
857e9c13 | 213 | virtual bool ArchitectureAll() = 0; |
8f3ba4e8 | 214 | virtual std::string Version() = 0; |
32b9a14c | 215 | virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; |
ffe3c68e DK |
216 | virtual std::string Description(std::string const &lang) = 0; |
217 | virtual std::vector<std::string> AvailableDescriptionLanguages() = 0; | |
a52f938b | 218 | virtual MD5SumValue Description_md5() = 0; |
204fbdcc | 219 | virtual unsigned short VersionHash() = 0; |
68134bda DK |
220 | /** compare currently parsed version with given version |
221 | * | |
222 | * \param Hash of the currently parsed version | |
223 | * \param Ver to compare with | |
224 | */ | |
c8a4ce6c | 225 | virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver); |
32b9a14c DK |
226 | virtual bool UsePackage(pkgCache::PkgIterator &Pkg, |
227 | pkgCache::VerIterator &Ver) = 0; | |
4ad8619b DK |
228 | virtual map_filesize_t Offset() = 0; |
229 | virtual map_filesize_t Size() = 0; | |
f55ece0e AL |
230 | |
231 | virtual bool Step() = 0; | |
232 | ||
65512241 DK |
233 | virtual bool CollectFileProvides(pkgCache &/*Cache*/, |
234 | pkgCache::VerIterator &/*Ver*/) {return true;}; | |
45415543 | 235 | |
c9443c01 DK |
236 | pkgCacheListParser(); |
237 | virtual ~pkgCacheListParser(); | |
f55ece0e | 238 | }; |
92fcbfc1 | 239 | /*}}}*/ |
2e5f4e45 | 240 | |
5dd00edb | 241 | APT_DEPRECATED_MSG("Use pkgCacheGenerator::MakeStatusCache instead") bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, |
b2e465d6 | 242 | MMap **OutMap = 0,bool AllowMem = false); |
5dd00edb | 243 | APT_DEPRECATED_MSG("Use pkgCacheGenerator::MakeOnlyStatusCache instead") bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); |
b2e465d6 | 244 | |
578bfd0a | 245 | #endif |