pkgcache.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /**\file pkgcache.h
  4. \brief pkgCache - Structure definitions for the cache file
  5. The goal of the cache file is two fold:
  6. Firstly to speed loading and processing of the package file array and
  7. secondly to reduce memory consumption of the package file array.
  8. The implementation is aimed at an environment with many primary package
  9. files, for instance someone that has a Package file for their CD-ROM, a
  10. Package file for the latest version of the distribution on the CD-ROM and a
  11. package file for the development version. Always present is the information
  12. contained in the status file which might be considered a separate package
  13. file.
  14. Please understand, this is designed as a <b>Cache file</b> it is not meant to be
  15. used on any system other than the one it was created for. It is not meant to
  16. be authoritative either, i.e. if a system crash or software failure occurs it
  17. must be perfectly acceptable for the cache file to be in an inconsistent
  18. state. Furthermore at any time the cache file may be erased without losing
  19. any information.
  20. Also the structures and storage layout is optimized for use by the APT
  21. and may not be suitable for all purposes. However it should be possible
  22. to extend it with associate cache files that contain other information.
  23. To keep memory use down the cache file only contains often used fields and
  24. fields that are inexpensive to store, the Package file has a full list of
  25. fields. Also the client may assume that all items are perfectly valid and
  26. need not perform checks against their correctness. Removal of information
  27. from the cache is possible, but blanks will be left in the file, and
  28. unused strings will also be present. The recommended implementation is to
  29. simply rebuild the cache each time any of the data files change. It is
  30. possible to add a new package file to the cache without any negative side
  31. effects.
  32. <b>Note on Pointer access</b>
  33. Clients should always use the CacheIterators classes for access to the
  34. cache and the data in it. They also provide a simple STL-like method for
  35. traversing the links of the datastructure.
  36. Every item in every structure is stored as the index to that structure.
  37. What this means is that once the files is mmaped every data access has to
  38. go through a fix up stage to get a real memory pointer. This is done
  39. by taking the index, multiplying it by the type size and then adding
  40. it to the start address of the memory block. This sounds complex, but
  41. in C it is a single array dereference. Because all items are aligned to
  42. their size and indexes are stored as multiples of the size of the structure
  43. the format is immediately portable to all possible architectures - BUT the
  44. generated files are -NOT-.
  45. This scheme allows code like this to be written:
  46. <example>
  47. void *Map = mmap(...);
  48. Package *PkgList = (Package *)Map;
  49. Header *Head = (Header *)Map;
  50. char *Strings = (char *)Map;
  51. cout << (Strings + PkgList[Head->HashTable[0]]->Name) << endl;
  52. </example>
  53. Notice the lack of casting or multiplication. The net result is to return
  54. the name of the first package in the first hash bucket, without error
  55. checks.
  56. The generator uses allocation pools to group similarly sized structures in
  57. large blocks to eliminate any alignment overhead. The generator also
  58. assures that no structures overlap and all indexes are unique. Although
  59. at first glance it may seem like there is the potential for two structures
  60. to exist at the same point the generator never allows this to happen.
  61. (See the discussion of free space pools)
  62. See \ref pkgcachegen.h for more information about generating cache structures. */
  63. /*}}}*/
  64. #ifndef PKGLIB_PKGCACHE_H
  65. #define PKGLIB_PKGCACHE_H
  66. #include <apt-pkg/mmap.h>
  67. #include <apt-pkg/macros.h>
  68. #include <string>
  69. #include <time.h>
  70. #include <stdint.h>
  71. #ifndef APT_8_CLEANER_HEADERS
  72. using std::string;
  73. #endif
  74. // storing file sizes of indexes, which are way below 4 GB for now
  75. typedef uint32_t map_filesize_t;
  76. // each package/group/dependency gets an id
  77. typedef uint32_t map_id_t;
  78. // some files get an id, too, but in far less absolute numbers
  79. typedef uint16_t map_fileid_t;
  80. // relative pointer from cache start
  81. typedef uint32_t map_pointer_t;
  82. // same as the previous, but documented to be to a string item
  83. typedef map_pointer_t map_stringitem_t;
  84. class pkgVersioningSystem;
  85. class pkgCache /*{{{*/
  86. {
  87. public:
  88. // Cache element predeclarations
  89. struct Header;
  90. struct Group;
  91. struct Package;
  92. struct PackageFile;
  93. struct Version;
  94. struct Description;
  95. struct Provides;
  96. struct Dependency;
  97. struct VerFile;
  98. struct DescFile;
  99. // Iterators
  100. template<typename Str, typename Itr> class Iterator;
  101. class GrpIterator;
  102. class PkgIterator;
  103. class VerIterator;
  104. class DescIterator;
  105. class DepIterator;
  106. class PrvIterator;
  107. class PkgFileIterator;
  108. class VerFileIterator;
  109. class DescFileIterator;
  110. class Namespace;
  111. // These are all the constants used in the cache structures
  112. // WARNING - if you change these lists you must also edit
  113. // the stringification in pkgcache.cc and also consider whether
  114. // the cache file will become incompatible.
  115. struct Dep
  116. {
  117. enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
  118. Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
  119. /** \brief available compare operators
  120. The lower 4 bits are used to indicate what operator is being specified and
  121. the upper 4 bits are flags. OR indicates that the next package is
  122. or'd with the current package. */
  123. enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
  124. Greater=0x4,Equals=0x5,NotEquals=0x6};
  125. };
  126. struct State
  127. {
  128. /** \brief priority of a package version
  129. Zero is used for unparsable or absent Priority fields. */
  130. enum VerPriority {Required=1,Important=2,Standard=3,Optional=4,Extra=5};
  131. enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
  132. enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
  133. enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
  134. HalfInstalled=4,ConfigFiles=5,Installed=6,
  135. TriggersAwaited=7,TriggersPending=8};
  136. };
  137. struct Flag
  138. {
  139. enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
  140. enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1),ButAutomaticUpgrades=(1<<2)};
  141. };
  142. protected:
  143. // Memory mapped cache file
  144. std::string CacheFile;
  145. MMap &Map;
  146. map_id_t sHash(const std::string &S) const APT_PURE;
  147. map_id_t sHash(const char *S) const APT_PURE;
  148. public:
  149. // Pointers to the arrays of items
  150. Header *HeaderP;
  151. Group *GrpP;
  152. Package *PkgP;
  153. VerFile *VerFileP;
  154. DescFile *DescFileP;
  155. PackageFile *PkgFileP;
  156. Version *VerP;
  157. Description *DescP;
  158. Provides *ProvideP;
  159. Dependency *DepP;
  160. char *StrP;
  161. virtual bool ReMap(bool const &Errorchecks = true);
  162. inline bool Sync() {return Map.Sync();}
  163. inline MMap &GetMap() {return Map;}
  164. inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();}
  165. // String hashing function (512 range)
  166. inline map_id_t Hash(const std::string &S) const {return sHash(S);}
  167. inline map_id_t Hash(const char *S) const {return sHash(S);}
  168. // Useful transformation things
  169. const char *Priority(unsigned char Priority);
  170. // Accessors
  171. GrpIterator FindGrp(const std::string &Name);
  172. PkgIterator FindPkg(const std::string &Name);
  173. PkgIterator FindPkg(const std::string &Name, const std::string &Arch);
  174. Header &Head() {return *HeaderP;}
  175. inline GrpIterator GrpBegin();
  176. inline GrpIterator GrpEnd();
  177. inline PkgIterator PkgBegin();
  178. inline PkgIterator PkgEnd();
  179. inline PkgFileIterator FileBegin();
  180. inline PkgFileIterator FileEnd();
  181. inline bool MultiArchCache() const { return MultiArchEnabled; }
  182. inline char const * NativeArch();
  183. // Make me a function
  184. pkgVersioningSystem *VS;
  185. // Converters
  186. static const char *CompTypeDeb(unsigned char Comp) APT_CONST;
  187. static const char *CompType(unsigned char Comp) APT_CONST;
  188. static const char *DepType(unsigned char Dep);
  189. pkgCache(MMap *Map,bool DoMap = true);
  190. virtual ~pkgCache() {}
  191. private:
  192. bool MultiArchEnabled;
  193. APT_HIDDEN PkgIterator SingleArchFindPkg(const std::string &Name);
  194. };
  195. /*}}}*/
  196. // Header structure /*{{{*/
  197. struct pkgCache::Header
  198. {
  199. /** \brief Signature information
  200. This must contain the hex value 0x98FE76DC which is designed to
  201. verify that the system loading the image has the same byte order
  202. and byte size as the system saving the image */
  203. unsigned long Signature;
  204. /** These contain the version of the cache file */
  205. short MajorVersion;
  206. short MinorVersion;
  207. /** \brief indicates if the cache should be erased
  208. Dirty is true if the cache file was opened for reading, the client
  209. expects to have written things to it and have not fully synced it.
  210. The file should be erased and rebuilt if it is true. */
  211. bool Dirty;
  212. /** \brief Size of structure values
  213. All *Sz variables contains the sizeof() that particular structure.
  214. It is used as an extra consistency check on the structure of the file.
  215. If any of the size values do not exactly match what the client expects
  216. then the client should refuse the load the file. */
  217. unsigned short HeaderSz;
  218. unsigned short GroupSz;
  219. unsigned short PackageSz;
  220. unsigned short PackageFileSz;
  221. unsigned short VersionSz;
  222. unsigned short DescriptionSz;
  223. unsigned short DependencySz;
  224. unsigned short ProvidesSz;
  225. unsigned short VerFileSz;
  226. unsigned short DescFileSz;
  227. /** \brief Structure counts
  228. These indicate the number of each structure contained in the cache.
  229. PackageCount is especially useful for generating user state structures.
  230. See Package::Id for more info. */
  231. map_id_t GroupCount;
  232. map_id_t PackageCount;
  233. map_id_t VersionCount;
  234. map_id_t DescriptionCount;
  235. map_id_t DependsCount;
  236. map_fileid_t PackageFileCount;
  237. map_fileid_t VerFileCount;
  238. map_fileid_t DescFileCount;
  239. map_id_t ProvidesCount;
  240. /** \brief index of the first PackageFile structure
  241. The PackageFile structures are singly linked lists that represent
  242. all package files that have been merged into the cache. */
  243. map_pointer_t FileList;
  244. /** \brief String representing the version system used */
  245. map_pointer_t VerSysName;
  246. /** \brief native architecture the cache was built against */
  247. map_pointer_t Architecture;
  248. /** \brief all architectures the cache was built against */
  249. map_pointer_t Architectures;
  250. /** \brief The maximum size of a raw entry from the original Package file */
  251. map_filesize_t MaxVerFileSize;
  252. /** \brief The maximum size of a raw entry from the original Translation file */
  253. map_filesize_t MaxDescFileSize;
  254. /** \brief The Pool structures manage the allocation pools that the generator uses
  255. Start indicates the first byte of the pool, Count is the number of objects
  256. remaining in the pool and ItemSize is the structure size (alignment factor)
  257. of the pool. An ItemSize of 0 indicates the pool is empty. There should be
  258. the same number of pools as there are structure types. The generator
  259. stores this information so future additions can make use of any unused pool
  260. blocks. */
  261. DynamicMMap::Pool Pools[9];
  262. /** \brief hash tables providing rapid group/package name lookup
  263. Each group/package name is inserted into a hash table using pkgCache::Hash(const &string)
  264. By iterating over each entry in the hash table it is possible to iterate over
  265. the entire list of packages. Hash Collisions are handled with a singly linked
  266. list of packages based at the hash item. The linked list contains only
  267. packages that match the hashing function.
  268. In the PkgHashTable is it possible that multiple packages have the same name -
  269. these packages are stored as a sequence in the list.
  270. The size of both tables is the same. */
  271. unsigned int HashTableSize;
  272. map_pointer_t * PkgHashTable() const { return (map_pointer_t*) (this + 1); }
  273. map_pointer_t * GrpHashTable() const { return PkgHashTable() + HashTableSize; }
  274. /** \brief Size of the complete cache file */
  275. unsigned long long CacheFileSize;
  276. bool CheckSizes(Header &Against) const APT_PURE;
  277. Header();
  278. };
  279. /*}}}*/
  280. // Group structure /*{{{*/
  281. /** \brief groups architecture depending packages together
  282. On or more packages with the same name form a group, so we have
  283. a simple way to access a package built for different architectures
  284. Group exists in a singly linked list of group records starting at
  285. the hash index of the name in the pkgCache::Header::GrpHashTable */
  286. struct pkgCache::Group
  287. {
  288. /** \brief Name of the group */
  289. map_stringitem_t Name;
  290. // Linked List
  291. /** \brief Link to the first package which belongs to the group */
  292. map_pointer_t FirstPackage; // Package
  293. /** \brief Link to the last package which belongs to the group */
  294. map_pointer_t LastPackage; // Package
  295. /** \brief Link to the next Group */
  296. map_pointer_t Next; // Group
  297. /** \brief unique sequel ID */
  298. map_id_t ID;
  299. };
  300. /*}}}*/
  301. // Package structure /*{{{*/
  302. /** \brief contains information for a single unique package
  303. There can be any number of versions of a given package.
  304. Package exists in a singly linked list of package records starting at
  305. the hash index of the name in the pkgCache::Header::PkgHashTable
  306. A package can be created for every architecture so package names are
  307. not unique, but it is guaranteed that packages with the same name
  308. are sequencel ordered in the list. Packages with the same name can be
  309. accessed with the Group.
  310. */
  311. struct pkgCache::Package
  312. {
  313. /** \brief Name of the package
  314. * Note that the access method Name() will remain. It is just this data member
  315. * deprecated as this information is already stored and available via the
  316. * associated Group – so it is wasting precious binary cache space */
  317. APT_DEPRECATED map_stringitem_t Name;
  318. /** \brief Architecture of the package */
  319. map_stringitem_t Arch;
  320. /** \brief Base of a singly linked list of versions
  321. Each structure represents a unique version of the package.
  322. The version structures contain links into PackageFile and the
  323. original text file as well as detailed information about the size
  324. and dependencies of the specific package. In this way multiple
  325. versions of a package can be cleanly handled by the system.
  326. Furthermore, this linked list is guaranteed to be sorted
  327. from Highest version to lowest version with no duplicate entries. */
  328. map_pointer_t VersionList; // Version
  329. /** \brief index to the installed version */
  330. map_pointer_t CurrentVer; // Version
  331. /** \brief index of the group this package belongs to */
  332. map_pointer_t Group; // Group the Package belongs to
  333. // Linked list
  334. /** \brief Link to the next package in the same bucket */
  335. map_pointer_t Next; // Package
  336. /** \brief List of all dependencies on this package */
  337. map_pointer_t RevDepends; // Dependency
  338. /** \brief List of all "packages" this package provide */
  339. map_pointer_t ProvidesList; // Provides
  340. // Install/Remove/Purge etc
  341. /** \brief state that the user wishes the package to be in */
  342. unsigned char SelectedState; // What
  343. /** \brief installation state of the package
  344. This should be "ok" but in case the installation failed
  345. it will be different.
  346. */
  347. unsigned char InstState; // Flags
  348. /** \brief indicates if the package is installed */
  349. unsigned char CurrentState; // State
  350. /** \brief unique sequel ID
  351. ID is a unique value from 0 to Header->PackageCount assigned by the generator.
  352. This allows clients to create an array of size PackageCount and use it to store
  353. state information for the package map. For instance the status file emitter uses
  354. this to track which packages have been emitted already. */
  355. map_id_t ID;
  356. /** \brief some useful indicators of the package's state */
  357. unsigned long Flags;
  358. };
  359. /*}}}*/
  360. // Package File structure /*{{{*/
  361. /** \brief stores information about the files used to generate the cache
  362. Package files are referenced by Version structures to be able to know
  363. after the generation still from which Packages file includes this Version
  364. as we need this information later on e.g. for pinning. */
  365. struct pkgCache::PackageFile
  366. {
  367. /** \brief physical disk file that this PackageFile represents */
  368. map_stringitem_t FileName;
  369. /** \brief the release information
  370. Please see the files document for a description of what the
  371. release information means. */
  372. map_stringitem_t Archive;
  373. map_stringitem_t Codename;
  374. map_stringitem_t Component;
  375. map_stringitem_t Version;
  376. map_stringitem_t Origin;
  377. map_stringitem_t Label;
  378. map_stringitem_t Architecture;
  379. /** \brief The site the index file was fetched from */
  380. map_stringitem_t Site;
  381. /** \brief indicates what sort of index file this is
  382. @TODO enumerate at least the possible indexes */
  383. map_stringitem_t IndexType;
  384. /** \brief Size of the file
  385. Used together with the modification time as a
  386. simple check to ensure that the Packages
  387. file has not been altered since Cache generation. */
  388. map_filesize_t Size;
  389. /** \brief Modification time for the file */
  390. time_t mtime;
  391. /** @TODO document PackageFile::Flags */
  392. unsigned long Flags;
  393. // Linked list
  394. /** \brief Link to the next PackageFile in the Cache */
  395. map_pointer_t NextFile; // PackageFile
  396. /** \brief unique sequel ID */
  397. map_fileid_t ID;
  398. };
  399. /*}}}*/
  400. // VerFile structure /*{{{*/
  401. /** \brief associates a version with a PackageFile
  402. This allows a full description of all Versions in all files
  403. (and hence all sources) under consideration. */
  404. struct pkgCache::VerFile
  405. {
  406. /** \brief index of the package file that this version was found in */
  407. map_pointer_t File; // PackageFile
  408. /** \brief next step in the linked list */
  409. map_pointer_t NextFile; // PkgVerFile
  410. /** \brief position in the package file */
  411. map_filesize_t Offset; // File offset
  412. /** @TODO document pkgCache::VerFile::Size */
  413. map_filesize_t Size;
  414. };
  415. /*}}}*/
  416. // DescFile structure /*{{{*/
  417. /** \brief associates a description with a Translation file */
  418. struct pkgCache::DescFile
  419. {
  420. /** \brief index of the file that this description was found in */
  421. map_pointer_t File; // PackageFile
  422. /** \brief next step in the linked list */
  423. map_pointer_t NextFile; // PkgVerFile
  424. /** \brief position in the file */
  425. map_filesize_t Offset; // File offset
  426. /** @TODO document pkgCache::DescFile::Size */
  427. map_filesize_t Size;
  428. };
  429. /*}}}*/
  430. // Version structure /*{{{*/
  431. /** \brief information for a single version of a package
  432. The version list is always sorted from highest version to lowest
  433. version by the generator. Equal version numbers are either merged
  434. or handled as separate versions based on the Hash value. */
  435. struct pkgCache::Version
  436. {
  437. /** \brief complete version string */
  438. map_stringitem_t VerStr;
  439. /** \brief section this version is filled in */
  440. map_stringitem_t Section;
  441. /** \brief source package name this version comes from
  442. Always contains the name, even if it is the same as the binary name */
  443. map_stringitem_t SourcePkgName;
  444. /** \brief source version this version comes from
  445. Always contains the version string, even if it is the same as the binary version */
  446. map_stringitem_t SourceVerStr;
  447. /** \brief Multi-Arch capabilities of a package version */
  448. enum VerMultiArch { None = 0, /*!< is the default and doesn't trigger special behaviour */
  449. All = (1<<0), /*!< will cause that Ver.Arch() will report "all" */
  450. Foreign = (1<<1), /*!< can satisfy dependencies in another architecture */
  451. Same = (1<<2), /*!< can be co-installed with itself from other architectures */
  452. Allowed = (1<<3), /*!< other packages are allowed to depend on thispkg:any */
  453. AllForeign = All | Foreign,
  454. AllAllowed = All | Allowed };
  455. /** \brief stores the MultiArch capabilities of this version
  456. Flags used are defined in pkgCache::Version::VerMultiArch
  457. */
  458. unsigned char MultiArch;
  459. /** \brief references all the PackageFile's that this version came from
  460. FileList can be used to determine what distribution(s) the Version
  461. applies to. If FileList is 0 then this is a blank version.
  462. The structure should also have a 0 in all other fields excluding
  463. pkgCache::Version::VerStr and Possibly pkgCache::Version::NextVer. */
  464. map_pointer_t FileList; // VerFile
  465. /** \brief next (lower or equal) version in the linked list */
  466. map_pointer_t NextVer; // Version
  467. /** \brief next description in the linked list */
  468. map_pointer_t DescriptionList; // Description
  469. /** \brief base of the dependency list */
  470. map_pointer_t DependsList; // Dependency
  471. /** \brief links to the owning package
  472. This allows reverse dependencies to determine the package */
  473. map_pointer_t ParentPkg; // Package
  474. /** \brief list of pkgCache::Provides */
  475. map_pointer_t ProvidesList; // Provides
  476. /** \brief archive size for this version
  477. For Debian this is the size of the .deb file. */
  478. uint64_t Size; // These are the .deb size
  479. /** \brief uncompressed size for this version */
  480. uint64_t InstalledSize;
  481. /** \brief characteristic value representing this version
  482. No two packages in existence should have the same VerStr
  483. and Hash with different contents. */
  484. unsigned short Hash;
  485. /** \brief unique sequel ID */
  486. map_id_t ID;
  487. /** \brief parsed priority value */
  488. unsigned char Priority;
  489. };
  490. /*}}}*/
  491. // Description structure /*{{{*/
  492. /** \brief datamember of a linked list of available description for a version */
  493. struct pkgCache::Description
  494. {
  495. /** \brief Language code of this description (translation)
  496. If the value has a 0 length then this is read using the Package
  497. file else the Translation-CODE file is used. */
  498. map_stringitem_t language_code;
  499. /** \brief MD5sum of the original description
  500. Used to map Translations of a description to a version
  501. and to check that the Translation is up-to-date. */
  502. map_stringitem_t md5sum;
  503. /** @TODO document pkgCache::Description::FileList */
  504. map_pointer_t FileList; // DescFile
  505. /** \brief next translation for this description */
  506. map_pointer_t NextDesc; // Description
  507. /** \brief the text is a description of this package */
  508. map_pointer_t ParentPkg; // Package
  509. /** \brief unique sequel ID */
  510. map_id_t ID;
  511. };
  512. /*}}}*/
  513. // Dependency structure /*{{{*/
  514. /** \brief information for a single dependency record
  515. The records are split up like this to ease processing by the client.
  516. The base of the linked list is pkgCache::Version::DependsList.
  517. All forms of dependencies are recorded here including Depends,
  518. Recommends, Suggests, Enhances, Conflicts, Replaces and Breaks. */
  519. struct pkgCache::Dependency
  520. {
  521. /** \brief string of the version the dependency is applied against */
  522. map_stringitem_t Version;
  523. /** \brief index of the package this depends applies to
  524. The generator will - if the package does not already exist -
  525. create a blank (no version records) package. */
  526. map_pointer_t Package; // Package
  527. /** \brief next dependency of this version */
  528. map_pointer_t NextDepends; // Dependency
  529. /** \brief next reverse dependency of this package */
  530. map_pointer_t NextRevDepends; // Dependency
  531. /** \brief version of the package which has the reverse depends */
  532. map_pointer_t ParentVer; // Version
  533. /** \brief unique sequel ID */
  534. map_id_t ID;
  535. /** \brief Dependency type - Depends, Recommends, Conflicts, etc */
  536. unsigned char Type;
  537. /** \brief comparison operator specified on the depends line
  538. If the high bit is set then it is a logical OR with the previous record. */
  539. unsigned char CompareOp;
  540. };
  541. /*}}}*/
  542. // Provides structure /*{{{*/
  543. /** \brief handles virtual packages
  544. When a Provides: line is encountered a new provides record is added
  545. associating the package with a virtual package name.
  546. The provides structures are linked off the package structures.
  547. This simplifies the analysis of dependencies and other aspects A provides
  548. refers to a specific version of a specific package, not all versions need to
  549. provide that provides.*/
  550. struct pkgCache::Provides
  551. {
  552. /** \brief index of the package providing this */
  553. map_pointer_t ParentPkg; // Package
  554. /** \brief index of the version this provide line applies to */
  555. map_pointer_t Version; // Version
  556. /** \brief version in the provides line (if any)
  557. This version allows dependencies to depend on specific versions of a
  558. Provides, as well as allowing Provides to override existing packages.
  559. This is experimental. Note that Debian doesn't allow versioned provides */
  560. map_stringitem_t ProvideVersion;
  561. /** \brief next provides (based of package) */
  562. map_pointer_t NextProvides; // Provides
  563. /** \brief next provides (based of version) */
  564. map_pointer_t NextPkgProv; // Provides
  565. };
  566. /*}}}*/
  567. inline char const * pkgCache::NativeArch()
  568. { return StrP + HeaderP->Architecture; }
  569. #include <apt-pkg/cacheiterators.h>
  570. inline pkgCache::GrpIterator pkgCache::GrpBegin()
  571. {return GrpIterator(*this);}
  572. inline pkgCache::GrpIterator pkgCache::GrpEnd()
  573. {return GrpIterator(*this,GrpP);}
  574. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  575. {return PkgIterator(*this);}
  576. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  577. {return PkgIterator(*this,PkgP);}
  578. inline pkgCache::PkgFileIterator pkgCache::FileBegin()
  579. {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);}
  580. inline pkgCache::PkgFileIterator pkgCache::FileEnd()
  581. {return PkgFileIterator(*this,PkgFileP);}
  582. // Oh I wish for Real Name Space Support
  583. class pkgCache::Namespace /*{{{*/
  584. {
  585. public:
  586. typedef pkgCache::GrpIterator GrpIterator;
  587. typedef pkgCache::PkgIterator PkgIterator;
  588. typedef pkgCache::VerIterator VerIterator;
  589. typedef pkgCache::DescIterator DescIterator;
  590. typedef pkgCache::DepIterator DepIterator;
  591. typedef pkgCache::PrvIterator PrvIterator;
  592. typedef pkgCache::PkgFileIterator PkgFileIterator;
  593. typedef pkgCache::VerFileIterator VerFileIterator;
  594. typedef pkgCache::Version Version;
  595. typedef pkgCache::Description Description;
  596. typedef pkgCache::Package Package;
  597. typedef pkgCache::Header Header;
  598. typedef pkgCache::Dep Dep;
  599. typedef pkgCache::Flag Flag;
  600. };
  601. /*}}}*/
  602. #endif