metaindex.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Include Files /*{{{*/
  2. #include <apt-pkg/pkgcachegen.h>
  3. #include <apt-pkg/indexfile.h>
  4. #include <apt-pkg/metaindex.h>
  5. #include <apt-pkg/debmetaindex.h>
  6. #include <string>
  7. #include <vector>
  8. /*}}}*/
  9. std::string metaIndex::Describe() const
  10. {
  11. return "Release";
  12. }
  13. pkgCache::RlsFileIterator metaIndex::FindInCache(pkgCache &Cache, bool const) const
  14. {
  15. return pkgCache::RlsFileIterator(Cache);
  16. }
  17. bool metaIndex::Merge(pkgCacheGenerator &Gen,OpProgress *) const
  18. {
  19. return Gen.SelectReleaseFile("", "");
  20. }
  21. metaIndex::metaIndex(std::string const &URI, std::string const &Dist,
  22. char const * const Type)
  23. : d(NULL), Indexes(NULL), Type(Type), URI(URI), Dist(Dist), Trusted(TRI_UNSET),
  24. Date(0), ValidUntil(0), SupportsAcquireByHash(false), LoadedSuccessfully(TRI_UNSET)
  25. {
  26. /* nothing */
  27. }
  28. metaIndex::~metaIndex()
  29. {
  30. if (Indexes != 0)
  31. {
  32. for (std::vector<pkgIndexFile *>::iterator I = (*Indexes).begin();
  33. I != (*Indexes).end(); ++I)
  34. delete *I;
  35. delete Indexes;
  36. }
  37. for (auto const &E: Entries)
  38. delete E.second;
  39. }
  40. // one line Getters for public fields /*{{{*/
  41. APT_PURE std::string metaIndex::GetURI() const { return URI; }
  42. APT_PURE std::string metaIndex::GetDist() const { return Dist; }
  43. APT_PURE const char* metaIndex::GetType() const { return Type; }
  44. APT_PURE metaIndex::TriState metaIndex::GetTrusted() const { return Trusted; }
  45. APT_PURE std::string metaIndex::GetSignedBy() const { return SignedBy; }
  46. APT_PURE std::string metaIndex::GetCodename() const { return Codename; }
  47. APT_PURE std::string metaIndex::GetSuite() const { return Suite; }
  48. APT_PURE bool metaIndex::GetSupportsAcquireByHash() const { return SupportsAcquireByHash; }
  49. APT_PURE time_t metaIndex::GetValidUntil() const { return ValidUntil; }
  50. APT_PURE time_t metaIndex::GetDate() const { return this->Date; }
  51. APT_PURE metaIndex::TriState metaIndex::GetLoadedSuccessfully() const { return LoadedSuccessfully; }
  52. APT_PURE bool metaIndex::CheckDist(string const &MaybeDist) const
  53. {
  54. return (this->Codename == MaybeDist
  55. || this->Suite == MaybeDist);
  56. }
  57. APT_PURE std::string metaIndex::GetExpectedDist() const
  58. {
  59. // TODO: Used to be an explicit value set in the constructor
  60. return "";
  61. }
  62. /*}}}*/
  63. APT_PURE metaIndex::checkSum *metaIndex::Lookup(string const &MetaKey) const /*{{{*/
  64. {
  65. std::map<std::string, metaIndex::checkSum* >::const_iterator sum = Entries.find(MetaKey);
  66. if (sum == Entries.end())
  67. return NULL;
  68. return sum->second;
  69. }
  70. /*}}}*/
  71. APT_PURE bool metaIndex::Exists(string const &MetaKey) const /*{{{*/
  72. {
  73. return Entries.find(MetaKey) != Entries.end();
  74. }
  75. /*}}}*/
  76. std::vector<std::string> metaIndex::MetaKeys() const /*{{{*/
  77. {
  78. std::vector<std::string> keys;
  79. std::map<string,checkSum *>::const_iterator I = Entries.begin();
  80. while(I != Entries.end()) {
  81. keys.push_back((*I).first);
  82. ++I;
  83. }
  84. return keys;
  85. }
  86. /*}}}*/
  87. void metaIndex::swapLoad(metaIndex * const OldMetaIndex) /*{{{*/
  88. {
  89. std::swap(Entries, OldMetaIndex->Entries);
  90. std::swap(Date, OldMetaIndex->Date);
  91. std::swap(ValidUntil, OldMetaIndex->ValidUntil);
  92. std::swap(SupportsAcquireByHash, OldMetaIndex->SupportsAcquireByHash);
  93. std::swap(LoadedSuccessfully, OldMetaIndex->LoadedSuccessfully);
  94. }
  95. /*}}}*/
  96. bool metaIndex::IsArchitectureSupported(std::string const &arch) const /*{{{*/
  97. {
  98. debReleaseIndex const * const deb = dynamic_cast<debReleaseIndex const *>(this);
  99. if (deb != NULL)
  100. return deb->IsArchitectureSupported(arch);
  101. return true;
  102. }
  103. /*}}}*/