metaindex.cc 3.3 KB

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