debmetaindex.cc 7.1 KB

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