debmetaindex.cc 7.0 KB

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