debmetaindex.cc 7.4 KB

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