debmetaindex.cc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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, HashString());
  132. }
  133. // this is normally created in pkgAcqMetaSig, but if we run
  134. // in --print-uris mode, we add it here
  135. new pkgAcqMetaIndex(Owner, MetaIndexURI("Release"),
  136. MetaIndexInfo("Release"), "Release",
  137. MetaIndexURI("Release.gpg"),
  138. ComputeIndexTargets(),
  139. new indexRecords (Dist));
  140. }
  141. new pkgAcqMetaSig(Owner, MetaIndexURI("Release.gpg"),
  142. MetaIndexInfo("Release.gpg"), "Release.gpg",
  143. MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
  144. ComputeIndexTargets(),
  145. new indexRecords (Dist));
  146. // Queue the translations
  147. for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
  148. I != SectionEntries.end(); I++) {
  149. if((*I)->IsSrc)
  150. continue;
  151. debTranslationsIndex i = debTranslationsIndex(URI,Dist,(*I)->Section);
  152. i.GetIndexes(Owner);
  153. }
  154. return true;
  155. }
  156. bool debReleaseIndex::IsTrusted() const
  157. {
  158. string VerifiedSigFile = _config->FindDir("Dir::State::lists") +
  159. URItoFileName(MetaIndexURI("Release")) + ".gpg";
  160. if(_config->FindB("APT::Authentication::TrustCDROM", false))
  161. if(URI.substr(0,strlen("cdrom:")) == "cdrom:")
  162. return true;
  163. if (FileExists(VerifiedSigFile))
  164. return true;
  165. return false;
  166. }
  167. vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
  168. {
  169. if (Indexes != NULL)
  170. return Indexes;
  171. Indexes = new vector <pkgIndexFile*>;
  172. for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
  173. I != SectionEntries.end(); I++) {
  174. if ((*I)->IsSrc)
  175. Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
  176. else
  177. {
  178. Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted()));
  179. Indexes->push_back(new debTranslationsIndex(URI, Dist, (*I)->Section));
  180. }
  181. }
  182. return Indexes;
  183. }
  184. void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry)
  185. {
  186. SectionEntries.push_back(Entry);
  187. }
  188. debReleaseIndex::debSectionEntry::debSectionEntry (string Section, bool IsSrc): Section(Section)
  189. {
  190. this->IsSrc = IsSrc;
  191. }
  192. class debSLTypeDebian : public pkgSourceList::Type
  193. {
  194. protected:
  195. bool CreateItemInternal(vector<metaIndex *> &List,string URI,
  196. string Dist,string Section,
  197. bool IsSrc) const
  198. {
  199. for (vector<metaIndex *>::const_iterator I = List.begin();
  200. I != List.end(); I++)
  201. {
  202. // This check insures that there will be only one Release file
  203. // queued for all the Packages files and Sources files it
  204. // corresponds to.
  205. if (strcmp((*I)->GetType(), "deb") == 0)
  206. {
  207. debReleaseIndex *Deb = (debReleaseIndex *) (*I);
  208. // This check insures that there will be only one Release file
  209. // queued for all the Packages files and Sources files it
  210. // corresponds to.
  211. if (Deb->GetURI() == URI && Deb->GetDist() == Dist)
  212. {
  213. Deb->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section, IsSrc));
  214. return true;
  215. }
  216. }
  217. }
  218. // No currently created Release file indexes this entry, so we create a new one.
  219. // XXX determine whether this release is trusted or not
  220. debReleaseIndex *Deb = new debReleaseIndex(URI,Dist);
  221. Deb->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section, IsSrc));
  222. List.push_back(Deb);
  223. return true;
  224. }
  225. };
  226. class debSLTypeDeb : public debSLTypeDebian
  227. {
  228. public:
  229. bool CreateItem(vector<metaIndex *> &List,string URI,
  230. string Dist,string Section) const
  231. {
  232. return CreateItemInternal(List, URI, Dist, Section, false);
  233. }
  234. debSLTypeDeb()
  235. {
  236. Name = "deb";
  237. Label = "Standard Debian binary tree";
  238. }
  239. };
  240. class debSLTypeDebSrc : public debSLTypeDebian
  241. {
  242. public:
  243. bool CreateItem(vector<metaIndex *> &List,string URI,
  244. string Dist,string Section) const
  245. {
  246. return CreateItemInternal(List, URI, Dist, Section, true);
  247. }
  248. debSLTypeDebSrc()
  249. {
  250. Name = "deb-src";
  251. Label = "Standard Debian source tree";
  252. }
  253. };
  254. debSLTypeDeb _apt_DebType;
  255. debSLTypeDebSrc _apt_DebSrcType;