debmetaindex.cc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. return true;
  143. }
  144. bool debReleaseIndex::IsTrusted() const
  145. {
  146. string VerifiedSigFile = _config->FindDir("Dir::State::lists") +
  147. URItoFileName(MetaIndexURI("Release")) + ".gpg";
  148. if (FileExists(VerifiedSigFile))
  149. return true;
  150. return false;
  151. }
  152. vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
  153. {
  154. if (Indexes != NULL)
  155. return Indexes;
  156. Indexes = new vector <pkgIndexFile*>;
  157. for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
  158. I != SectionEntries.end(); I++) {
  159. if ((*I)->IsSrc)
  160. Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
  161. else
  162. Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted()));
  163. Indexes->push_back(new debTranslationsIndex(URI,Dist,(*I)->Section));
  164. }
  165. return Indexes;
  166. }
  167. void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry)
  168. {
  169. SectionEntries.push_back(Entry);
  170. }
  171. debReleaseIndex::debSectionEntry::debSectionEntry (string Section, bool IsSrc): Section(Section)
  172. {
  173. this->IsSrc = IsSrc;
  174. }
  175. class debSLTypeDebian : public pkgSourceList::Type
  176. {
  177. protected:
  178. bool CreateItemInternal(vector<metaIndex *> &List,string URI,
  179. string Dist,string Section,
  180. bool IsSrc) const
  181. {
  182. for (vector<metaIndex *>::const_iterator I = List.begin();
  183. I != List.end(); I++)
  184. {
  185. // This check insures that there will be only one Release file
  186. // queued for all the Packages files and Sources files it
  187. // corresponds to.
  188. if ((*I)->GetType() == "deb")
  189. {
  190. debReleaseIndex *Deb = (debReleaseIndex *) (*I);
  191. // This check insures that there will be only one Release file
  192. // queued for all the Packages files and Sources files it
  193. // corresponds to.
  194. if (Deb->GetURI() == URI && Deb->GetDist() == Dist)
  195. {
  196. Deb->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section, IsSrc));
  197. return true;
  198. }
  199. }
  200. }
  201. // No currently created Release file indexes this entry, so we create a new one.
  202. // XXX determine whether this release is trusted or not
  203. debReleaseIndex *Deb = new debReleaseIndex(URI,Dist);
  204. Deb->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section, IsSrc));
  205. List.push_back(Deb);
  206. return true;
  207. }
  208. };
  209. class debSLTypeDeb : public debSLTypeDebian
  210. {
  211. public:
  212. bool CreateItem(vector<metaIndex *> &List,string URI,
  213. string Dist,string Section) const
  214. {
  215. return CreateItemInternal(List, URI, Dist, Section, false);
  216. }
  217. debSLTypeDeb()
  218. {
  219. Name = "deb";
  220. Label = "Standard Debian binary tree";
  221. }
  222. };
  223. class debSLTypeDebSrc : public debSLTypeDebian
  224. {
  225. public:
  226. bool CreateItem(vector<metaIndex *> &List,string URI,
  227. string Dist,string Section) const
  228. {
  229. return CreateItemInternal(List, URI, Dist, Section, true);
  230. }
  231. debSLTypeDebSrc()
  232. {
  233. Name = "deb-src";
  234. Label = "Standard Debian source tree";
  235. }
  236. };
  237. debSLTypeDeb _apt_DebType;
  238. debSLTypeDebSrc _apt_DebSrcType;