debmetaindex.cc 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. #include <config.h>
  2. #include <apt-pkg/error.h>
  3. #include <apt-pkg/debmetaindex.h>
  4. #include <apt-pkg/debindexfile.h>
  5. #include <apt-pkg/strutl.h>
  6. #include <apt-pkg/fileutl.h>
  7. #include <apt-pkg/acquire-item.h>
  8. #include <apt-pkg/configuration.h>
  9. #include <apt-pkg/aptconfiguration.h>
  10. #include <apt-pkg/sourcelist.h>
  11. #include <apt-pkg/hashes.h>
  12. #include <apt-pkg/metaindex.h>
  13. #include <apt-pkg/pkgcachegen.h>
  14. #include <apt-pkg/tagfile.h>
  15. #include <apt-pkg/gpgv.h>
  16. #include <apt-pkg/macros.h>
  17. #include <map>
  18. #include <string>
  19. #include <utility>
  20. #include <vector>
  21. #include <algorithm>
  22. #include <sstream>
  23. #include <sys/stat.h>
  24. #include <string.h>
  25. #include <apti18n.h>
  26. class APT_HIDDEN debReleaseIndexPrivate /*{{{*/
  27. {
  28. public:
  29. struct APT_HIDDEN debSectionEntry
  30. {
  31. std::string const sourcesEntry;
  32. std::string const Name;
  33. std::vector<std::string> const Targets;
  34. std::vector<std::string> const Architectures;
  35. std::vector<std::string> const Languages;
  36. bool const UsePDiffs;
  37. std::string const UseByHash;
  38. };
  39. std::vector<debSectionEntry> DebEntries;
  40. std::vector<debSectionEntry> DebSrcEntries;
  41. metaIndex::TriState CheckValidUntil;
  42. time_t ValidUntilMin;
  43. time_t ValidUntilMax;
  44. std::vector<std::string> Architectures;
  45. std::vector<std::string> NoSupportForAll;
  46. debReleaseIndexPrivate() : CheckValidUntil(metaIndex::TRI_UNSET), ValidUntilMin(0), ValidUntilMax(0) {}
  47. };
  48. /*}}}*/
  49. // ReleaseIndex::MetaIndex* - display helpers /*{{{*/
  50. std::string debReleaseIndex::MetaIndexInfo(const char *Type) const
  51. {
  52. std::string Info = ::URI::ArchiveOnly(URI) + ' ';
  53. if (Dist[Dist.size() - 1] == '/')
  54. {
  55. if (Dist != "/")
  56. Info += Dist;
  57. }
  58. else
  59. Info += Dist;
  60. Info += " ";
  61. Info += Type;
  62. return Info;
  63. }
  64. std::string debReleaseIndex::Describe() const
  65. {
  66. return MetaIndexInfo("Release");
  67. }
  68. std::string debReleaseIndex::MetaIndexFile(const char *Type) const
  69. {
  70. return _config->FindDir("Dir::State::lists") +
  71. URItoFileName(MetaIndexURI(Type));
  72. }
  73. std::string debReleaseIndex::MetaIndexURI(const char *Type) const
  74. {
  75. std::string Res;
  76. if (Dist == "/")
  77. Res = URI;
  78. else if (Dist[Dist.size()-1] == '/')
  79. Res = URI + Dist;
  80. else
  81. Res = URI + "dists/" + Dist + "/";
  82. Res += Type;
  83. return Res;
  84. }
  85. /*}}}*/
  86. // ReleaseIndex Con- and Destructors /*{{{*/
  87. debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist) :
  88. metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate())
  89. {}
  90. debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const pTrusted) :
  91. metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate())
  92. {
  93. Trusted = pTrusted ? TRI_YES : TRI_NO;
  94. }
  95. debReleaseIndex::~debReleaseIndex() {
  96. if (d != NULL)
  97. delete d;
  98. }
  99. /*}}}*/
  100. // ReleaseIndex::GetIndexTargets /*{{{*/
  101. static void GetIndexTargetsFor(char const * const Type, std::string const &URI, std::string const &Dist,
  102. std::vector<debReleaseIndexPrivate::debSectionEntry> const &entries,
  103. std::vector<IndexTarget> &IndexTargets)
  104. {
  105. bool const flatArchive = (Dist[Dist.length() - 1] == '/');
  106. std::string baseURI = URI;
  107. if (flatArchive)
  108. {
  109. if (Dist != "/")
  110. baseURI += Dist;
  111. }
  112. else
  113. baseURI += "dists/" + Dist + "/";
  114. std::string const Release = (Dist == "/") ? "" : Dist;
  115. std::string const Site = ::URI::ArchiveOnly(URI);
  116. std::string DefCompressionTypes;
  117. {
  118. std::vector<std::string> types = APT::Configuration::getCompressionTypes();
  119. if (types.empty() == false)
  120. {
  121. std::ostringstream os;
  122. std::copy(types.begin(), types.end()-1, std::ostream_iterator<std::string>(os, " "));
  123. os << *types.rbegin();
  124. DefCompressionTypes = os.str();
  125. }
  126. }
  127. std::string DefKeepCompressedAs;
  128. {
  129. std::vector<APT::Configuration::Compressor> comps = APT::Configuration::getCompressors();
  130. if (comps.empty() == false)
  131. {
  132. std::sort(comps.begin(), comps.end(),
  133. [](APT::Configuration::Compressor const &a, APT::Configuration::Compressor const &b) { return a.Cost < b.Cost; });
  134. std::ostringstream os;
  135. for (auto const &c : comps)
  136. if (c.Cost != 0)
  137. os << c.Extension.substr(1) << ' ';
  138. DefKeepCompressedAs = os.str();
  139. }
  140. DefKeepCompressedAs += "uncompressed";
  141. }
  142. std::vector<std::string> const NativeArchs = { _config->Find("APT::Architecture"), "all" };
  143. bool const GzipIndex = _config->FindB("Acquire::GzipIndexes", false);
  144. for (std::vector<debReleaseIndexPrivate::debSectionEntry>::const_iterator E = entries.begin(); E != entries.end(); ++E)
  145. {
  146. for (std::vector<std::string>::const_iterator T = E->Targets.begin(); T != E->Targets.end(); ++T)
  147. {
  148. #define APT_T_CONFIG_STR(X, Y) _config->Find(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X), (Y))
  149. #define APT_T_CONFIG_BOOL(X, Y) _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X), (Y))
  150. std::string const tplMetaKey = APT_T_CONFIG_STR(flatArchive ? "flatMetaKey" : "MetaKey", "");
  151. std::string const tplShortDesc = APT_T_CONFIG_STR("ShortDescription", "");
  152. std::string const tplLongDesc = "$(SITE) " + APT_T_CONFIG_STR(flatArchive ? "flatDescription" : "Description", "");
  153. std::string const tplIdentifier = APT_T_CONFIG_STR("Identifier", *T);
  154. bool const IsOptional = APT_T_CONFIG_BOOL("Optional", true);
  155. bool const KeepCompressed = APT_T_CONFIG_BOOL("KeepCompressed", GzipIndex);
  156. bool const DefaultEnabled = APT_T_CONFIG_BOOL("DefaultEnabled", true);
  157. bool const UsePDiffs = APT_T_CONFIG_BOOL("PDiffs", E->UsePDiffs);
  158. std::string const UseByHash = APT_T_CONFIG_STR("By-Hash", E->UseByHash);
  159. std::string const CompressionTypes = APT_T_CONFIG_STR("CompressionTypes", DefCompressionTypes);
  160. std::string KeepCompressedAs = APT_T_CONFIG_STR("KeepCompressedAs", "");
  161. std::string const FallbackOf = APT_T_CONFIG_STR("Fallback-Of", "");
  162. #undef APT_T_CONFIG_BOOL
  163. #undef APT_T_CONFIG_STR
  164. if (tplMetaKey.empty())
  165. continue;
  166. if (KeepCompressedAs.empty())
  167. KeepCompressedAs = DefKeepCompressedAs;
  168. else
  169. {
  170. std::vector<std::string> const defKeep = VectorizeString(DefKeepCompressedAs, ' ');
  171. std::vector<std::string> const valKeep = VectorizeString(KeepCompressedAs, ' ');
  172. std::vector<std::string> keep;
  173. for (auto const &val : valKeep)
  174. {
  175. if (val.empty())
  176. continue;
  177. if (std::find(defKeep.begin(), defKeep.end(), val) == defKeep.end())
  178. continue;
  179. keep.push_back(val);
  180. }
  181. if (std::find(keep.begin(), keep.end(), "uncompressed") == keep.end())
  182. keep.push_back("uncompressed");
  183. std::ostringstream os;
  184. std::copy(keep.begin(), keep.end()-1, std::ostream_iterator<std::string>(os, " "));
  185. os << *keep.rbegin();
  186. KeepCompressedAs = os.str();
  187. }
  188. for (std::vector<std::string>::const_iterator L = E->Languages.begin(); L != E->Languages.end(); ++L)
  189. {
  190. if (*L == "none" && tplMetaKey.find("$(LANGUAGE)") != std::string::npos)
  191. continue;
  192. for (std::vector<std::string>::const_iterator A = E->Architectures.begin(); A != E->Architectures.end(); ++A)
  193. {
  194. for (auto const &NativeArch: NativeArchs)
  195. {
  196. constexpr static auto BreakPoint = "$(NATIVE_ARCHITECTURE)";
  197. // available in templates
  198. std::map<std::string, std::string> Options;
  199. Options.insert(std::make_pair("SITE", Site));
  200. Options.insert(std::make_pair("RELEASE", Release));
  201. if (tplMetaKey.find("$(COMPONENT)") != std::string::npos)
  202. Options.insert(std::make_pair("COMPONENT", E->Name));
  203. if (tplMetaKey.find("$(LANGUAGE)") != std::string::npos)
  204. Options.insert(std::make_pair("LANGUAGE", *L));
  205. if (tplMetaKey.find("$(ARCHITECTURE)") != std::string::npos)
  206. Options.insert(std::make_pair("ARCHITECTURE", *A));
  207. else if (tplMetaKey.find("$(NATIVE_ARCHITECTURE)") != std::string::npos)
  208. Options.insert(std::make_pair("ARCHITECTURE", NativeArch));
  209. if (tplMetaKey.find("$(NATIVE_ARCHITECTURE)") != std::string::npos)
  210. Options.insert(std::make_pair("NATIVE_ARCHITECTURE", NativeArch));
  211. std::string MetaKey = tplMetaKey;
  212. std::string ShortDesc = tplShortDesc;
  213. std::string LongDesc = tplLongDesc;
  214. std::string Identifier = tplIdentifier;
  215. for (std::map<std::string, std::string>::const_iterator O = Options.begin(); O != Options.end(); ++O)
  216. {
  217. std::string const varname = "$(" + O->first + ")";
  218. MetaKey = SubstVar(MetaKey, varname, O->second);
  219. ShortDesc = SubstVar(ShortDesc, varname, O->second);
  220. LongDesc = SubstVar(LongDesc, varname, O->second);
  221. Identifier = SubstVar(Identifier, varname, O->second);
  222. }
  223. {
  224. auto const dup = std::find_if(IndexTargets.begin(), IndexTargets.end(), [&](IndexTarget const &IT) {
  225. return MetaKey == IT.MetaKey && baseURI == IT.Option(IndexTarget::BASE_URI) &&
  226. E->sourcesEntry == IT.Option(IndexTarget::SOURCESENTRY) && *T == IT.Option(IndexTarget::CREATED_BY);
  227. });
  228. if (dup != IndexTargets.end())
  229. {
  230. if (tplMetaKey.find(BreakPoint) == std::string::npos)
  231. break;
  232. continue;
  233. }
  234. }
  235. {
  236. auto const dup = std::find_if(IndexTargets.begin(), IndexTargets.end(), [&](IndexTarget const &IT) {
  237. return MetaKey == IT.MetaKey && baseURI == IT.Option(IndexTarget::BASE_URI) &&
  238. E->sourcesEntry == IT.Option(IndexTarget::SOURCESENTRY) && *T != IT.Option(IndexTarget::CREATED_BY);
  239. });
  240. if (dup != IndexTargets.end())
  241. {
  242. std::string const dupT = dup->Option(IndexTarget::CREATED_BY);
  243. std::string const dupEntry = dup->Option(IndexTarget::SOURCESENTRY);
  244. //TRANSLATOR: an identifier like Packages; Releasefile key indicating
  245. // a file like main/binary-amd64/Packages; another identifier like Contents;
  246. // filename and linenumber of the sources.list entry currently parsed
  247. _error->Warning(_("Target %s wants to acquire the same file (%s) as %s from source %s"),
  248. T->c_str(), MetaKey.c_str(), dupT.c_str(), dupEntry.c_str());
  249. if (tplMetaKey.find(BreakPoint) == std::string::npos)
  250. break;
  251. continue;
  252. }
  253. }
  254. {
  255. auto const dup = std::find_if(IndexTargets.begin(), IndexTargets.end(), [&](IndexTarget const &T) {
  256. return MetaKey == T.MetaKey && baseURI == T.Option(IndexTarget::BASE_URI) &&
  257. E->sourcesEntry != T.Option(IndexTarget::SOURCESENTRY);
  258. });
  259. if (dup != IndexTargets.end())
  260. {
  261. std::string const dupEntry = dup->Option(IndexTarget::SOURCESENTRY);
  262. //TRANSLATOR: an identifier like Packages; Releasefile key indicating
  263. // a file like main/binary-amd64/Packages; filename and linenumber of
  264. // two sources.list entries
  265. _error->Warning(_("Target %s (%s) is configured multiple times in %s and %s"),
  266. T->c_str(), MetaKey.c_str(), dupEntry.c_str(), E->sourcesEntry.c_str());
  267. if (tplMetaKey.find(BreakPoint) == std::string::npos)
  268. break;
  269. continue;
  270. }
  271. }
  272. // not available in templates, but in the indextarget
  273. Options.insert(std::make_pair("BASE_URI", baseURI));
  274. Options.insert(std::make_pair("REPO_URI", URI));
  275. Options.insert(std::make_pair("IDENTIFIER", Identifier));
  276. Options.insert(std::make_pair("TARGET_OF", Type));
  277. Options.insert(std::make_pair("CREATED_BY", *T));
  278. Options.insert(std::make_pair("FALLBACK_OF", FallbackOf));
  279. Options.insert(std::make_pair("PDIFFS", UsePDiffs ? "yes" : "no"));
  280. Options.insert(std::make_pair("BY_HASH", UseByHash));
  281. Options.insert(std::make_pair("DEFAULTENABLED", DefaultEnabled ? "yes" : "no"));
  282. Options.insert(std::make_pair("COMPRESSIONTYPES", CompressionTypes));
  283. Options.insert(std::make_pair("KEEPCOMPRESSEDAS", KeepCompressedAs));
  284. Options.insert(std::make_pair("SOURCESENTRY", E->sourcesEntry));
  285. bool IsOpt = IsOptional;
  286. if (IsOpt == false)
  287. {
  288. auto const arch = Options.find("ARCHITECTURE");
  289. if (arch != Options.end() && arch->second == "all")
  290. IsOpt = true;
  291. }
  292. IndexTarget Target(
  293. MetaKey,
  294. ShortDesc,
  295. LongDesc,
  296. Options.find("BASE_URI")->second + MetaKey,
  297. IsOpt,
  298. KeepCompressed,
  299. Options
  300. );
  301. IndexTargets.push_back(Target);
  302. if (tplMetaKey.find(BreakPoint) == std::string::npos)
  303. break;
  304. }
  305. if (tplMetaKey.find("$(ARCHITECTURE)") == std::string::npos)
  306. break;
  307. }
  308. if (tplMetaKey.find("$(LANGUAGE)") == std::string::npos)
  309. break;
  310. }
  311. }
  312. }
  313. }
  314. std::vector<IndexTarget> debReleaseIndex::GetIndexTargets() const
  315. {
  316. std::vector<IndexTarget> IndexTargets;
  317. GetIndexTargetsFor("deb-src", URI, Dist, d->DebSrcEntries, IndexTargets);
  318. GetIndexTargetsFor("deb", URI, Dist, d->DebEntries, IndexTargets);
  319. return IndexTargets;
  320. }
  321. /*}}}*/
  322. void debReleaseIndex::AddComponent(std::string const &sourcesEntry, /*{{{*/
  323. bool const isSrc, std::string const &Name,
  324. std::vector<std::string> const &Targets,
  325. std::vector<std::string> const &Architectures,
  326. std::vector<std::string> Languages,
  327. bool const usePDiffs, std::string const &useByHash)
  328. {
  329. if (Languages.empty() == true)
  330. Languages.push_back("none");
  331. debReleaseIndexPrivate::debSectionEntry const entry = {
  332. sourcesEntry, Name, Targets, Architectures, Languages, usePDiffs, useByHash
  333. };
  334. if (isSrc)
  335. d->DebSrcEntries.push_back(entry);
  336. else
  337. d->DebEntries.push_back(entry);
  338. }
  339. /*}}}*/
  340. bool debReleaseIndex::Load(std::string const &Filename, std::string * const ErrorText)/*{{{*/
  341. {
  342. LoadedSuccessfully = TRI_NO;
  343. FileFd Fd;
  344. if (OpenMaybeClearSignedFile(Filename, Fd) == false)
  345. return false;
  346. pkgTagFile TagFile(&Fd, Fd.Size());
  347. if (Fd.IsOpen() == false || Fd.Failed())
  348. {
  349. if (ErrorText != NULL)
  350. strprintf(*ErrorText, _("Unable to parse Release file %s"),Filename.c_str());
  351. return false;
  352. }
  353. pkgTagSection Section;
  354. const char *Start, *End;
  355. if (TagFile.Step(Section) == false)
  356. {
  357. if (ErrorText != NULL)
  358. strprintf(*ErrorText, _("No sections in Release file %s"), Filename.c_str());
  359. return false;
  360. }
  361. // FIXME: find better tag name
  362. SupportsAcquireByHash = Section.FindB("Acquire-By-Hash", false);
  363. Suite = Section.FindS("Suite");
  364. Codename = Section.FindS("Codename");
  365. {
  366. std::string const archs = Section.FindS("Architectures");
  367. if (archs.empty() == false)
  368. d->Architectures = VectorizeString(archs, ' ');
  369. }
  370. {
  371. std::string const targets = Section.FindS("No-Support-for-Architecture-all");
  372. if (targets.empty() == false)
  373. d->NoSupportForAll = VectorizeString(targets, ' ');
  374. }
  375. bool FoundHashSum = false;
  376. bool FoundStrongHashSum = false;
  377. auto const SupportedHashes = HashString::SupportedHashes();
  378. for (int i=0; SupportedHashes[i] != NULL; i++)
  379. {
  380. if (!Section.Find(SupportedHashes[i], Start, End))
  381. continue;
  382. std::string Name;
  383. std::string Hash;
  384. unsigned long long Size;
  385. while (Start < End)
  386. {
  387. if (!parseSumData(Start, End, Name, Hash, Size))
  388. return false;
  389. HashString const hs(SupportedHashes[i], Hash);
  390. if (Entries.find(Name) == Entries.end())
  391. {
  392. metaIndex::checkSum *Sum = new metaIndex::checkSum;
  393. Sum->MetaKeyFilename = Name;
  394. Sum->Size = Size;
  395. Sum->Hashes.FileSize(Size);
  396. APT_IGNORE_DEPRECATED(Sum->Hash = hs;)
  397. Entries[Name] = Sum;
  398. }
  399. Entries[Name]->Hashes.push_back(hs);
  400. FoundHashSum = true;
  401. if (FoundStrongHashSum == false && hs.usable() == true)
  402. FoundStrongHashSum = true;
  403. }
  404. }
  405. if(FoundHashSum == false)
  406. {
  407. if (ErrorText != NULL)
  408. strprintf(*ErrorText, _("No Hash entry in Release file %s"), Filename.c_str());
  409. return false;
  410. }
  411. if(FoundStrongHashSum == false)
  412. {
  413. if (ErrorText != NULL)
  414. strprintf(*ErrorText, _("No Hash entry in Release file %s which is considered strong enough for security purposes"), Filename.c_str());
  415. return false;
  416. }
  417. std::string const StrDate = Section.FindS("Date");
  418. if (RFC1123StrToTime(StrDate.c_str(), Date) == false)
  419. {
  420. _error->Warning( _("Invalid '%s' entry in Release file %s"), "Date", Filename.c_str());
  421. Date = 0;
  422. }
  423. bool CheckValidUntil = _config->FindB("Acquire::Check-Valid-Until", true);
  424. if (d->CheckValidUntil == metaIndex::TRI_NO)
  425. CheckValidUntil = false;
  426. else if (d->CheckValidUntil == metaIndex::TRI_YES)
  427. CheckValidUntil = true;
  428. if (CheckValidUntil == true)
  429. {
  430. std::string const Label = Section.FindS("Label");
  431. std::string const StrValidUntil = Section.FindS("Valid-Until");
  432. // if we have a Valid-Until header in the Release file, use it as default
  433. if (StrValidUntil.empty() == false)
  434. {
  435. if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false)
  436. {
  437. if (ErrorText != NULL)
  438. strprintf(*ErrorText, _("Invalid '%s' entry in Release file %s"), "Valid-Until", Filename.c_str());
  439. return false;
  440. }
  441. }
  442. // get the user settings for this archive and use what expires earlier
  443. time_t MaxAge = d->ValidUntilMax;
  444. if (MaxAge == 0)
  445. {
  446. MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
  447. if (Label.empty() == false)
  448. MaxAge = _config->FindI(("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge);
  449. }
  450. time_t MinAge = d->ValidUntilMin;
  451. if (MinAge == 0)
  452. {
  453. MinAge = _config->FindI("Acquire::Min-ValidTime", 0);
  454. if (Label.empty() == false)
  455. MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge);
  456. }
  457. if (MinAge != 0 || ValidUntil != 0 || MaxAge != 0)
  458. {
  459. if (MinAge != 0 && ValidUntil != 0) {
  460. time_t const min_date = Date + MinAge;
  461. if (ValidUntil < min_date)
  462. ValidUntil = min_date;
  463. }
  464. if (MaxAge != 0 && Date != 0) {
  465. time_t const max_date = Date + MaxAge;
  466. if (ValidUntil == 0 || ValidUntil > max_date)
  467. ValidUntil = max_date;
  468. }
  469. }
  470. }
  471. /* as the Release file is parsed only after it was verified, the Signed-By field
  472. does not effect the current, but the "next" Release file */
  473. auto Sign = Section.FindS("Signed-By");
  474. if (Sign.empty() == false)
  475. {
  476. std::transform(Sign.begin(), Sign.end(), Sign.begin(), [&](char const c) {
  477. return (isspace(c) == 0) ? c : ',';
  478. });
  479. auto fingers = VectorizeString(Sign, ',');
  480. std::transform(fingers.begin(), fingers.end(), fingers.begin(), [&](std::string finger) {
  481. std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper);
  482. if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos)
  483. {
  484. if (ErrorText != NULL)
  485. strprintf(*ErrorText, _("Invalid '%s' entry in Release file %s"), "Signed-By", Filename.c_str());
  486. return std::string();
  487. }
  488. return finger;
  489. });
  490. if (fingers.empty() == false && std::find(fingers.begin(), fingers.end(), "") == fingers.end())
  491. {
  492. std::stringstream os;
  493. std::copy(fingers.begin(), fingers.end(), std::ostream_iterator<std::string>(os, ","));
  494. SignedBy = os.str();
  495. }
  496. }
  497. LoadedSuccessfully = TRI_YES;
  498. return true;
  499. }
  500. /*}}}*/
  501. metaIndex * debReleaseIndex::UnloadedClone() const /*{{{*/
  502. {
  503. if (Trusted == TRI_NO)
  504. return new debReleaseIndex(URI, Dist, false);
  505. else if (Trusted == TRI_YES)
  506. return new debReleaseIndex(URI, Dist, true);
  507. else
  508. return new debReleaseIndex(URI, Dist);
  509. }
  510. /*}}}*/
  511. bool debReleaseIndex::parseSumData(const char *&Start, const char *End, /*{{{*/
  512. std::string &Name, std::string &Hash, unsigned long long &Size)
  513. {
  514. Name = "";
  515. Hash = "";
  516. Size = 0;
  517. /* Skip over the first blank */
  518. while ((*Start == '\t' || *Start == ' ' || *Start == '\n' || *Start == '\r')
  519. && Start < End)
  520. Start++;
  521. if (Start >= End)
  522. return false;
  523. /* Move EntryEnd to the end of the first entry (the hash) */
  524. const char *EntryEnd = Start;
  525. while ((*EntryEnd != '\t' && *EntryEnd != ' ')
  526. && EntryEnd < End)
  527. EntryEnd++;
  528. if (EntryEnd == End)
  529. return false;
  530. Hash.append(Start, EntryEnd-Start);
  531. /* Skip over intermediate blanks */
  532. Start = EntryEnd;
  533. while (*Start == '\t' || *Start == ' ')
  534. Start++;
  535. if (Start >= End)
  536. return false;
  537. EntryEnd = Start;
  538. /* Find the end of the second entry (the size) */
  539. while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
  540. && EntryEnd < End)
  541. EntryEnd++;
  542. if (EntryEnd == End)
  543. return false;
  544. Size = strtoull (Start, NULL, 10);
  545. /* Skip over intermediate blanks */
  546. Start = EntryEnd;
  547. while (*Start == '\t' || *Start == ' ')
  548. Start++;
  549. if (Start >= End)
  550. return false;
  551. EntryEnd = Start;
  552. /* Find the end of the third entry (the filename) */
  553. while ((*EntryEnd != '\t' && *EntryEnd != ' ' &&
  554. *EntryEnd != '\n' && *EntryEnd != '\r')
  555. && EntryEnd < End)
  556. EntryEnd++;
  557. Name.append(Start, EntryEnd-Start);
  558. Start = EntryEnd; //prepare for the next round
  559. return true;
  560. }
  561. /*}}}*/
  562. bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll)/*{{{*/
  563. {
  564. #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, false, std::map<std::string,std::string>())
  565. pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner,
  566. APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), this);
  567. #undef APT_TARGET
  568. // special case for --print-uris
  569. if (GetAll)
  570. for (auto const &Target: GetIndexTargets())
  571. if (Target.Option(IndexTarget::FALLBACK_OF).empty())
  572. new pkgAcqIndex(Owner, TransactionManager, Target);
  573. return true;
  574. }
  575. /*}}}*/
  576. // ReleaseIndex::Set* TriState options /*{{{*/
  577. bool debReleaseIndex::SetTrusted(TriState const pTrusted)
  578. {
  579. if (Trusted == TRI_UNSET)
  580. Trusted = pTrusted;
  581. else if (Trusted != pTrusted)
  582. // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite
  583. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Trusted", URI.c_str(), Dist.c_str());
  584. return true;
  585. }
  586. bool debReleaseIndex::SetCheckValidUntil(TriState const pCheckValidUntil)
  587. {
  588. if (d->CheckValidUntil == TRI_UNSET)
  589. d->CheckValidUntil = pCheckValidUntil;
  590. else if (d->CheckValidUntil != pCheckValidUntil)
  591. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Check-Valid-Until", URI.c_str(), Dist.c_str());
  592. return true;
  593. }
  594. bool debReleaseIndex::SetValidUntilMin(time_t const Valid)
  595. {
  596. if (d->ValidUntilMin == 0)
  597. d->ValidUntilMin = Valid;
  598. else if (d->ValidUntilMin != Valid)
  599. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Min-ValidTime", URI.c_str(), Dist.c_str());
  600. return true;
  601. }
  602. bool debReleaseIndex::SetValidUntilMax(time_t const Valid)
  603. {
  604. if (d->ValidUntilMax == 0)
  605. d->ValidUntilMax = Valid;
  606. else if (d->ValidUntilMax != Valid)
  607. return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Max-ValidTime", URI.c_str(), Dist.c_str());
  608. return true;
  609. }
  610. bool debReleaseIndex::SetSignedBy(std::string const &pSignedBy)
  611. {
  612. if (SignedBy.empty() == true && pSignedBy.empty() == false)
  613. {
  614. if (pSignedBy[0] == '/') // no check for existence as we could be chrooting later or such things
  615. SignedBy = pSignedBy; // absolute path to a keyring file
  616. else
  617. {
  618. // we could go all fancy and allow short/long/string matches as gpgv/apt-key does,
  619. // but fingerprints are harder to fake than the others and this option is set once,
  620. // not interactively all the time so easy to type is not really a concern.
  621. auto fingers = VectorizeString(pSignedBy, ',');
  622. std::transform(fingers.begin(), fingers.end(), fingers.begin(), [&](std::string finger) {
  623. std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper);
  624. if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos)
  625. {
  626. _error->Error(_("Invalid value set for option %s regarding source %s %s (%s)"), "Signed-By", URI.c_str(), Dist.c_str(), "not a fingerprint");
  627. return std::string();
  628. }
  629. return finger;
  630. });
  631. std::stringstream os;
  632. std::copy(fingers.begin(), fingers.end(), std::ostream_iterator<std::string>(os, ","));
  633. SignedBy = os.str();
  634. }
  635. // Normalize the string: Remove trailing commas
  636. while (SignedBy[SignedBy.size() - 1] == ',')
  637. SignedBy.resize(SignedBy.size() - 1);
  638. }
  639. else {
  640. // Only compare normalized strings
  641. auto pSignedByView = APT::StringView(pSignedBy);
  642. while (pSignedByView[pSignedByView.size() - 1] == ',')
  643. pSignedByView = pSignedByView.substr(0, pSignedByView.size() - 1);
  644. if (pSignedByView != SignedBy)
  645. return _error->Error(_("Conflicting values set for option %s regarding source %s %s: %s != %s"), "Signed-By", URI.c_str(), Dist.c_str(), SignedBy.c_str(), pSignedByView.to_string().c_str());
  646. }
  647. return true;
  648. }
  649. /*}}}*/
  650. // ReleaseIndex::IsTrusted /*{{{*/
  651. bool debReleaseIndex::IsTrusted() const
  652. {
  653. if (Trusted == TRI_YES)
  654. return true;
  655. else if (Trusted == TRI_NO)
  656. return false;
  657. if(_config->FindB("APT::Authentication::TrustCDROM", false))
  658. if(URI.substr(0,strlen("cdrom:")) == "cdrom:")
  659. return true;
  660. if (FileExists(MetaIndexFile("Release.gpg")))
  661. return true;
  662. return FileExists(MetaIndexFile("InRelease"));
  663. }
  664. /*}}}*/
  665. bool debReleaseIndex::IsArchitectureSupported(std::string const &arch) const/*{{{*/
  666. {
  667. if (d->Architectures.empty())
  668. return true;
  669. return std::find(d->Architectures.begin(), d->Architectures.end(), arch) != d->Architectures.end();
  670. }
  671. /*}}}*/
  672. bool debReleaseIndex::IsArchitectureAllSupportedFor(IndexTarget const &target) const/*{{{*/
  673. {
  674. if (d->NoSupportForAll.empty())
  675. return true;
  676. return std::find(d->NoSupportForAll.begin(), d->NoSupportForAll.end(), target.Option(IndexTarget::CREATED_BY)) == d->NoSupportForAll.end();
  677. }
  678. /*}}}*/
  679. std::vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() /*{{{*/
  680. {
  681. if (Indexes != NULL)
  682. return Indexes;
  683. Indexes = new std::vector<pkgIndexFile*>();
  684. bool const istrusted = IsTrusted();
  685. for (auto const &T: GetIndexTargets())
  686. {
  687. std::string const TargetName = T.Option(IndexTarget::CREATED_BY);
  688. if (TargetName == "Packages")
  689. Indexes->push_back(new debPackagesIndex(T, istrusted));
  690. else if (TargetName == "Sources")
  691. Indexes->push_back(new debSourcesIndex(T, istrusted));
  692. else if (TargetName == "Translations")
  693. Indexes->push_back(new debTranslationsIndex(T));
  694. }
  695. return Indexes;
  696. }
  697. /*}}}*/
  698. static bool ReleaseFileName(debReleaseIndex const * const That, std::string &ReleaseFile)/*{{{*/
  699. {
  700. ReleaseFile = That->MetaIndexFile("InRelease");
  701. bool releaseExists = false;
  702. if (FileExists(ReleaseFile) == true)
  703. releaseExists = true;
  704. else
  705. {
  706. ReleaseFile = That->MetaIndexFile("Release");
  707. if (FileExists(ReleaseFile))
  708. releaseExists = true;
  709. }
  710. return releaseExists;
  711. }
  712. /*}}}*/
  713. bool debReleaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress * /*Prog*/) const/*{{{*/
  714. {
  715. std::string ReleaseFile;
  716. bool const releaseExists = ReleaseFileName(this, ReleaseFile);
  717. ::URI Tmp(URI);
  718. if (Gen.SelectReleaseFile(ReleaseFile, Tmp.Host) == false)
  719. return _error->Error("Problem with SelectReleaseFile %s", ReleaseFile.c_str());
  720. if (releaseExists == false)
  721. return true;
  722. FileFd Rel;
  723. // Beware: The 'Release' file might be clearsigned in case the
  724. // signature for an 'InRelease' file couldn't be checked
  725. if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false)
  726. return false;
  727. // Store the IMS information
  728. pkgCache::RlsFileIterator File = Gen.GetCurRlsFile();
  729. pkgCacheGenerator::Dynamic<pkgCache::RlsFileIterator> DynFile(File);
  730. // Rel can't be used as this is potentially a temporary file
  731. struct stat Buf;
  732. if (stat(ReleaseFile.c_str(), &Buf) != 0)
  733. return _error->Errno("fstat", "Unable to stat file %s", ReleaseFile.c_str());
  734. File->Size = Buf.st_size;
  735. File->mtime = Buf.st_mtime;
  736. pkgTagFile TagFile(&Rel, Rel.Size());
  737. pkgTagSection Section;
  738. if (Rel.IsOpen() == false || Rel.Failed() || TagFile.Step(Section) == false)
  739. return false;
  740. std::string data;
  741. #define APT_INRELEASE(TYPE, TAG, STORE) \
  742. data = Section.FindS(TAG); \
  743. if (data.empty() == false) \
  744. { \
  745. map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::TYPE, data); \
  746. if (storage == 0) return false; \
  747. STORE = storage; \
  748. }
  749. APT_INRELEASE(MIXED, "Suite", File->Archive)
  750. APT_INRELEASE(VERSIONNUMBER, "Version", File->Version)
  751. APT_INRELEASE(MIXED, "Origin", File->Origin)
  752. APT_INRELEASE(MIXED, "Codename", File->Codename)
  753. APT_INRELEASE(MIXED, "Label", File->Label)
  754. #undef APT_INRELEASE
  755. Section.FindFlag("NotAutomatic", File->Flags, pkgCache::Flag::NotAutomatic);
  756. Section.FindFlag("ButAutomaticUpgrades", File->Flags, pkgCache::Flag::ButAutomaticUpgrades);
  757. return true;
  758. }
  759. /*}}}*/
  760. // ReleaseIndex::FindInCache - Find this index /*{{{*/
  761. pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool const ModifyCheck) const
  762. {
  763. std::string ReleaseFile;
  764. bool const releaseExists = ReleaseFileName(this, ReleaseFile);
  765. pkgCache::RlsFileIterator File = Cache.RlsFileBegin();
  766. for (; File.end() == false; ++File)
  767. {
  768. if (File->FileName == 0 || ReleaseFile != File.FileName())
  769. continue;
  770. // empty means the file does not exist by "design"
  771. if (ModifyCheck == false || (releaseExists == false && File->Size == 0))
  772. return File;
  773. struct stat St;
  774. if (stat(File.FileName(),&St) != 0)
  775. {
  776. if (_config->FindB("Debug::pkgCacheGen", false))
  777. std::clog << "ReleaseIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
  778. return pkgCache::RlsFileIterator(Cache);
  779. }
  780. if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
  781. {
  782. if (_config->FindB("Debug::pkgCacheGen", false))
  783. std::clog << "ReleaseIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
  784. << ") or mtime (" << St.st_mtime << " <> " << File->mtime
  785. << ") doesn't match for " << File.FileName() << std::endl;
  786. return pkgCache::RlsFileIterator(Cache);
  787. }
  788. return File;
  789. }
  790. return File;
  791. }
  792. /*}}}*/
  793. static std::vector<std::string> parsePlusMinusOptions(std::string const &Name, /*{{{*/
  794. std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues)
  795. {
  796. std::map<std::string, std::string>::const_iterator val = Options.find(Name);
  797. std::vector<std::string> Values;
  798. if (val != Options.end())
  799. Values = VectorizeString(val->second, ',');
  800. else
  801. Values = defaultValues;
  802. // all is a very special architecture users shouldn't be concerned with explicitly
  803. if (Name == "arch" && std::find(Values.begin(), Values.end(), "all") == Values.end())
  804. Values.push_back("all");
  805. if ((val = Options.find(Name + "+")) != Options.end())
  806. {
  807. std::vector<std::string> const plus = VectorizeString(val->second, ',');
  808. std::copy_if(plus.begin(), plus.end(), std::back_inserter(Values), [&Values](std::string const &v) {
  809. return std::find(Values.begin(), Values.end(), v) == Values.end();
  810. });
  811. }
  812. if ((val = Options.find(Name + "-")) != Options.end())
  813. {
  814. std::vector<std::string> const minus = VectorizeString(val->second, ',');
  815. Values.erase(std::remove_if(Values.begin(), Values.end(), [&minus](std::string const &v) {
  816. return std::find(minus.begin(), minus.end(), v) != minus.end();
  817. }), Values.end());
  818. }
  819. return Values;
  820. }
  821. /*}}}*/
  822. class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/
  823. {
  824. metaIndex::TriState GetTriStateOption(std::map<std::string, std::string>const &Options, char const * const name) const
  825. {
  826. std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
  827. if (opt != Options.end())
  828. return StringToBool(opt->second, false) ? metaIndex::TRI_YES : metaIndex::TRI_NO;
  829. return metaIndex::TRI_DONTCARE;
  830. }
  831. time_t GetTimeOption(std::map<std::string, std::string>const &Options, char const * const name) const
  832. {
  833. std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
  834. if (opt == Options.end())
  835. return 0;
  836. return strtoull(opt->second.c_str(), NULL, 10);
  837. }
  838. protected:
  839. bool CreateItemInternal(std::vector<metaIndex *> &List, std::string const &URI,
  840. std::string const &Dist, std::string const &Section,
  841. bool const &IsSrc, std::map<std::string, std::string> const &Options) const
  842. {
  843. debReleaseIndex *Deb = NULL;
  844. for (std::vector<metaIndex *>::const_iterator I = List.begin();
  845. I != List.end(); ++I)
  846. {
  847. // We only worry about debian entries here
  848. if (strcmp((*I)->GetType(), "deb") != 0)
  849. continue;
  850. /* This check insures that there will be only one Release file
  851. queued for all the Packages files and Sources files it
  852. corresponds to. */
  853. if ((*I)->GetURI() == URI && (*I)->GetDist() == Dist)
  854. {
  855. Deb = dynamic_cast<debReleaseIndex*>(*I);
  856. if (Deb != NULL)
  857. break;
  858. }
  859. }
  860. // No currently created Release file indexes this entry, so we create a new one.
  861. if (Deb == NULL)
  862. {
  863. Deb = new debReleaseIndex(URI, Dist);
  864. List.push_back(Deb);
  865. }
  866. std::vector<std::string> const alltargets = _config->FindVector(std::string("Acquire::IndexTargets::") + Name, "", true);
  867. std::vector<std::string> deftargets;
  868. deftargets.reserve(alltargets.size());
  869. std::copy_if(alltargets.begin(), alltargets.end(), std::back_inserter(deftargets), [&](std::string const &t) {
  870. std::string c = "Acquire::IndexTargets::";
  871. c.append(Name).append("::").append(t).append("::DefaultEnabled");
  872. return _config->FindB(c, true);
  873. });
  874. std::vector<std::string> mytargets = parsePlusMinusOptions("target", Options, deftargets);
  875. for (auto const &target : alltargets)
  876. {
  877. std::map<std::string, std::string>::const_iterator const opt = Options.find(target);
  878. if (opt == Options.end())
  879. continue;
  880. auto const idMatch = [&](std::string const &t) {
  881. return target == _config->Find(std::string("Acquire::IndexTargets::") + Name + "::" + t + "::Identifier", t);
  882. };
  883. if (StringToBool(opt->second))
  884. std::copy_if(alltargets.begin(), alltargets.end(), std::back_inserter(mytargets), idMatch);
  885. else
  886. mytargets.erase(std::remove_if(mytargets.begin(), mytargets.end(), idMatch), mytargets.end());
  887. }
  888. // if we can't order it in a 1000 steps we give up… probably a cycle
  889. for (auto i = 0; i < 1000; ++i)
  890. {
  891. bool Changed = false;
  892. for (auto t = mytargets.begin(); t != mytargets.end(); ++t)
  893. {
  894. std::string const fallback = _config->Find(std::string("Acquire::IndexTargets::") + Name + "::" + *t + "::Fallback-Of");
  895. if (fallback.empty())
  896. continue;
  897. auto const faller = std::find(mytargets.begin(), mytargets.end(), fallback);
  898. if (faller == mytargets.end() || faller < t)
  899. continue;
  900. Changed = true;
  901. auto const tv = *t;
  902. mytargets.erase(t);
  903. mytargets.emplace_back(tv);
  904. }
  905. if (Changed == false)
  906. break;
  907. }
  908. // remove duplicates without changing the order (in first appearance)
  909. {
  910. std::set<std::string> seenOnce;
  911. mytargets.erase(std::remove_if(mytargets.begin(), mytargets.end(), [&](std::string const &t) {
  912. return seenOnce.insert(t).second == false;
  913. }), mytargets.end());
  914. }
  915. bool UsePDiffs = _config->FindB("Acquire::PDiffs", true);
  916. {
  917. std::map<std::string, std::string>::const_iterator const opt = Options.find("pdiffs");
  918. if (opt != Options.end())
  919. UsePDiffs = StringToBool(opt->second);
  920. }
  921. std::string UseByHash = _config->Find("APT::Acquire::By-Hash", "yes");
  922. UseByHash = _config->Find("Acquire::By-Hash", UseByHash);
  923. {
  924. std::string const host = ::URI(URI).Host;
  925. UseByHash = _config->Find("APT::Acquire::" + host + "::By-Hash", UseByHash);
  926. UseByHash = _config->Find("Acquire::" + host + "::By-Hash", UseByHash);
  927. std::map<std::string, std::string>::const_iterator const opt = Options.find("by-hash");
  928. if (opt != Options.end())
  929. UseByHash = opt->second;
  930. }
  931. auto const entry = Options.find("sourceslist-entry");
  932. Deb->AddComponent(
  933. entry->second,
  934. IsSrc,
  935. Section,
  936. mytargets,
  937. parsePlusMinusOptions("arch", Options, APT::Configuration::getArchitectures()),
  938. parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true)),
  939. UsePDiffs,
  940. UseByHash
  941. );
  942. if (Deb->SetTrusted(GetTriStateOption(Options, "trusted")) == false ||
  943. Deb->SetCheckValidUntil(GetTriStateOption(Options, "check-valid-until")) == false ||
  944. Deb->SetValidUntilMax(GetTimeOption(Options, "valid-until-max")) == false ||
  945. Deb->SetValidUntilMin(GetTimeOption(Options, "valid-until-min")) == false)
  946. return false;
  947. std::map<std::string, std::string>::const_iterator const signedby = Options.find("signed-by");
  948. if (signedby == Options.end())
  949. {
  950. bool alreadySet = false;
  951. std::string filename;
  952. if (ReleaseFileName(Deb, filename))
  953. {
  954. auto OldDeb = Deb->UnloadedClone();
  955. _error->PushToStack();
  956. OldDeb->Load(filename, nullptr);
  957. bool const goodLoad = _error->PendingError() == false;
  958. _error->RevertToStack();
  959. if (goodLoad)
  960. {
  961. if (OldDeb->GetValidUntil() > 0)
  962. {
  963. time_t const invalid_since = time(NULL) - OldDeb->GetValidUntil();
  964. if (invalid_since <= 0)
  965. {
  966. Deb->SetSignedBy(OldDeb->GetSignedBy());
  967. alreadySet = true;
  968. }
  969. }
  970. }
  971. delete OldDeb;
  972. }
  973. if (alreadySet == false && Deb->SetSignedBy("") == false)
  974. return false;
  975. }
  976. else
  977. {
  978. if (Deb->SetSignedBy(signedby->second) == false)
  979. return false;
  980. }
  981. return true;
  982. }
  983. debSLTypeDebian(char const * const Name, char const * const Label) : Type(Name, Label)
  984. {
  985. }
  986. };
  987. /*}}}*/
  988. class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian /*{{{*/
  989. {
  990. public:
  991. bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI,
  992. std::string const &Dist, std::string const &Section,
  993. std::map<std::string, std::string> const &Options) const APT_OVERRIDE
  994. {
  995. return CreateItemInternal(List, URI, Dist, Section, false, Options);
  996. }
  997. debSLTypeDeb() : debSLTypeDebian("deb", "Debian binary tree")
  998. {
  999. }
  1000. };
  1001. /*}}}*/
  1002. class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian /*{{{*/
  1003. {
  1004. public:
  1005. bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI,
  1006. std::string const &Dist, std::string const &Section,
  1007. std::map<std::string, std::string> const &Options) const APT_OVERRIDE
  1008. {
  1009. return CreateItemInternal(List, URI, Dist, Section, true, Options);
  1010. }
  1011. debSLTypeDebSrc() : debSLTypeDebian("deb-src", "Debian source tree")
  1012. {
  1013. }
  1014. };
  1015. /*}}}*/
  1016. APT_HIDDEN debSLTypeDeb _apt_DebType;
  1017. APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType;