debmetaindex.cc 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. // ijones, walters
  2. #ifdef __GNUG__
  3. #pragma implementation "apt-pkg/debmetaindex.h"
  4. #endif
  5. #include <apt-pkg/debmetaindex.h>
  6. #include <apt-pkg/debindexfile.h>
  7. #include <apt-pkg/strutl.h>
  8. #include <apt-pkg/acquire-item.h>
  9. #include <apt-pkg/configuration.h>
  10. #include <apt-pkg/error.h>
  11. using namespace std;
  12. string debReleaseIndex::Info(const char *Type, const string Section) const
  13. {
  14. string Info = ::URI::SiteOnly(URI) + ' ';
  15. if (Dist[Dist.size() - 1] == '/')
  16. {
  17. if (Dist != "/")
  18. Info += Dist;
  19. }
  20. else
  21. Info += Dist + '/' + Section;
  22. Info += " ";
  23. Info += Type;
  24. return Info;
  25. }
  26. string debReleaseIndex::MetaIndexInfo(const char *Type) const
  27. {
  28. string Info = ::URI::SiteOnly(URI) + ' ';
  29. if (Dist[Dist.size() - 1] == '/')
  30. {
  31. if (Dist != "/")
  32. Info += Dist;
  33. }
  34. else
  35. Info += Dist;
  36. Info += " ";
  37. Info += Type;
  38. return Info;
  39. }
  40. string debReleaseIndex::MetaIndexFile(const char *Type) const
  41. {
  42. return _config->FindDir("Dir::State::lists") +
  43. URItoFileName(MetaIndexURI(Type));
  44. }
  45. string debReleaseIndex::MetaIndexURI(const char *Type) const
  46. {
  47. string Res;
  48. if (Dist == "/")
  49. Res = URI;
  50. else if (Dist[Dist.size()-1] == '/')
  51. Res = URI + Dist;
  52. else
  53. Res = URI + "dists/" + Dist + "/";
  54. Res += Type;
  55. return Res;
  56. }
  57. string debReleaseIndex::IndexURISuffix(const char *Type, const string Section) const
  58. {
  59. string Res ="";
  60. if (Dist[Dist.size() - 1] != '/')
  61. Res += Section + "/binary-" + _config->Find("APT::Architecture") + '/';
  62. return Res + Type;
  63. }
  64. string debReleaseIndex::IndexURI(const char *Type, const string Section) const
  65. {
  66. if (Dist[Dist.size() - 1] == '/')
  67. {
  68. string Res;
  69. if (Dist != "/")
  70. Res = URI + Dist;
  71. else
  72. Res = URI;
  73. return Res + Type;
  74. }
  75. else
  76. return URI + "dists/" + Dist + '/' + IndexURISuffix(Type, Section);
  77. }
  78. string debReleaseIndex::SourceIndexURISuffix(const char *Type, const string Section) const
  79. {
  80. string Res ="";
  81. if (Dist[Dist.size() - 1] != '/')
  82. Res += Section + "/source/";
  83. return Res + Type;
  84. }
  85. string debReleaseIndex::SourceIndexURI(const char *Type, const string Section) const
  86. {
  87. string Res;
  88. if (Dist[Dist.size() - 1] == '/')
  89. {
  90. if (Dist != "/")
  91. Res = URI + Dist;
  92. else
  93. Res = URI;
  94. return Res + Type;
  95. }
  96. else
  97. return URI + "dists/" + Dist + "/" + SourceIndexURISuffix(Type, Section);
  98. }
  99. debReleaseIndex::debReleaseIndex(string URI,string Dist)
  100. {
  101. this->URI = URI;
  102. this->Dist = Dist;
  103. this->Indexes = NULL;
  104. this->Type = "deb";
  105. }
  106. vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const
  107. {
  108. vector <struct IndexTarget *>* IndexTargets = new vector <IndexTarget *>;
  109. for (vector <const debSectionEntry *>::const_iterator I = SectionEntries.begin();
  110. I != SectionEntries.end();
  111. I++)
  112. {
  113. IndexTarget * Target = new IndexTarget();
  114. Target->ShortDesc = (*I)->IsSrc ? "Sources" : "Packages";
  115. Target->MetaKey
  116. = (*I)->IsSrc ? SourceIndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section)
  117. : IndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section);
  118. Target->URI
  119. = (*I)->IsSrc ? SourceIndexURI(Target->ShortDesc.c_str(), (*I)->Section)
  120. : IndexURI(Target->ShortDesc.c_str(), (*I)->Section);
  121. Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section);
  122. IndexTargets->push_back (Target);
  123. }
  124. return IndexTargets;
  125. }
  126. /*}}}*/
  127. bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool GetAll) const
  128. {
  129. // special case for --print-uris
  130. if (GetAll) {
  131. vector <struct IndexTarget *> *targets = ComputeIndexTargets();
  132. for (vector <struct IndexTarget*>::const_iterator Target = targets->begin(); Target != targets->end(); Target++) {
  133. new pkgAcqIndex(Owner, (*Target)->URI, (*Target)->Description,
  134. (*Target)->ShortDesc, "");
  135. }
  136. }
  137. new pkgAcqMetaSig(Owner, MetaIndexURI("Release.gpg"),
  138. MetaIndexInfo("Release.gpg"), "Release.gpg",
  139. MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
  140. ComputeIndexTargets(),
  141. new indexRecords (Dist));
  142. // Queue the translations
  143. for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
  144. I != SectionEntries.end(); I++) {
  145. debTranslationsIndex i = debTranslationsIndex(URI,Dist,(*I)->Section);
  146. i.GetIndexes(Owner);
  147. }
  148. return true;
  149. }
  150. bool debReleaseIndex::IsTrusted() const
  151. {
  152. string VerifiedSigFile = _config->FindDir("Dir::State::lists") +
  153. URItoFileName(MetaIndexURI("Release")) + ".gpg";
  154. if (FileExists(VerifiedSigFile))
  155. return true;
  156. return false;
  157. }
  158. vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
  159. {
  160. if (Indexes != NULL)
  161. return Indexes;
  162. Indexes = new vector <pkgIndexFile*>;
  163. for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
  164. I != SectionEntries.end(); I++) {
  165. if ((*I)->IsSrc)
  166. Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
  167. else
  168. {
  169. Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted()));
  170. Indexes->push_back(new debTranslationsIndex(URI, Dist, (*I)->Section));
  171. }
  172. }
  173. return Indexes;
  174. }
  175. void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry)
  176. {
  177. SectionEntries.push_back(Entry);
  178. }
  179. debReleaseIndex::debSectionEntry::debSectionEntry (string Section, bool IsSrc): Section(Section)
  180. {
  181. this->IsSrc = IsSrc;
  182. }
  183. class debSLTypeDebian : public pkgSourceList::Type
  184. {
  185. protected:
  186. bool CreateItemInternal(vector<metaIndex *> &List,string URI,
  187. string Dist,string Section,
  188. bool IsSrc) const
  189. {
  190. for (vector<metaIndex *>::const_iterator I = List.begin();
  191. I != List.end(); I++)
  192. {
  193. // This check insures that there will be only one Release file
  194. // queued for all the Packages files and Sources files it
  195. // corresponds to.
  196. if ((*I)->GetType() == "deb")
  197. {
  198. debReleaseIndex *Deb = (debReleaseIndex *) (*I);
  199. // This check insures that there will be only one Release file
  200. // queued for all the Packages files and Sources files it
  201. // corresponds to.
  202. if (Deb->GetURI() == URI && Deb->GetDist() == Dist)
  203. {
  204. Deb->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section, IsSrc));
  205. return true;
  206. }
  207. }
  208. }
  209. // No currently created Release file indexes this entry, so we create a new one.
  210. // XXX determine whether this release is trusted or not
  211. debReleaseIndex *Deb = new debReleaseIndex(URI,Dist);
  212. Deb->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section, IsSrc));
  213. List.push_back(Deb);
  214. return true;
  215. }
  216. };
  217. class debSLTypeDeb : public debSLTypeDebian
  218. {
  219. public:
  220. bool CreateItem(vector<metaIndex *> &List,string URI,
  221. string Dist,string Section) const
  222. {
  223. return CreateItemInternal(List, URI, Dist, Section, false);
  224. }
  225. debSLTypeDeb()
  226. {
  227. Name = "deb";
  228. Label = "Standard Debian binary tree";
  229. }
  230. };
  231. class debSLTypeDebSrc : public debSLTypeDebian
  232. {
  233. public:
  234. bool CreateItem(vector<metaIndex *> &List,string URI,
  235. string Dist,string Section) const
  236. {
  237. return CreateItemInternal(List, URI, Dist, Section, true);
  238. }
  239. debSLTypeDebSrc()
  240. {
  241. Name = "deb-src";
  242. Label = "Standard Debian source tree";
  243. }
  244. };
  245. debSLTypeDeb _apt_DebType;
  246. debSLTypeDebSrc _apt_DebSrcType;