apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

pkgcachegen.h
Go to the documentation of this file.
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4 
5  Package Cache Generator - Generator for the cache structure.
6 
7  This builds the cache structure from the abstract package list parser.
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
15 
16  ##################################################################### */
17  /*}}}*/
18 #ifndef PKGLIB_PKGCACHEGEN_H
19 #define PKGLIB_PKGCACHEGEN_H
20 
21 #include <apt-pkg/macros.h>
22 #include <apt-pkg/mmap.h>
23 #include <apt-pkg/pkgcache.h>
24 
25 #include <string>
26 #include <vector>
27 #if __cplusplus >= 201103L
28 #include <unordered_set>
29 #endif
30 #include <apt-pkg/string_view.h>
31 
32 #ifdef APT_COMPILING_APT
33 #include <xxhash.h>
34 #endif
35 
36 class FileFd;
37 class pkgSourceList;
38 class OpProgress;
39 class pkgIndexFile;
40 class pkgCacheListParser;
41 
43 {
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 uint32_t AllocateInMap(const unsigned long &size);
48  template<typename T> map_pointer<T> AllocateInMap() {
49  return map_pointer<T>{AllocateInMap(sizeof(T))};
50  }
51 
52  // Dirty hack for public users that do not use C++11 yet
53 #if __cplusplus >= 201103L && defined(APT_COMPILING_APT)
54  struct string_pointer {
55  const char *data_;
56  size_t size;
57  pkgCacheGenerator *generator;
58  map_stringitem_t item;
59 
60  const char *data() const {
61  return data_ != nullptr ? data_ : static_cast<char*>(generator->Map.Data()) + item;
62  }
63 
64  bool operator ==(string_pointer const &other) const {
65  return size == other.size && memcmp(data(), other.data(), size) == 0;
66  }
67  };
68  struct hash {
69  uint32_t operator()(string_pointer const &that) const {
70  return XXH3_64bits(that.data(), that.size) & 0xFFFFFFFF;
71  }
72  };
73 
74  std::unordered_set<string_pointer, hash> strMixed;
75  std::unordered_set<string_pointer, hash> strVersions;
76  std::unordered_set<string_pointer, hash> strSections;
77 #endif
78 
79  friend class pkgCacheListParser;
81 
82  public:
83 
84  template<typename Iter> class Dynamic {
85  public:
86  static std::vector<Iter*> toReMap;
87  explicit Dynamic(Iter &I) {
88  toReMap.push_back(&I);
89  }
90 
92  toReMap.pop_back();
93  }
94 
95 #if __cplusplus >= 201103L
96  Dynamic(const Dynamic&) = delete;
97  void operator=(const Dynamic&) = delete;
98 #endif
99  };
100 
101  protected:
102 
106 
107  std::string RlsFileName;
109  std::string PkgFileName;
111 
112  bool NewGroup(pkgCache::GrpIterator &Grp, APT::StringView Name);
113  bool NewPackage(pkgCache::PkgIterator &Pkg, APT::StringView Name, APT::StringView Arch);
115  map_pointer<pkgCache::Package> const ParentPkg, uint32_t Hash,
116  map_pointer<pkgCache::Version> const Next);
117  map_pointer<pkgCache::Description> NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang, APT::StringView md5sum,map_stringitem_t const idxmd5str);
118  bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
119  bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
120  bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
121  map_stringitem_t const Version, uint8_t const Op,
122  uint8_t const Type, map_pointer<pkgCache::Dependency>* &OldDepLast);
123  bool NewProvides(pkgCache::VerIterator &Ver, pkgCache::PkgIterator &Pkg,
124  map_stringitem_t const ProvidesVersion, uint8_t const Flags);
125 
126  public:
127 
128  enum StringType { MIXED, VERSIONNUMBER, SECTION };
129  map_stringitem_t StoreString(StringType const type, const char * S, unsigned int const Size);
130 
131  inline map_stringitem_t StoreString(enum StringType const type, APT::StringView S) {return StoreString(type, S.data(),S.length());};
132 
133  void DropProgress() {Progress = 0;};
134  bool SelectFile(const std::string &File,pkgIndexFile const &Index, std::string const &Architecture, std::string const &Component, unsigned long Flags = 0);
135  bool SelectReleaseFile(const std::string &File, const std::string &Site, unsigned long Flags = 0);
136  bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
137  inline pkgCache &GetCache() {return Cache;};
139  {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
141  {return pkgCache::RlsFileIterator(Cache,CurrentRlsFile);};
142 
143  APT_PUBLIC static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
144  MMap **OutMap = 0,bool AllowMem = false);
145  APT_HIDDEN static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
146  MMap **OutMap,pkgCache **OutCache, bool AllowMem = false);
147  APT_PUBLIC static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);
148 
149  void ReMap(void const * const oldMap, void * const newMap, size_t oldSize);
150  bool Start();
151 
152  pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
153  virtual ~~pkgCacheGenerator();
154 
155  private:
156  void * const d;
157  APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName);
158  APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg);
159  APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg,
160  APT::StringView const &Version, pkgCache::VerIterator* &OutVer);
161 
162  APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P,
164  APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D);
165 
166  APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver,
167  std::string const &lang, APT::StringView CurMd5, map_stringitem_t &md5idx);
168 };
169  /*}}}*/
170 // This is the abstract package list parser class. /*{{{*/
172 {
174  friend class pkgCacheGenerator;
175 
176  // Some cache items
179 
180  void * const d;
181 
182  protected:
183  inline bool NewGroup(pkgCache::GrpIterator &Grp, APT::StringView Name) { return Owner->NewGroup(Grp, Name); }
184  inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);};
187 
188  inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
190  APT::StringView Version,uint8_t const Op,
191  uint8_t const Type);
193  APT::StringView PkgArch, APT::StringView Version,
194  uint8_t const Flags);
195  bool NewProvidesAllArch(pkgCache::VerIterator &Ver, APT::StringView Package,
196  APT::StringView Version, uint8_t const Flags);
197  public:
198 
199  // These all operate against the current section
200  virtual std::string Package() = 0;
201  virtual bool ArchitectureAll() = 0;
203  virtual APT::StringView Version() = 0;
204  virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
205  virtual std::vector<std::string> AvailableDescriptionLanguages() = 0;
207  virtual uint32_t VersionHash() = 0;
208  /** compare currently parsed version with given version
209  *
210  * \param Hash of the currently parsed version
211  * \param Ver to compare with
212  */
213  virtual bool SameVersion(uint32_t Hash, pkgCache::VerIterator const &Ver);
215  pkgCache::VerIterator &Ver) = 0;
216  virtual map_filesize_t Offset() = 0;
217  virtual map_filesize_t Size() = 0;
218 
219  virtual bool Step() = 0;
220 
221  virtual bool CollectFileProvides(pkgCache &/*Cache*/,
222  pkgCache::VerIterator &/*Ver*/) {return true;};
223 
225  virtual ~~pkgCacheListParser();
226 };
227  /*}}}*/
228 
229 #endif
static bool std::string const metaIndex const *const pkgAcqMetaClearSig *const pkgAcquire::Item *const I
static bool operator==(LineBuffer const &buf, APT::StringView const exp) noexcept
Definition: gpgv.cc:104
Simple subset of std::string_view from C++17.
Definition: string_view.h:27
constexpr size_t length() const
Definition: string_view.h:138
constexpr const char * data() const
Definition: string_view.h:133
constexpr size_t size() const
Definition: string_view.h:137
Definition: fileutl.h:39
Definition: mmap.h:41
void * Data()
Definition: mmap.h:63
static std::vector< Iter * > toReMap
Definition: pkgcachegen.h:86
std::string PkgFileName
Definition: pkgcachegen.h:109
pkgCache::PackageFile * CurrentFile
Definition: pkgcachegen.h:110
APT_HIDDEN map_stringitem_t WriteStringInMap(APT::StringView String)
Definition: pkgcachegen.h:44
pkgCacheListParser ListParser
Definition: pkgcachegen.h:80
friend class pkgCacheListParser
Definition: pkgcachegen.h:79
map_stringitem_t StoreString(StringType const type, const char *S, unsigned int const Size)
pkgCache::PkgFileIterator GetCurFile()
Definition: pkgcachegen.h:138
map_stringitem_t StoreString(enum StringType const type, APT::StringView S)
Definition: pkgcachegen.h:131
bool NewGroup(pkgCache::GrpIterator &Grp, APT::StringView Name)
Definition: pkgcachegen.cc:547
map_pointer< T > AllocateInMap()
Definition: pkgcachegen.h:48
OpProgress * Progress
Definition: pkgcachegen.h:105
bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, map_stringitem_t const Version, uint8_t const Op, uint8_t const Type, map_pointer< pkgCache::Dependency > *&OldDepLast)
Definition: pkgcachegen.cc:974
pkgCache & GetCache()
Definition: pkgcachegen.h:137
pkgCache::RlsFileIterator GetCurRlsFile()
Definition: pkgcachegen.h:140
pkgCache::ReleaseFile * CurrentRlsFile
Definition: pkgcachegen.h:108
bool NewProvides(pkgCache::VerIterator &Ver, pkgCache::PkgIterator &Pkg, map_stringitem_t const ProvidesVersion, uint8_t const Flags)
DynamicMMap & Map
Definition: pkgcachegen.h:103
void *const d
Definition: pkgcachegen.h:156
std::string RlsFileName
Definition: pkgcachegen.h:107
virtual bool ArchitectureAll()=0
virtual bool UsePackage(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver)=0
virtual bool CollectFileProvides(pkgCache &, pkgCache::VerIterator &)
Definition: pkgcachegen.h:221
virtual map_filesize_t Offset()=0
map_stringitem_t WriteString(const char *S, unsigned int Size)
Definition: pkgcachegen.h:188
virtual std::string Package()=0
map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, APT::StringView S)
Definition: pkgcachegen.h:185
virtual std::vector< std::string > AvailableDescriptionLanguages()=0
virtual APT::StringView Description_md5()=0
virtual uint32_t VersionHash()=0
map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S, unsigned int Size)
Definition: pkgcachegen.h:184
pkgCacheGenerator * Owner
Definition: pkgcachegen.h:173
bool NewGroup(pkgCache::GrpIterator &Grp, APT::StringView Name)
Definition: pkgcachegen.h:183
virtual map_filesize_t Size()=0
virtual bool Step()=0
virtual APT::StringView Version()=0
map_stringitem_t WriteString(APT::StringView S)
Definition: pkgcachegen.h:186
virtual bool NewVersion(pkgCache::VerIterator &Ver)=0
virtual APT::StringView Architecture()=0
pkgCache::VerIterator OldDepVer
Definition: pkgcachegen.h:177
map_pointer< pkgCache::Dependency > * OldDepLast
Definition: pkgcachegen.h:178
#define APT_PUBLIC
Definition: macros.h:77
#define APT_HIDDEN
Definition: macros.h:78
pkgCache - Structure definitions for the cache file
uint64_t map_filesize_t
Definition: pkgcache.h:89
pkgCacheGenerator::Dynamic< T > Dynamic
Definition: pkgcachegen.cc:42
stores information about the files used to generate the cache
Definition: pkgcache.h:552
stores information about the release files used to generate the cache
Definition: pkgcache.h:508