sourcelist.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. SourceList - Manage a list of sources
  5. The Source List class provides access to a list of sources. It
  6. can read them from a file and generate a list of all the distinct
  7. sources.
  8. All sources have a type associated with them that defines the layout
  9. of the archive. The exact format of the file is documented in
  10. files.sgml.
  11. The types are mapped through a list of type definitions which handle
  12. the actual construction of the back end type. After loading a source
  13. list all you have is a list of package index files that have the ability
  14. to be Acquired.
  15. ##################################################################### */
  16. /*}}}*/
  17. #ifndef PKGLIB_SOURCELIST_H
  18. #define PKGLIB_SOURCELIST_H
  19. #include <apt-pkg/pkgcache.h>
  20. #include <apt-pkg/cacheiterators.h>
  21. #include <apt-pkg/macros.h>
  22. #include <time.h>
  23. #include <string>
  24. #include <vector>
  25. #include <map>
  26. #ifndef APT_8_CLEANER_HEADERS
  27. #include <apt-pkg/tagfile.h>
  28. #endif
  29. #ifndef APT_8_CLEANER_HEADERS
  30. #include <apt-pkg/metaindex.h>
  31. using std::string;
  32. using std::vector;
  33. #endif
  34. class FileFd;
  35. class pkgTagSection;
  36. class pkgAcquire;
  37. class pkgIndexFile;
  38. class metaIndex;
  39. class CommandLine;
  40. class pkgSourceList
  41. {
  42. void * const d;
  43. std::vector<pkgIndexFile*> VolatileFiles;
  44. public:
  45. // List of supported source list types
  46. class Type
  47. {
  48. public:
  49. // Global list of Items supported
  50. static Type **GlobalList;
  51. static unsigned long GlobalListLen;
  52. static Type *GetType(const char *Type) APT_PURE;
  53. char const * const Name;
  54. char const * const Label;
  55. bool FixupURI(std::string &URI) const;
  56. virtual bool ParseStanza(std::vector<metaIndex *> &List,
  57. pkgTagSection &Tags,
  58. unsigned int const stanza_n,
  59. FileFd &Fd);
  60. virtual bool ParseLine(std::vector<metaIndex *> &List,
  61. const char *Buffer,
  62. unsigned int const CurLine,std::string const &File) const;
  63. virtual bool CreateItem(std::vector<metaIndex *> &List,std::string const &URI,
  64. std::string const &Dist,std::string const &Section,
  65. std::map<std::string, std::string> const &Options) const = 0;
  66. Type(char const * const Name, char const * const Label);
  67. virtual ~Type();
  68. };
  69. typedef std::vector<metaIndex *>::const_iterator const_iterator;
  70. protected:
  71. std::vector<metaIndex *> SrcList;
  72. private:
  73. APT_HIDDEN bool ParseFileDeb822(std::string const &File);
  74. APT_HIDDEN bool ParseFileOldStyle(std::string const &File);
  75. public:
  76. bool ReadMainList();
  77. bool Read(std::string const &File);
  78. // CNC:2003-03-03
  79. void Reset();
  80. bool ReadAppend(std::string const &File);
  81. bool ReadSourceDir(std::string const &Dir);
  82. // List accessors
  83. inline const_iterator begin() const {return SrcList.begin();};
  84. inline const_iterator end() const {return SrcList.end();};
  85. inline unsigned int size() const {return SrcList.size();};
  86. inline bool empty() const {return SrcList.empty();};
  87. bool FindIndex(pkgCache::PkgFileIterator File,
  88. pkgIndexFile *&Found) const;
  89. bool GetIndexes(pkgAcquire *Owner, bool GetAll=false) const;
  90. // query last-modified time
  91. time_t GetLastModifiedTime();
  92. /** \brief add file for parsing, but not to the cache
  93. *
  94. * pkgIndexFiles origining from pkgSourcesList are included in
  95. * srcpkgcache, the status files added via #AddStatusFiles are
  96. * included in pkgcache, but these files here are not included in
  97. * any cache to have the possibility of having a file included just
  98. * for a single run like a local .deb/.dsc file.
  99. *
  100. * The volatile files do not count as "normal" sourceslist entries,
  101. * can't be iterated over with #begin and #end and can't be
  102. * downloaded, but they can be found via #FindIndex.
  103. *
  104. * @param File is an index file; pointer-ownership is transferred
  105. */
  106. void AddVolatileFile(pkgIndexFile * const File);
  107. bool AddVolatileFile(std::string const &File);
  108. bool AddVolatileFile(std::string const &File, std::vector<std::string> * const VolatileCmdL);
  109. APT_DEPRECATED_MSG("Use the overload with string-vector") void AddVolatileFiles(CommandLine &CmdL, std::vector<const char*> * const VolatileCmdL);
  110. void AddVolatileFiles(CommandLine &CmdL, std::vector<std::string> * const VolatileCmdL);
  111. /** @return list of files registered with #AddVolatileFile */
  112. std::vector<pkgIndexFile*> GetVolatileFiles() const;
  113. pkgSourceList();
  114. virtual ~pkgSourceList();
  115. };
  116. #endif