]>
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> |
78a5476f | 29 | #include <map> |
a9fe5928 | 30 | |
453b82a3 | 31 | class FileFd; |
b35d2f5f AL |
32 | class pkgSourceList; |
33 | class OpProgress; | |
b2e465d6 | 34 | class pkgIndexFile; |
578bfd0a | 35 | |
dce45dbe | 36 | class APT_HIDDEN pkgCacheGenerator /*{{{*/ |
578bfd0a | 37 | { |
f9eec0e7 | 38 | private: |
4ad8619b DK |
39 | APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; |
40 | APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String); | |
41 | APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len); | |
42 | APT_HIDDEN map_pointer_t AllocateInMap(const unsigned long &size); | |
7e58ab0c | 43 | |
78a5476f DK |
44 | std::map<std::string,map_stringitem_t> strMixed; |
45 | std::map<std::string,map_stringitem_t> strSections; | |
46 | std::map<std::string,map_stringitem_t> strPkgNames; | |
47 | std::map<std::string,map_stringitem_t> strVersions; | |
48 | ||
578bfd0a AL |
49 | public: |
50 | ||
51 | class ListParser; | |
b2e465d6 | 52 | friend class ListParser; |
a9fe5928 DK |
53 | |
54 | template<typename Iter> class Dynamic { | |
a9fe5928 | 55 | public: |
7635093c DK |
56 | static std::vector<Iter*> toReMap; |
57 | Dynamic(Iter &I) { | |
58 | toReMap.push_back(&I); | |
a9fe5928 DK |
59 | } |
60 | ||
61 | ~Dynamic() { | |
7635093c | 62 | toReMap.pop_back(); |
a9fe5928 DK |
63 | } |
64 | }; | |
65 | ||
578bfd0a | 66 | protected: |
a9fe5928 | 67 | |
578bfd0a AL |
68 | DynamicMMap ⤅ |
69 | pkgCache Cache; | |
ddc1d8d0 | 70 | OpProgress *Progress; |
b07aeb1a DK |
71 | |
72 | std::string RlsFileName; | |
73 | pkgCache::ReleaseFile *CurrentRlsFile; | |
8f3ba4e8 | 74 | std::string PkgFileName; |
578bfd0a | 75 | pkgCache::PackageFile *CurrentFile; |
45415543 AL |
76 | |
77 | // Flag file dependencies | |
78 | bool FoundFileDeps; | |
578bfd0a | 79 | |
8f3ba4e8 DK |
80 | bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name); |
81 | bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch); | |
f55a958f | 82 | bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); |
a52f938b | 83 | bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); |
25396fb0 | 84 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
8f3ba4e8 | 85 | std::string const &Version, unsigned int const &Op, |
4ad8619b | 86 | unsigned int const &Type, map_pointer_t* &OldDepLast); |
9c44383f | 87 | bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, |
4ad8619b DK |
88 | map_pointer_t const Version, unsigned int const &Op, |
89 | unsigned int const &Type, map_pointer_t* &OldDepLast); | |
90 | map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,map_pointer_t const Next) APT_DEPRECATED | |
885594fc | 91 | { return NewVersion(Ver, VerStr, 0, 0, Next); } |
4ad8619b DK |
92 | map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr, |
93 | map_pointer_t const ParentPkg, unsigned short const Hash, | |
94 | map_pointer_t const Next); | |
95 | map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_stringitem_t const idxmd5str); | |
578bfd0a | 96 | |
b2e465d6 AL |
97 | public: |
98 | ||
30b45652 DK |
99 | enum StringType { MIXED, PKGNAME, VERSIONNUMBER, SECTION }; |
100 | map_stringitem_t StoreString(StringType const type, const char * S, unsigned int const Size); | |
78a5476f | 101 | inline map_stringitem_t StoreString(enum StringType const type, const std::string &S) {return StoreString(type, S.c_str(),S.length());}; |
813c8eea | 102 | |
ddc1d8d0 | 103 | void DropProgress() {Progress = 0;}; |
e185d8b3 | 104 | bool SelectFile(const std::string &File,pkgIndexFile const &Index, std::string const &Architecture, std::string const &Component, unsigned long Flags = 0); |
b07aeb1a | 105 | bool SelectReleaseFile(const std::string &File, const std::string &Site, unsigned long Flags = 0); |
ddc1d8d0 | 106 | bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0); |
ad00ae81 | 107 | inline pkgCache &GetCache() {return Cache;}; |
b0b4efb9 AL |
108 | inline pkgCache::PkgFileIterator GetCurFile() |
109 | {return pkgCache::PkgFileIterator(Cache,CurrentFile);}; | |
b07aeb1a DK |
110 | inline pkgCache::RlsFileIterator GetCurRlsFile() |
111 | {return pkgCache::RlsFileIterator(Cache,CurrentRlsFile);}; | |
45415543 AL |
112 | |
113 | bool HasFileDeps() {return FoundFileDeps;}; | |
114 | bool MergeFileProvides(ListParser &List); | |
a02db58f | 115 | bool FinishCache(OpProgress *Progress) APT_DEPRECATED APT_CONST; |
2e5f4e45 | 116 | |
dce45dbe | 117 | APT_PUBLIC static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, |
2e5f4e45 | 118 | MMap **OutMap = 0,bool AllowMem = false); |
dce45dbe DK |
119 | APT_PUBLIC static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); |
120 | APT_PUBLIC static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0); | |
25396fb0 | 121 | |
a9fe5928 DK |
122 | void ReMap(void const * const oldMap, void const * const newMap); |
123 | ||
b2e465d6 | 124 | pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress); |
c8a4ce6c | 125 | virtual ~pkgCacheGenerator(); |
99a2ea5a DK |
126 | |
127 | private: | |
c8a4ce6c | 128 | void *d; |
ce62f1de DK |
129 | APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName); |
130 | APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); | |
131 | APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, | |
99a2ea5a | 132 | std::string const &Version, pkgCache::VerIterator* &OutVer); |
5a8e963b | 133 | |
ce62f1de | 134 | APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, |
5a8e963b | 135 | pkgCache::VerIterator &V); |
ce62f1de | 136 | APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D); |
ffe3c68e DK |
137 | |
138 | APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver, | |
4ad8619b | 139 | std::string const &lang, MD5SumValue const &CurMd5, map_stringitem_t &md5idx); |
578bfd0a | 140 | }; |
92fcbfc1 DK |
141 | /*}}}*/ |
142 | // This is the abstract package list parser class. /*{{{*/ | |
dce45dbe | 143 | class APT_HIDDEN pkgCacheGenerator::ListParser |
f55ece0e AL |
144 | { |
145 | pkgCacheGenerator *Owner; | |
b2e465d6 | 146 | friend class pkgCacheGenerator; |
f55ece0e | 147 | |
f9eec0e7 AL |
148 | // Some cache items |
149 | pkgCache::VerIterator OldDepVer; | |
4ad8619b | 150 | map_pointer_t *OldDepLast; |
45415543 AL |
151 | |
152 | // Flag file dependencies | |
153 | bool FoundFileDeps; | |
c8a4ce6c DK |
154 | |
155 | void *d; | |
156 | ||
f55ece0e | 157 | protected: |
813c8eea | 158 | |
78a5476f DK |
159 | inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, std::string const &S) {return Owner->StoreString(type, S);}; |
160 | inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);}; | |
161 | ||
4ad8619b DK |
162 | inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);}; |
163 | inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; | |
8f3ba4e8 DK |
164 | bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch, |
165 | const std::string &Version,unsigned int Op, | |
f55ece0e | 166 | unsigned int Type); |
8f3ba4e8 DK |
167 | bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName, |
168 | const std::string &PkgArch, const std::string &Version); | |
f55ece0e AL |
169 | |
170 | public: | |
171 | ||
172 | // These all operate against the current section | |
8f3ba4e8 DK |
173 | virtual std::string Package() = 0; |
174 | virtual std::string Architecture() = 0; | |
857e9c13 | 175 | virtual bool ArchitectureAll() = 0; |
8f3ba4e8 | 176 | virtual std::string Version() = 0; |
32b9a14c | 177 | virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; |
ffe3c68e DK |
178 | virtual std::string Description(std::string const &lang) = 0; |
179 | virtual std::vector<std::string> AvailableDescriptionLanguages() = 0; | |
a52f938b | 180 | virtual MD5SumValue Description_md5() = 0; |
204fbdcc | 181 | virtual unsigned short VersionHash() = 0; |
68134bda DK |
182 | /** compare currently parsed version with given version |
183 | * | |
184 | * \param Hash of the currently parsed version | |
185 | * \param Ver to compare with | |
186 | */ | |
c8a4ce6c | 187 | virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver); |
32b9a14c DK |
188 | virtual bool UsePackage(pkgCache::PkgIterator &Pkg, |
189 | pkgCache::VerIterator &Ver) = 0; | |
4ad8619b DK |
190 | virtual map_filesize_t Offset() = 0; |
191 | virtual map_filesize_t Size() = 0; | |
f55ece0e AL |
192 | |
193 | virtual bool Step() = 0; | |
194 | ||
45415543 | 195 | inline bool HasFileDeps() {return FoundFileDeps;}; |
65512241 DK |
196 | virtual bool CollectFileProvides(pkgCache &/*Cache*/, |
197 | pkgCache::VerIterator &/*Ver*/) {return true;}; | |
45415543 | 198 | |
c8a4ce6c DK |
199 | ListParser(); |
200 | virtual ~ListParser(); | |
f55ece0e | 201 | }; |
92fcbfc1 | 202 | /*}}}*/ |
2e5f4e45 | 203 | |
b2e465d6 AL |
204 | bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, |
205 | MMap **OutMap = 0,bool AllowMem = false); | |
206 | bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap); | |
207 | ||
578bfd0a | 208 | #endif |