]> git.saurik.com Git - apt.git/blob - apt-pkg/pkgcachegen.h
store Release files data in the Cache
[apt.git] / apt-pkg / pkgcachegen.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: pkgcachegen.h,v 1.19 2002/07/08 03:13:30 jgg Exp $
4 /* ######################################################################
5
6 Package Cache Generator - Generator for the cache structure.
7
8 This builds the cache structure from the abstract package list parser.
9 Each archive source has it's own list parser that is instantiated by
10 the caller to provide data for the generator.
11
12 Parts of the cache are created by this generator class while other
13 parts are created by the list parser. The list parser is responsible
14 for creating version, depends and provides structures, and some of
15 their contents
16
17 ##################################################################### */
18 /*}}}*/
19 #ifndef PKGLIB_PKGCACHEGEN_H
20 #define PKGLIB_PKGCACHEGEN_H
21
22 #include <apt-pkg/md5.h>
23 #include <apt-pkg/mmap.h>
24 #include <apt-pkg/pkgcache.h>
25 #include <apt-pkg/cacheiterators.h>
26 #include <apt-pkg/macros.h>
27
28 #include <vector>
29 #include <string>
30 #include <map>
31
32 class FileFd;
33 class pkgSourceList;
34 class OpProgress;
35 class pkgIndexFile;
36
37 class APT_HIDDEN pkgCacheGenerator /*{{{*/
38 {
39 private:
40 APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); };
41 APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String);
42 APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len);
43 APT_HIDDEN map_pointer_t AllocateInMap(const unsigned long &size);
44
45 std::map<std::string,map_stringitem_t> strMixed;
46 std::map<std::string,map_stringitem_t> strSections;
47 std::map<std::string,map_stringitem_t> strPkgNames;
48 std::map<std::string,map_stringitem_t> strVersions;
49
50 public:
51
52 class ListParser;
53 friend class ListParser;
54
55 template<typename Iter> class Dynamic {
56 public:
57 static std::vector<Iter*> toReMap;
58 Dynamic(Iter &I) {
59 toReMap.push_back(&I);
60 }
61
62 ~Dynamic() {
63 toReMap.pop_back();
64 }
65 };
66
67 protected:
68
69 DynamicMMap &Map;
70 pkgCache Cache;
71 OpProgress *Progress;
72
73 std::string RlsFileName;
74 pkgCache::ReleaseFile *CurrentRlsFile;
75 std::string PkgFileName;
76 pkgCache::PackageFile *CurrentFile;
77
78 // Flag file dependencies
79 bool FoundFileDeps;
80
81 bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name);
82 bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch);
83 bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
84 bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
85 bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
86 std::string const &Version, unsigned int const &Op,
87 unsigned int const &Type, map_pointer_t* &OldDepLast);
88 bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
89 map_pointer_t const Version, unsigned int const &Op,
90 unsigned int const &Type, map_pointer_t* &OldDepLast);
91 map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,map_pointer_t const Next) APT_DEPRECATED
92 { return NewVersion(Ver, VerStr, 0, 0, Next); }
93 map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,
94 map_pointer_t const ParentPkg, unsigned short const Hash,
95 map_pointer_t const Next);
96 map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_stringitem_t const idxmd5str);
97
98 public:
99
100 enum StringType { MIXED, PKGNAME, VERSIONNUMBER, SECTION };
101 map_stringitem_t StoreString(StringType const type, const char * S, unsigned int const Size);
102 inline map_stringitem_t StoreString(enum StringType const type, const std::string &S) {return StoreString(type, S.c_str(),S.length());};
103
104 void DropProgress() {Progress = 0;};
105 bool SelectFile(const std::string &File,pkgIndexFile const &Index, std::string const &Component, unsigned long Flags = 0);
106 bool SelectReleaseFile(const std::string &File, const std::string &Site, unsigned long Flags = 0);
107 bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
108 inline pkgCache &GetCache() {return Cache;};
109 inline pkgCache::PkgFileIterator GetCurFile()
110 {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
111 inline pkgCache::RlsFileIterator GetCurRlsFile()
112 {return pkgCache::RlsFileIterator(Cache,CurrentRlsFile);};
113
114 bool HasFileDeps() {return FoundFileDeps;};
115 bool MergeFileProvides(ListParser &List);
116 bool FinishCache(OpProgress *Progress) APT_DEPRECATED APT_CONST;
117
118 APT_PUBLIC static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
119 MMap **OutMap = 0,bool AllowMem = false);
120 APT_PUBLIC static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);
121 APT_PUBLIC static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0);
122
123 void ReMap(void const * const oldMap, void const * const newMap);
124
125 pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
126 ~pkgCacheGenerator();
127
128 private:
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,
132 std::string const &Version, pkgCache::VerIterator* &OutVer);
133
134 APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P,
135 pkgCache::VerIterator &V);
136 APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D);
137
138 APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver,
139 std::string const &lang, MD5SumValue const &CurMd5, map_stringitem_t &md5idx);
140 };
141 /*}}}*/
142 // This is the abstract package list parser class. /*{{{*/
143 class APT_HIDDEN pkgCacheGenerator::ListParser
144 {
145 pkgCacheGenerator *Owner;
146 friend class pkgCacheGenerator;
147
148 // Some cache items
149 pkgCache::VerIterator OldDepVer;
150 map_pointer_t *OldDepLast;
151
152 // Flag file dependencies
153 bool FoundFileDeps;
154
155 protected:
156
157 inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, std::string const &S) {return Owner->StoreString(type, S);};
158 inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);};
159
160 inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);};
161 inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
162 bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch,
163 const std::string &Version,unsigned int Op,
164 unsigned int Type);
165 bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName,
166 const std::string &PkgArch, const std::string &Version);
167
168 public:
169
170 // These all operate against the current section
171 virtual std::string Package() = 0;
172 virtual std::string Architecture() = 0;
173 virtual bool ArchitectureAll() = 0;
174 virtual std::string Version() = 0;
175 virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
176 virtual std::string Description(std::string const &lang) = 0;
177 virtual std::vector<std::string> AvailableDescriptionLanguages() = 0;
178 virtual MD5SumValue Description_md5() = 0;
179 virtual unsigned short VersionHash() = 0;
180 /** compare currently parsed version with given version
181 *
182 * \param Hash of the currently parsed version
183 * \param Ver to compare with
184 */
185 #if APT_PKG_ABI >= 413
186 virtual
187 #endif
188 APT_PURE bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
189 virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
190 pkgCache::VerIterator &Ver) = 0;
191 virtual map_filesize_t Offset() = 0;
192 virtual map_filesize_t Size() = 0;
193
194 virtual bool Step() = 0;
195
196 inline bool HasFileDeps() {return FoundFileDeps;};
197 virtual bool CollectFileProvides(pkgCache &/*Cache*/,
198 pkgCache::VerIterator &/*Ver*/) {return true;};
199
200 ListParser() : Owner(NULL), OldDepLast(NULL), FoundFileDeps(false) {};
201 virtual ~ListParser() {};
202 };
203 /*}}}*/
204
205 bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
206 MMap **OutMap = 0,bool AllowMem = false);
207 bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
208
209 #endif