You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

170 lines
5.8 KiB

  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. class metaIndexPrivate /*{{{*/
  10. {
  11. public:
  12. std::string Origin;
  13. std::string Label;
  14. std::string Version;
  15. signed short DefaultPin;
  16. std::string ReleaseNotes;
  17. };
  18. /*}}}*/
  19. std::string metaIndex::Describe() const
  20. {
  21. return "Release";
  22. }
  23. pkgCache::RlsFileIterator metaIndex::FindInCache(pkgCache &Cache, bool const) const
  24. {
  25. return pkgCache::RlsFileIterator(Cache);
  26. }
  27. bool metaIndex::Merge(pkgCacheGenerator &Gen,OpProgress *) const
  28. {
  29. return Gen.SelectReleaseFile("", "");
  30. }
  31. metaIndex::metaIndex(std::string const &URI, std::string const &Dist,
  32. char const * const Type)
  33. : d(new metaIndexPrivate()), Indexes(NULL), Type(Type), URI(URI), Dist(Dist), Trusted(TRI_UNSET),
  34. Date(0), ValidUntil(0), SupportsAcquireByHash(false), LoadedSuccessfully(TRI_UNSET)
  35. {
  36. /* nothing */
  37. }
  38. metaIndex::~metaIndex()
  39. {
  40. if (Indexes != 0)
  41. {
  42. for (std::vector<pkgIndexFile *>::iterator I = (*Indexes).begin();
  43. I != (*Indexes).end(); ++I)
  44. delete *I;
  45. delete Indexes;
  46. }
  47. for (auto const &E: Entries)
  48. delete E.second;
  49. delete d;
  50. }
  51. // one line Getters for public fields /*{{{*/
  52. APT_PURE std::string metaIndex::GetURI() const { return URI; }
  53. APT_PURE std::string metaIndex::GetDist() const { return Dist; }
  54. APT_PURE const char* metaIndex::GetType() const { return Type; }
  55. APT_PURE metaIndex::TriState metaIndex::GetTrusted() const { return Trusted; }
  56. APT_PURE std::string metaIndex::GetSignedBy() const { return SignedBy; }
  57. APT_PURE std::string metaIndex::GetOrigin() const { return d->Origin; }
  58. APT_PURE std::string metaIndex::GetLabel() const { return d->Label; }
  59. APT_PURE std::string metaIndex::GetVersion() const { return d->Version; }
  60. APT_PURE std::string metaIndex::GetCodename() const { return Codename; }
  61. APT_PURE std::string metaIndex::GetSuite() const { return Suite; }
  62. APT_PURE std::string metaIndex::GetReleaseNotes() const { return d->ReleaseNotes; }
  63. APT_PURE signed short metaIndex::GetDefaultPin() const { return d->DefaultPin; }
  64. APT_PURE bool metaIndex::GetSupportsAcquireByHash() const { return SupportsAcquireByHash; }
  65. APT_PURE time_t metaIndex::GetValidUntil() const { return ValidUntil; }
  66. APT_PURE time_t metaIndex::GetDate() const { return this->Date; }
  67. APT_PURE metaIndex::TriState metaIndex::GetLoadedSuccessfully() const { return LoadedSuccessfully; }
  68. APT_PURE std::string metaIndex::GetExpectedDist() const { return Dist; }
  69. /*}}}*/
  70. bool metaIndex::CheckDist(string const &MaybeDist) const /*{{{*/
  71. {
  72. if (MaybeDist.empty() || this->Codename == MaybeDist || this->Suite == MaybeDist)
  73. return true;
  74. std::string Transformed = MaybeDist;
  75. if (Transformed == "../project/experimental")
  76. Transformed = "experimental";
  77. auto const pos = Transformed.rfind('/');
  78. if (pos != string::npos)
  79. Transformed = Transformed.substr(0, pos);
  80. if (Transformed == ".")
  81. Transformed.clear();
  82. return Transformed.empty() || this->Codename == Transformed || this->Suite == Transformed;
  83. }
  84. /*}}}*/
  85. APT_PURE metaIndex::checkSum *metaIndex::Lookup(string const &MetaKey) const /*{{{*/
  86. {
  87. std::map<std::string, metaIndex::checkSum* >::const_iterator sum = Entries.find(MetaKey);
  88. if (sum == Entries.end())
  89. return NULL;
  90. return sum->second;
  91. }
  92. /*}}}*/
  93. APT_PURE bool metaIndex::Exists(string const &MetaKey) const /*{{{*/
  94. {
  95. return Entries.find(MetaKey) != Entries.end();
  96. }
  97. /*}}}*/
  98. std::vector<std::string> metaIndex::MetaKeys() const /*{{{*/
  99. {
  100. std::vector<std::string> keys;
  101. std::map<string,checkSum *>::const_iterator I = Entries.begin();
  102. while(I != Entries.end()) {
  103. keys.push_back((*I).first);
  104. ++I;
  105. }
  106. return keys;
  107. }
  108. /*}}}*/
  109. void metaIndex::swapLoad(metaIndex * const OldMetaIndex) /*{{{*/
  110. {
  111. std::swap(SignedBy, OldMetaIndex->SignedBy);
  112. std::swap(Suite, OldMetaIndex->Suite);
  113. std::swap(Codename, OldMetaIndex->Codename);
  114. std::swap(Date, OldMetaIndex->Date);
  115. std::swap(ValidUntil, OldMetaIndex->ValidUntil);
  116. std::swap(SupportsAcquireByHash, OldMetaIndex->SupportsAcquireByHash);
  117. std::swap(Entries, OldMetaIndex->Entries);
  118. std::swap(LoadedSuccessfully, OldMetaIndex->LoadedSuccessfully);
  119. OldMetaIndex->SetOrigin(d->Origin);
  120. OldMetaIndex->SetLabel(d->Label);
  121. OldMetaIndex->SetVersion(d->Version);
  122. OldMetaIndex->SetDefaultPin(d->DefaultPin);
  123. }
  124. /*}}}*/
  125. bool metaIndex::IsArchitectureSupported(std::string const &arch) const /*{{{*/
  126. {
  127. debReleaseIndex const * const deb = dynamic_cast<debReleaseIndex const *>(this);
  128. if (deb != NULL)
  129. return deb->IsArchitectureSupported(arch);
  130. return true;
  131. }
  132. /*}}}*/
  133. bool metaIndex::IsArchitectureAllSupportedFor(IndexTarget const &target) const/*{{{*/
  134. {
  135. debReleaseIndex const * const deb = dynamic_cast<debReleaseIndex const *>(this);
  136. if (deb != NULL)
  137. return deb->IsArchitectureAllSupportedFor(target);
  138. return true;
  139. }
  140. /*}}}*/
  141. bool metaIndex::HasSupportForComponent(std::string const &component) const/*{{{*/
  142. {
  143. debReleaseIndex const * const deb = dynamic_cast<debReleaseIndex const *>(this);
  144. if (deb != NULL)
  145. return deb->HasSupportForComponent(component);
  146. return true;
  147. }
  148. /*}}}*/
  149. void metaIndex::SetOrigin(std::string const &origin) { d->Origin = origin; }
  150. void metaIndex::SetLabel(std::string const &label) { d->Label = label; }
  151. void metaIndex::SetVersion(std::string const &version) { d->Version = version; }
  152. void metaIndex::SetDefaultPin(signed short const defaultpin) { d->DefaultPin = defaultpin; }
  153. void metaIndex::SetReleaseNotes(std::string const &notes) { d->ReleaseNotes = notes; }