metaindex.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 std::string metaIndex::GetExpectedDist() const { return Dist; }
  53. /*}}}*/
  54. bool metaIndex::CheckDist(string const &MaybeDist) const /*{{{*/
  55. {
  56. if (MaybeDist.empty() || this->Codename == MaybeDist || this->Suite == MaybeDist)
  57. return true;
  58. std::string Transformed = MaybeDist;
  59. if (Transformed == "../project/experimental")
  60. Transformed = "experimental";
  61. auto const pos = Transformed.rfind('/');
  62. if (pos != string::npos)
  63. Transformed = Transformed.substr(0, pos);
  64. if (Transformed == ".")
  65. Transformed.clear();
  66. return Transformed.empty() || this->Codename == Transformed || this->Suite == Transformed;
  67. }
  68. /*}}}*/
  69. APT_PURE metaIndex::checkSum *metaIndex::Lookup(string const &MetaKey) const /*{{{*/
  70. {
  71. std::map<std::string, metaIndex::checkSum* >::const_iterator sum = Entries.find(MetaKey);
  72. if (sum == Entries.end())
  73. return NULL;
  74. return sum->second;
  75. }
  76. /*}}}*/
  77. APT_PURE bool metaIndex::Exists(string const &MetaKey) const /*{{{*/
  78. {
  79. return Entries.find(MetaKey) != Entries.end();
  80. }
  81. /*}}}*/
  82. std::vector<std::string> metaIndex::MetaKeys() const /*{{{*/
  83. {
  84. std::vector<std::string> keys;
  85. std::map<string,checkSum *>::const_iterator I = Entries.begin();
  86. while(I != Entries.end()) {
  87. keys.push_back((*I).first);
  88. ++I;
  89. }
  90. return keys;
  91. }
  92. /*}}}*/
  93. void metaIndex::swapLoad(metaIndex * const OldMetaIndex) /*{{{*/
  94. {
  95. std::swap(Entries, OldMetaIndex->Entries);
  96. std::swap(Date, OldMetaIndex->Date);
  97. std::swap(ValidUntil, OldMetaIndex->ValidUntil);
  98. std::swap(SupportsAcquireByHash, OldMetaIndex->SupportsAcquireByHash);
  99. std::swap(LoadedSuccessfully, OldMetaIndex->LoadedSuccessfully);
  100. }
  101. /*}}}*/
  102. bool metaIndex::IsArchitectureSupported(std::string const &arch) const /*{{{*/
  103. {
  104. debReleaseIndex const * const deb = dynamic_cast<debReleaseIndex const *>(this);
  105. if (deb != NULL)
  106. return deb->IsArchitectureSupported(arch);
  107. return true;
  108. }
  109. /*}}}*/
  110. bool metaIndex::IsArchitectureAllSupportedFor(IndexTarget const &target) const/*{{{*/
  111. {
  112. debReleaseIndex const * const deb = dynamic_cast<debReleaseIndex const *>(this);
  113. if (deb != NULL)
  114. return deb->IsArchitectureAllSupportedFor(target);
  115. return true;
  116. }
  117. /*}}}*/