metaindex.cc 3.3 KB

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