debmetaindex.cc 8.4 KB

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