pkgcachegen.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcachegen.h,v 1.19 2002/07/08 03:13:30 jgg Exp $
  4. /* ######################################################################
  5. Package Cache Generator - Generator for the cache structure.
  6. This builds the cache structure from the abstract package list parser.
  7. Each archive source has it's own list parser that is instantiated by
  8. the caller to provide data for the generator.
  9. Parts of the cache are created by this generator class while other
  10. parts are created by the list parser. The list parser is responsible
  11. for creating version, depends and provides structures, and some of
  12. their contents
  13. ##################################################################### */
  14. /*}}}*/
  15. #ifndef PKGLIB_PKGCACHEGEN_H
  16. #define PKGLIB_PKGCACHEGEN_H
  17. #include <apt-pkg/md5.h>
  18. #include <apt-pkg/mmap.h>
  19. #include <apt-pkg/pkgcache.h>
  20. #include <apt-pkg/cacheiterators.h>
  21. #include <apt-pkg/macros.h>
  22. #include <vector>
  23. #include <string>
  24. class FileFd;
  25. class pkgSourceList;
  26. class OpProgress;
  27. class pkgIndexFile;
  28. class pkgCacheGenerator /*{{{*/
  29. {
  30. private:
  31. pkgCache::StringItem *UniqHash[26];
  32. APT_HIDDEN map_ptrloc WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); };
  33. APT_HIDDEN map_ptrloc WriteStringInMap(const char *String);
  34. APT_HIDDEN map_ptrloc WriteStringInMap(const char *String, const unsigned long &Len);
  35. APT_HIDDEN map_ptrloc AllocateInMap(const unsigned long &size);
  36. public:
  37. class ListParser;
  38. friend class ListParser;
  39. template<typename Iter> class Dynamic {
  40. public:
  41. static std::vector<Iter*> toReMap;
  42. Dynamic(Iter &I) {
  43. toReMap.push_back(&I);
  44. }
  45. ~Dynamic() {
  46. toReMap.pop_back();
  47. }
  48. };
  49. protected:
  50. DynamicMMap &Map;
  51. pkgCache Cache;
  52. OpProgress *Progress;
  53. std::string PkgFileName;
  54. pkgCache::PackageFile *CurrentFile;
  55. // Flag file dependencies
  56. bool FoundFileDeps;
  57. bool NewGroup(pkgCache::GrpIterator &Grp,const std::string &Name);
  58. bool NewPackage(pkgCache::PkgIterator &Pkg,const std::string &Name, const std::string &Arch);
  59. bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
  60. bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
  61. bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
  62. std::string const &Version, unsigned int const &Op,
  63. unsigned int const &Type, map_ptrloc* &OldDepLast);
  64. bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver,
  65. map_ptrloc const Version, unsigned int const &Op,
  66. unsigned int const &Type, map_ptrloc* &OldDepLast);
  67. unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,unsigned long Next) APT_DEPRECATED
  68. { return NewVersion(Ver, VerStr, 0, 0, Next); }
  69. unsigned long NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,
  70. map_ptrloc const ParentPkg, unsigned long const Hash,
  71. unsigned long Next);
  72. map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_ptrloc Next);
  73. public:
  74. unsigned long WriteUniqString(const char *S,unsigned int Size);
  75. inline unsigned long WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());};
  76. void DropProgress() {Progress = 0;};
  77. bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index,
  78. unsigned long Flags = 0);
  79. bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
  80. inline pkgCache &GetCache() {return Cache;};
  81. inline pkgCache::PkgFileIterator GetCurFile()
  82. {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
  83. bool HasFileDeps() {return FoundFileDeps;};
  84. bool MergeFileProvides(ListParser &List);
  85. bool FinishCache(OpProgress *Progress) APT_DEPRECATED APT_CONST;
  86. static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress,
  87. MMap **OutMap = 0,bool AllowMem = false);
  88. static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap);
  89. static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0);
  90. void ReMap(void const * const oldMap, void const * const newMap);
  91. pkgCacheGenerator(DynamicMMap *Map,OpProgress *Progress);
  92. ~pkgCacheGenerator();
  93. private:
  94. APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName);
  95. APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg);
  96. APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg,
  97. std::string const &Version, pkgCache::VerIterator* &OutVer);
  98. APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P,
  99. pkgCache::VerIterator &V);
  100. APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D);
  101. APT_HIDDEN bool AddNewDescription(ListParser &List, pkgCache::VerIterator &Ver,
  102. std::string const &lang, MD5SumValue const &CurMd5, map_ptrloc &md5idx);
  103. };
  104. /*}}}*/
  105. // This is the abstract package list parser class. /*{{{*/
  106. class pkgCacheGenerator::ListParser
  107. {
  108. pkgCacheGenerator *Owner;
  109. friend class pkgCacheGenerator;
  110. // Some cache items
  111. pkgCache::VerIterator OldDepVer;
  112. map_ptrloc *OldDepLast;
  113. // Flag file dependencies
  114. bool FoundFileDeps;
  115. protected:
  116. inline unsigned long WriteUniqString(std::string S) {return Owner->WriteUniqString(S);};
  117. inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
  118. inline unsigned long WriteString(const std::string &S) {return Owner->WriteStringInMap(S);};
  119. inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);};
  120. bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch,
  121. const std::string &Version,unsigned int Op,
  122. unsigned int Type);
  123. bool NewProvides(pkgCache::VerIterator &Ver,const std::string &PkgName,
  124. const std::string &PkgArch, const std::string &Version);
  125. public:
  126. // These all operate against the current section
  127. virtual std::string Package() = 0;
  128. virtual std::string Architecture() = 0;
  129. virtual bool ArchitectureAll() = 0;
  130. virtual std::string Version() = 0;
  131. virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
  132. virtual std::string Description(std::string const &lang) = 0;
  133. virtual std::vector<std::string> AvailableDescriptionLanguages() = 0;
  134. virtual MD5SumValue Description_md5() = 0;
  135. virtual unsigned short VersionHash() = 0;
  136. /** compare currently parsed version with given version
  137. *
  138. * \param Hash of the currently parsed version
  139. * \param Ver to compare with
  140. */
  141. #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
  142. virtual
  143. #endif
  144. APT_PURE bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
  145. virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
  146. pkgCache::VerIterator &Ver) = 0;
  147. virtual unsigned long Offset() = 0;
  148. virtual unsigned long Size() = 0;
  149. virtual bool Step() = 0;
  150. inline bool HasFileDeps() {return FoundFileDeps;};
  151. virtual bool CollectFileProvides(pkgCache &/*Cache*/,
  152. pkgCache::VerIterator &/*Ver*/) {return true;};
  153. ListParser() : FoundFileDeps(false) {};
  154. virtual ~ListParser() {};
  155. };
  156. /*}}}*/
  157. bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
  158. MMap **OutMap = 0,bool AllowMem = false);
  159. bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutMap);
  160. #endif