]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgcachegen.h
tests: try to support spaces in TMPDIR
[apt.git] / apt-pkg / pkgcachegen.h
CommitLineData
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 31class FileFd;
b35d2f5f
AL
32class pkgSourceList;
33class OpProgress;
b2e465d6 34class pkgIndexFile;
c9443c01 35class pkgCacheListParser;
578bfd0a 36
dce45dbe 37class APT_HIDDEN pkgCacheGenerator /*{{{*/
578bfd0a 38{
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
c9443c01
DK
49 friend class pkgCacheListParser;
50 typedef pkgCacheListParser ListParser;
51
578bfd0a 52 public:
a9fe5928
DK
53
54 template<typename Iter> class Dynamic {
a9fe5928 55 public:
7635093c 56 static std::vector<Iter*> toReMap;
e8afd168 57 explicit Dynamic(Iter &I) {
7635093c 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 &Map;
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 76
8f3ba4e8
DK
77 bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name);
78 bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch);
f55a958f 79 bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
a52f938b 80 bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
9c44383f 81 bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
8c7af4d4
DK
82 map_pointer_t const Version, uint8_t const Op,
83 uint8_t const Type, map_pointer_t* &OldDepLast);
4ad8619b 84 map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,map_pointer_t const Next) APT_DEPRECATED
885594fc 85 { return NewVersion(Ver, VerStr, 0, 0, Next); }
4ad8619b
DK
86 map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,
87 map_pointer_t const ParentPkg, unsigned short const Hash,
88 map_pointer_t const Next);
89 map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_stringitem_t const idxmd5str);
ecc138f8
DK
90 bool NewProvides(pkgCache::VerIterator &Ver, pkgCache::PkgIterator &Pkg,
91 map_stringitem_t const ProvidesVersion, uint8_t const Flags);
578bfd0a 92
b2e465d6
AL
93 public:
94
30b45652
DK
95 enum StringType { MIXED, PKGNAME, VERSIONNUMBER, SECTION };
96 map_stringitem_t StoreString(StringType const type, const char * S, unsigned int const Size);
78a5476f 97 inline map_stringitem_t StoreString(enum StringType const type, const std::string &S) {return StoreString(type, S.c_str(),S.length());};
813c8eea 98
ddc1d8d0 99 void DropProgress() {Progress = 0;};
e185d8b3 100 bool SelectFile(const std::string &File,pkgIndexFile const &Index, std::string const &Architecture, std::string const &Component, unsigned long Flags = 0);
b07aeb1a 101 bool SelectReleaseFile(const std::string &File, const std::string &Site, unsigned long Flags = 0);
ddc1d8d0 102 bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
ad00ae81 103 inline pkgCache &GetCache() {return Cache;};
1d3eea5c 104 inline pkgCache::PkgFileIterator GetCurFile()
b0b4efb9 105 {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
1d3eea5c 106 inline pkgCache::RlsFileIterator GetCurRlsFile()
b07aeb1a 107 {return pkgCache::RlsFileIterator(Cache,CurrentRlsFile);};
45415543 108
dce45dbe 109 APT_PUBLIC static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
2e5f4e45 110 MMap **OutMap = 0,bool AllowMem = false);
dce45dbe 111 APT_PUBLIC static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);
25396fb0 112
a9fe5928
DK
113 void ReMap(void const * const oldMap, void const * const newMap);
114
b2e465d6 115 pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
c8a4ce6c 116 virtual ~pkgCacheGenerator();
99a2ea5a
DK
117
118 private:
6c55f07a 119 void * const d;
ce62f1de
DK
120 APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName);
121 APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg);
122 APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg,
99a2ea5a 123 std::string const &Version, pkgCache::VerIterator* &OutVer);
5a8e963b 124
ce62f1de 125 APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P,
5a8e963b 126 pkgCache::VerIterator &V);
ce62f1de 127 APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D);
ffe3c68e
DK
128
129 APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver,
4ad8619b 130 std::string const &lang, MD5SumValue const &CurMd5, map_stringitem_t &md5idx);
578bfd0a 131};
92fcbfc1
DK
132 /*}}}*/
133// This is the abstract package list parser class. /*{{{*/
c9443c01 134class APT_HIDDEN pkgCacheListParser
f55ece0e
AL
135{
136 pkgCacheGenerator *Owner;
b2e465d6 137 friend class pkgCacheGenerator;
c9443c01 138
f9eec0e7
AL
139 // Some cache items
140 pkgCache::VerIterator OldDepVer;
4ad8619b 141 map_pointer_t *OldDepLast;
45415543 142
6c55f07a 143 void * const d;
c8a4ce6c 144
f55ece0e 145 protected:
813c8eea 146
78a5476f
DK
147 inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, std::string const &S) {return Owner->StoreString(type, S);};
148 inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);};
149
4ad8619b
DK
150 inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);};
151 inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
8f3ba4e8 152 bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch,
8c7af4d4
DK
153 const std::string &Version,uint8_t const Op,
154 uint8_t const Type);
8f3ba4e8 155 bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName,
8c7af4d4
DK
156 const std::string &PkgArch, const std::string &Version,
157 uint8_t const Flags);
ecc138f8
DK
158 bool NewProvidesAllArch(pkgCache::VerIterator &Ver, std::string const &Package,
159 std::string const &Version, uint8_t const Flags);
f55ece0e
AL
160
161 public:
162
163 // These all operate against the current section
8f3ba4e8
DK
164 virtual std::string Package() = 0;
165 virtual std::string Architecture() = 0;
857e9c13 166 virtual bool ArchitectureAll() = 0;
8f3ba4e8 167 virtual std::string Version() = 0;
32b9a14c 168 virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
ffe3c68e
DK
169 virtual std::string Description(std::string const &lang) = 0;
170 virtual std::vector<std::string> AvailableDescriptionLanguages() = 0;
a52f938b 171 virtual MD5SumValue Description_md5() = 0;
204fbdcc 172 virtual unsigned short VersionHash() = 0;
68134bda
DK
173 /** compare currently parsed version with given version
174 *
175 * \param Hash of the currently parsed version
176 * \param Ver to compare with
177 */
c8a4ce6c 178 virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
32b9a14c
DK
179 virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
180 pkgCache::VerIterator &Ver) = 0;
4ad8619b
DK
181 virtual map_filesize_t Offset() = 0;
182 virtual map_filesize_t Size() = 0;
f55ece0e
AL
183
184 virtual bool Step() = 0;
185
65512241
DK
186 virtual bool CollectFileProvides(pkgCache &/*Cache*/,
187 pkgCache::VerIterator &/*Ver*/) {return true;};
45415543 188
c9443c01
DK
189 pkgCacheListParser();
190 virtual ~pkgCacheListParser();
f55ece0e 191};
92fcbfc1 192 /*}}}*/
2e5f4e45 193
b2e465d6
AL
194bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
195 MMap **OutMap = 0,bool AllowMem = false);
196bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
197
578bfd0a 198#endif