indexfile.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Index File - Abstraction for an index of archive/source file.
  5. There are 4 primary sorts of index files, all represented by this
  6. class:
  7. Binary index files
  8. Binary translation files
  9. Binary index files describing the local system
  10. Source index files
  11. They are all bundled together here, and the interfaces for
  12. sources.list, acquire, cache gen and record parsing all use this class
  13. to access the underlying representation.
  14. ##################################################################### */
  15. /*}}}*/
  16. #ifndef PKGLIB_INDEXFILE_H
  17. #define PKGLIB_INDEXFILE_H
  18. #include <apt-pkg/srcrecords.h>
  19. #include <apt-pkg/pkgrecords.h>
  20. #include <apt-pkg/pkgcache.h>
  21. #include <apt-pkg/cacheiterators.h>
  22. #include <apt-pkg/macros.h>
  23. #include <map>
  24. #include <string>
  25. #ifndef APT_8_CLEANER_HEADERS
  26. using std::string;
  27. #endif
  28. #ifndef APT_10_CLEANER_HEADERS
  29. class pkgAcquire;
  30. #endif
  31. class pkgCacheGenerator;
  32. class OpProgress;
  33. class IndexTarget /*{{{*/
  34. /** \brief Information about an index file. */
  35. {
  36. public:
  37. /** \brief A URI from which the index file can be downloaded. */
  38. std::string URI;
  39. /** \brief A description of the index file. */
  40. std::string Description;
  41. /** \brief A shorter description of the index file. */
  42. std::string ShortDesc;
  43. /** \brief The key by which this index file should be
  44. looked up within the meta index file. */
  45. std::string MetaKey;
  46. /** \brief Is it okay if the file isn't found in the meta index */
  47. bool IsOptional;
  48. /** \brief If the file is downloaded compressed, do not unpack it */
  49. bool KeepCompressed;
  50. /** \brief options with which this target was created
  51. Prefer the usage of #Option if at all possible.
  52. Beware: Not all of these options are intended for public use */
  53. std::map<std::string, std::string> Options;
  54. IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
  55. std::string const &LongDesc, std::string const &URI, bool const IsOptional,
  56. bool const KeepCompressed, std::map<std::string, std::string> const &Options);
  57. enum OptionKeys {
  58. SITE,
  59. RELEASE,
  60. COMPONENT,
  61. LANGUAGE,
  62. ARCHITECTURE,
  63. BASE_URI,
  64. REPO_URI,
  65. CREATED_BY,
  66. TARGET_OF,
  67. FILENAME,
  68. EXISTING_FILENAME,
  69. };
  70. std::string Option(OptionKeys const Key) const;
  71. std::string Format(std::string format) const;
  72. };
  73. /*}}}*/
  74. class pkgIndexFile
  75. {
  76. void * const d;
  77. protected:
  78. bool Trusted;
  79. public:
  80. class Type
  81. {
  82. public:
  83. // Global list of Items supported
  84. static Type **GlobalList;
  85. static unsigned long GlobalListLen;
  86. static Type *GetType(const char *Type) APT_PURE;
  87. const char *Label;
  88. virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator /*File*/) const {return 0;};
  89. virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string /*File*/) const {return 0;};
  90. Type();
  91. virtual ~Type() {};
  92. };
  93. virtual const Type *GetType() const = 0;
  94. // Return descriptive strings of various sorts
  95. virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const;
  96. virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record,
  97. pkgSrcRecords::File const &File) const;
  98. virtual std::string Describe(bool Short = false) const = 0;
  99. // Interface for acquire
  100. virtual std::string ArchiveURI(std::string /*File*/) const {return std::string();};
  101. // Interface for the record parsers
  102. virtual pkgSrcRecords::Parser *CreateSrcParser() const {return 0;};
  103. // Interface for the Cache Generator
  104. virtual bool Exists() const = 0;
  105. virtual bool HasPackages() const = 0;
  106. virtual unsigned long Size() const = 0;
  107. virtual bool Merge(pkgCacheGenerator &/*Gen*/, OpProgress* /*Prog*/) const { return false; };
  108. APT_DEPRECATED virtual bool Merge(pkgCacheGenerator &Gen, OpProgress &Prog) const
  109. { return Merge(Gen, &Prog); };
  110. virtual bool MergeFileProvides(pkgCacheGenerator &/*Gen*/,OpProgress* /*Prog*/) const {return true;};
  111. APT_DEPRECATED virtual bool MergeFileProvides(pkgCacheGenerator &Gen, OpProgress &Prog) const
  112. {return MergeFileProvides(Gen, &Prog);};
  113. virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const;
  114. static bool TranslationsAvailable();
  115. static bool CheckLanguageCode(const char *Lang);
  116. static std::string LanguageCode();
  117. bool IsTrusted() const { return Trusted; };
  118. explicit pkgIndexFile(bool Trusted);
  119. virtual ~pkgIndexFile();
  120. };
  121. class pkgIndexTargetFile : public pkgIndexFile
  122. {
  123. void * const d;
  124. protected:
  125. IndexTarget const Target;
  126. std::string IndexFileName() const;
  127. public:
  128. virtual std::string ArchiveURI(std::string File) const APT_OVERRIDE;
  129. virtual std::string Describe(bool Short = false) const APT_OVERRIDE;
  130. virtual bool Exists() const APT_OVERRIDE;
  131. virtual unsigned long Size() const APT_OVERRIDE;
  132. pkgIndexTargetFile(IndexTarget const &Target, bool const Trusted);
  133. virtual ~pkgIndexTargetFile();
  134. };
  135. #endif