metaindex.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. return;
  31. for (std::vector<pkgIndexFile *>::iterator I = (*Indexes).begin();
  32. I != (*Indexes).end(); ++I)
  33. delete *I;
  34. delete Indexes;
  35. }
  36. // one line Getters for public fields /*{{{*/
  37. APT_PURE std::string metaIndex::GetURI() const { return URI; }
  38. APT_PURE std::string metaIndex::GetDist() const { return Dist; }
  39. APT_PURE const char* metaIndex::GetType() const { return Type; }
  40. APT_PURE metaIndex::TriState metaIndex::GetTrusted() const { return Trusted; }
  41. APT_PURE std::string metaIndex::GetSignedBy() const { return SignedBy; }
  42. APT_PURE std::string metaIndex::GetCodename() const { return Codename; }
  43. APT_PURE std::string metaIndex::GetSuite() const { return Suite; }
  44. APT_PURE bool metaIndex::GetSupportsAcquireByHash() const { return SupportsAcquireByHash; }
  45. APT_PURE time_t metaIndex::GetValidUntil() const { return ValidUntil; }
  46. APT_PURE time_t metaIndex::GetDate() const { return this->Date; }
  47. APT_PURE metaIndex::TriState metaIndex::GetLoadedSuccessfully() const { return LoadedSuccessfully; }
  48. APT_PURE bool metaIndex::CheckDist(string const &MaybeDist) const
  49. {
  50. return (this->Codename == MaybeDist
  51. || this->Suite == MaybeDist);
  52. }
  53. APT_PURE std::string metaIndex::GetExpectedDist() const
  54. {
  55. // TODO: Used to be an explicit value set in the constructor
  56. return "";
  57. }
  58. /*}}}*/
  59. APT_PURE metaIndex::checkSum *metaIndex::Lookup(string const &MetaKey) const /*{{{*/
  60. {
  61. std::map<std::string, metaIndex::checkSum* >::const_iterator sum = Entries.find(MetaKey);
  62. if (sum == Entries.end())
  63. return NULL;
  64. return sum->second;
  65. }
  66. /*}}}*/
  67. APT_PURE bool metaIndex::Exists(string const &MetaKey) const /*{{{*/
  68. {
  69. return Entries.find(MetaKey) != Entries.end();
  70. }
  71. /*}}}*/
  72. std::vector<std::string> metaIndex::MetaKeys() const /*{{{*/
  73. {
  74. std::vector<std::string> keys;
  75. std::map<string,checkSum *>::const_iterator I = Entries.begin();
  76. while(I != Entries.end()) {
  77. keys.push_back((*I).first);
  78. ++I;
  79. }
  80. return keys;
  81. }
  82. /*}}}*/
  83. void metaIndex::swapLoad(metaIndex * const OldMetaIndex) /*{{{*/
  84. {
  85. std::swap(Entries, OldMetaIndex->Entries);
  86. std::swap(Date, OldMetaIndex->Date);
  87. std::swap(ValidUntil, OldMetaIndex->ValidUntil);
  88. std::swap(SupportsAcquireByHash, OldMetaIndex->SupportsAcquireByHash);
  89. std::swap(LoadedSuccessfully, OldMetaIndex->LoadedSuccessfully);
  90. }
  91. /*}}}*/