You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

802 lines
26 KiB

  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 <sys/stat.h>
  23. #include <string.h>
  24. #include <apti18n.h>
  25. class APT_HIDDEN debReleaseIndexPrivate /*{{{*/
  26. {
  27. public:
  28. struct APT_HIDDEN debSectionEntry
  29. {
  30. std::string Name;
  31. std::vector<std::string> Targets;
  32. std::vector<std::string> Architectures;
  33. std::vector<std::string> Languages;
  34. };
  35. std::vector<debSectionEntry> DebEntries;
  36. std::vector<debSectionEntry> DebSrcEntries;
  37. metaIndex::TriState CheckValidUntil;
  38. time_t ValidUntilMin;
  39. time_t ValidUntilMax;
  40. debReleaseIndexPrivate() : CheckValidUntil(metaIndex::TRI_UNSET), ValidUntilMin(0), ValidUntilMax(0) {}
  41. };
  42. /*}}}*/
  43. // ReleaseIndex::MetaIndex* - display helpers /*{{{*/
  44. std::string debReleaseIndex::MetaIndexInfo(const char *Type) const
  45. {
  46. std::string Info = ::URI::ArchiveOnly(URI) + ' ';
  47. if (Dist[Dist.size() - 1] == '/')
  48. {
  49. if (Dist != "/")
  50. Info += Dist;
  51. }
  52. else
  53. Info += Dist;
  54. Info += " ";
  55. Info += Type;
  56. return Info;
  57. }
  58. std::string debReleaseIndex::Describe() const
  59. {
  60. return MetaIndexInfo("Release");
  61. }
  62. std::string debReleaseIndex::MetaIndexFile(const char *Type) const
  63. {
  64. return _config->FindDir("Dir::State::lists") +
  65. URItoFileName(MetaIndexURI(Type));
  66. }
  67. std::string debReleaseIndex::MetaIndexURI(const char *Type) const
  68. {
  69. std::string Res;
  70. if (Dist == "/")
  71. Res = URI;
  72. else if (Dist[Dist.size()-1] == '/')
  73. Res = URI + Dist;
  74. else
  75. Res = URI + "dists/" + Dist + "/";
  76. Res += Type;
  77. return Res;
  78. }
  79. /*}}}*/
  80. // ReleaseIndex Con- and Destructors /*{{{*/
  81. debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist) :
  82. metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate())
  83. {}
  84. debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const pTrusted) :
  85. metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate())
  86. {
  87. Trusted = pTrusted ? TRI_YES : TRI_NO;
  88. }
  89. debReleaseIndex::~debReleaseIndex() {
  90. if (d != NULL)
  91. delete d;
  92. }
  93. /*}}}*/
  94. // ReleaseIndex::GetIndexTargets /*{{{*/
  95. static void GetIndexTargetsFor(char const * const Type, std::string const &URI, std::string const &Dist,
  96. std::vector<debReleaseIndexPrivate::debSectionEntry> const &entries,
  97. std::vector<IndexTarget> &IndexTargets)
  98. {
  99. bool const flatArchive = (Dist[Dist.length() - 1] == '/');
  100. std::string baseURI = URI;
  101. if (flatArchive)
  102. {
  103. if (Dist != "/")
  104. baseURI += Dist;
  105. }
  106. else
  107. baseURI += "dists/" + Dist + "/";
  108. std::string const Release = (Dist == "/") ? "" : Dist;
  109. std::string const Site = ::URI::ArchiveOnly(URI);
  110. bool const GzipIndex = _config->FindB("Acquire::GzipIndexes", false);
  111. for (std::vector<debReleaseIndexPrivate::debSectionEntry>::const_iterator E = entries.begin(); E != entries.end(); ++E)
  112. {
  113. for (std::vector<std::string>::const_iterator T = E->Targets.begin(); T != E->Targets.end(); ++T)
  114. {
  115. #define APT_T_CONFIG(X) _config->Find(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X))
  116. std::string const tplMetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey");
  117. std::string const tplShortDesc = APT_T_CONFIG("ShortDescription");
  118. std::string const tplLongDesc = "$(SITE) " + APT_T_CONFIG(flatArchive ? "flatDescription" : "Description");
  119. bool const IsOptional = _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::Optional", true);
  120. bool const KeepCompressed = _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::KeepCompressed", GzipIndex);
  121. #undef APT_T_CONFIG
  122. if (tplMetaKey.empty())
  123. continue;
  124. for (std::vector<std::string>::const_iterator L = E->Languages.begin(); L != E->Languages.end(); ++L)
  125. {
  126. if (*L == "none" && tplMetaKey.find("$(LANGUAGE)") != std::string::npos)
  127. continue;
  128. for (std::vector<std::string>::const_iterator A = E->Architectures.begin(); A != E->Architectures.end(); ++A)
  129. {
  130. std::map<std::string, std::string> Options;
  131. Options.insert(std::make_pair("SITE", Site));
  132. Options.insert(std::make_pair("RELEASE", Release));
  133. if (tplMetaKey.find("$(COMPONENT)") != std::string::npos)
  134. Options.insert(std::make_pair("COMPONENT", E->Name));
  135. if (tplMetaKey.find("$(LANGUAGE)") != std::string::npos)
  136. Options.insert(std::make_pair("LANGUAGE", *L));
  137. if (tplMetaKey.find("$(ARCHITECTURE)") != std::string::npos)
  138. Options.insert(std::make_pair("ARCHITECTURE", *A));
  139. Options.insert(std::make_pair("BASE_URI", baseURI));
  140. Options.insert(std::make_pair("REPO_URI", URI));
  141. Options.insert(std::make_pair("TARGET_OF", Type));
  142. Options.insert(std::make_pair("CREATED_BY", *T));
  143. std::string MetaKey = tplMetaKey;
  144. std::string ShortDesc = tplShortDesc;
  145. std::string LongDesc = tplLongDesc;
  146. for (std::map<std::string, std::string>::const_iterator O = Options.begin(); O != Options.end(); ++O)
  147. {
  148. MetaKey = SubstVar(MetaKey, std::string("$(") + O->first + ")", O->second);
  149. ShortDesc = SubstVar(ShortDesc, std::string("$(") + O->first + ")", O->second);
  150. LongDesc = SubstVar(LongDesc, std::string("$(") + O->first + ")", O->second);
  151. }
  152. IndexTarget Target(
  153. MetaKey,
  154. ShortDesc,
  155. LongDesc,
  156. Options.find("BASE_URI")->second + MetaKey,
  157. IsOptional,
  158. KeepCompressed,
  159. Options
  160. );
  161. IndexTargets.push_back(Target);
  162. if (tplMetaKey.find("$(ARCHITECTURE)") == std::string::npos)
  163. break;
  164. }
  165. if (tplMetaKey.find("$(LANGUAGE)") == std::string::npos)
  166. break;
  167. }
  168. }
  169. }
  170. }
  171. std::vector<IndexTarget> debReleaseIndex::GetIndexTargets() const
  172. {
  173. std::vector<IndexTarget> IndexTargets;
  174. GetIndexTargetsFor("deb-src", URI, Dist, d->DebSrcEntries, IndexTargets);
  175. GetIndexTargetsFor("deb", URI, Dist, d->DebEntries, IndexTargets);
  176. return IndexTargets;
  177. }
  178. /*}}}*/
  179. void debReleaseIndex::AddComponent(bool const isSrc, std::string const &Name,/*{{{*/
  180. std::vector<std::string> const &Targets,
  181. std::vector<std::string> const &Architectures,
  182. std::vector<std::string> Languages)
  183. {
  184. if (Languages.empty() == true)
  185. Languages.push_back("none");
  186. debReleaseIndexPrivate::debSectionEntry const entry = {
  187. Name, Targets, Architectures, Languages
  188. };
  189. if (isSrc)
  190. d->DebSrcEntries.push_back(entry);
  191. else
  192. d->DebEntries.push_back(entry);
  193. }
  194. /*}}}*/
  195. bool debReleaseIndex::Load(std::string const &Filename, std::string * const ErrorText)/*{{{*/
  196. {
  197. LoadedSuccessfully = TRI_NO;
  198. FileFd Fd;
  199. if (OpenMaybeClearSignedFile(Filename, Fd) == false)
  200. return false;
  201. pkgTagFile TagFile(&Fd, Fd.Size());
  202. if (_error->PendingError() == true)
  203. {
  204. if (ErrorText != NULL)
  205. strprintf(*ErrorText, _("Unable to parse Release file %s"),Filename.c_str());
  206. return false;
  207. }
  208. pkgTagSection Section;
  209. const char *Start, *End;
  210. if (TagFile.Step(Section) == false)
  211. {
  212. if (ErrorText != NULL)
  213. strprintf(*ErrorText, _("No sections in Release file %s"), Filename.c_str());
  214. return false;
  215. }
  216. // FIXME: find better tag name
  217. SupportsAcquireByHash = Section.FindB("Acquire-By-Hash", false);
  218. Suite = Section.FindS("Suite");
  219. Codename = Section.FindS("Codename");
  220. bool FoundHashSum = false;
  221. for (int i=0;HashString::SupportedHashes()[i] != NULL; i++)
  222. {
  223. if (!Section.Find(HashString::SupportedHashes()[i], Start, End))
  224. continue;
  225. std::string Name;
  226. std::string Hash;
  227. unsigned long long Size;
  228. while (Start < End)
  229. {
  230. if (!parseSumData(Start, End, Name, Hash, Size))
  231. return false;
  232. if (Entries.find(Name) == Entries.end())
  233. {
  234. metaIndex::checkSum *Sum = new metaIndex::checkSum;
  235. Sum->MetaKeyFilename = Name;
  236. Sum->Size = Size;
  237. Sum->Hashes.FileSize(Size);
  238. APT_IGNORE_DEPRECATED(Sum->Hash = HashString(HashString::SupportedHashes()[i],Hash);)
  239. Entries[Name] = Sum;
  240. }
  241. Entries[Name]->Hashes.push_back(HashString(HashString::SupportedHashes()[i],Hash));
  242. FoundHashSum = true;
  243. }
  244. }
  245. if(FoundHashSum == false)
  246. {
  247. if (ErrorText != NULL)
  248. strprintf(*ErrorText, _("No Hash entry in Release file %s"), Filename.c_str());
  249. return false;
  250. }
  251. std::string const StrDate = Section.FindS("Date");
  252. if (RFC1123StrToTime(StrDate.c_str(), Date) == false)
  253. {
  254. if (ErrorText != NULL)
  255. strprintf(*ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str());
  256. return false;
  257. }
  258. bool CheckValidUntil = _config->FindB("Acquire::Check-Valid-Until", true);
  259. if (d->CheckValidUntil == metaIndex::TRI_NO)
  260. CheckValidUntil = false;
  261. else if (d->CheckValidUntil == metaIndex::TRI_YES)
  262. CheckValidUntil = true;
  263. if (CheckValidUntil == true)
  264. {
  265. std::string const Label = Section.FindS("Label");
  266. std::string const StrValidUntil = Section.FindS("Valid-Until");
  267. // if we have a Valid-Until header in the Release file, use it as default
  268. if (StrValidUntil.empty() == false)
  269. {
  270. if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false)
  271. {
  272. if (ErrorText != NULL)
  273. strprintf(*ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str());
  274. return false;
  275. }
  276. }
  277. // get the user settings for this archive and use what expires earlier
  278. time_t MaxAge = d->ValidUntilMax;
  279. if (MaxAge == 0)
  280. {
  281. MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
  282. if (Label.empty() == false)
  283. MaxAge = _config->FindI(("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge);
  284. }
  285. time_t MinAge = d->ValidUntilMin;
  286. if (MinAge == 0)
  287. {
  288. MinAge = _config->FindI("Acquire::Min-ValidTime", 0);
  289. if (Label.empty() == false)
  290. MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge);
  291. }
  292. if (MinAge != 0 && ValidUntil != 0) {
  293. time_t const min_date = Date + MinAge;
  294. if (ValidUntil < min_date)
  295. ValidUntil = min_date;
  296. }
  297. if (MaxAge != 0) {
  298. time_t const max_date = Date + MaxAge;
  299. if (ValidUntil == 0 || ValidUntil > max_date)
  300. ValidUntil = max_date;
  301. }
  302. }
  303. LoadedSuccessfully = TRI_YES;
  304. return true;
  305. }
  306. /*}}}*/
  307. metaIndex * debReleaseIndex::UnloadedClone() const /*{{{*/
  308. {
  309. if (Trusted == TRI_NO)
  310. return new debReleaseIndex(URI, Dist, false);
  311. else if (Trusted == TRI_YES)
  312. return new debReleaseIndex(URI, Dist, true);
  313. else
  314. return new debReleaseIndex(URI, Dist);
  315. }
  316. /*}}}*/
  317. bool debReleaseIndex::parseSumData(const char *&Start, const char *End, /*{{{*/
  318. std::string &Name, std::string &Hash, unsigned long long &Size)
  319. {
  320. Name = "";
  321. Hash = "";
  322. Size = 0;
  323. /* Skip over the first blank */
  324. while ((*Start == '\t' || *Start == ' ' || *Start == '\n' || *Start == '\r')
  325. && Start < End)
  326. Start++;
  327. if (Start >= End)
  328. return false;
  329. /* Move EntryEnd to the end of the first entry (the hash) */
  330. const char *EntryEnd = Start;
  331. while ((*EntryEnd != '\t' && *EntryEnd != ' ')
  332. && EntryEnd < End)
  333. EntryEnd++;
  334. if (EntryEnd == End)
  335. return false;
  336. Hash.append(Start, EntryEnd-Start);
  337. /* Skip over intermediate blanks */
  338. Start = EntryEnd;
  339. while (*Start == '\t' || *Start == ' ')
  340. Start++;
  341. if (Start >= End)
  342. return false;
  343. EntryEnd = Start;
  344. /* Find the end of the second entry (the size) */
  345. while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
  346. && EntryEnd < End)
  347. EntryEnd++;
  348. if (EntryEnd == End)
  349. return false;
  350. Size = strtoull (Start, NULL, 10);
  351. /* Skip over intermediate blanks */
  352. Start = EntryEnd;
  353. while (*Start == '\t' || *Start == ' ')
  354. Start++;
  355. if (Start >= End)
  356. return false;
  357. EntryEnd = Start;
  358. /* Find the end of the third entry (the filename) */
  359. while ((*EntryEnd != '\t' && *EntryEnd != ' ' &&
  360. *EntryEnd != '\n' && *EntryEnd != '\r')
  361. && EntryEnd < End)
  362. EntryEnd++;
  363. Name.append(Start, EntryEnd-Start);
  364. Start = EntryEnd; //prepare for the next round
  365. return true;
  366. }
  367. /*}}}*/
  368. bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll)/*{{{*/
  369. {
  370. std::vector<IndexTarget> const targets = GetIndexTargets();
  371. #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, false, std::map<std::string,std::string>())
  372. pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner,
  373. APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"),
  374. targets, this);
  375. #undef APT_TARGET
  376. // special case for --print-uris
  377. if (GetAll)
  378. {
  379. for (std::vector<IndexTarget>::const_iterator Target = targets.begin(); Target != targets.end(); ++Target)
  380. new pkgAcqIndex(Owner, TransactionManager, *Target);
  381. }
  382. return true;
  383. }
  384. /*}}}*/
  385. // ReleaseIndex::Set* TriState options /*{{{*/
  386. bool debReleaseIndex::SetTrusted(TriState const pTrusted)
  387. {
  388. if (Trusted == TRI_UNSET)
  389. Trusted = pTrusted;
  390. else if (Trusted != pTrusted)
  391. // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite
  392. return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Trusted", URI.c_str(), Dist.c_str());
  393. return true;
  394. }
  395. bool debReleaseIndex::SetCheckValidUntil(TriState const pCheckValidUntil)
  396. {
  397. if (d->CheckValidUntil == TRI_UNSET)
  398. d->CheckValidUntil = pCheckValidUntil;
  399. else if (d->CheckValidUntil != pCheckValidUntil)
  400. return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Check-Valid-Until", URI.c_str(), Dist.c_str());
  401. return true;
  402. }
  403. bool debReleaseIndex::SetValidUntilMin(time_t const Valid)
  404. {
  405. if (d->ValidUntilMin == 0)
  406. d->ValidUntilMin = Valid;
  407. else if (d->ValidUntilMin != Valid)
  408. return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Min-ValidTime", URI.c_str(), Dist.c_str());
  409. return true;
  410. }
  411. bool debReleaseIndex::SetValidUntilMax(time_t const Valid)
  412. {
  413. if (d->ValidUntilMax == 0)
  414. d->ValidUntilMax = Valid;
  415. else if (d->ValidUntilMax != Valid)
  416. return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Max-ValidTime", URI.c_str(), Dist.c_str());
  417. return true;
  418. }
  419. bool debReleaseIndex::SetSignedBy(std::string const &pSignedBy)
  420. {
  421. if (SignedBy.empty() == true && pSignedBy.empty() == false)
  422. {
  423. if (pSignedBy[0] == '/') // no check for existence as we could be chrooting later or such things
  424. ; // absolute path to a keyring file
  425. else
  426. {
  427. // we could go all fancy and allow short/long/string matches as gpgv/apt-key does,
  428. // but fingerprints are harder to fake than the others and this option is set once,
  429. // not interactively all the time so easy to type is not really a concern.
  430. std::string finger = pSignedBy;
  431. finger.erase(std::remove(finger.begin(), finger.end(), ' '), finger.end());
  432. std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper);
  433. if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos)
  434. return _error->Error(_("Invalid value set for option %s concerning source %s %s (%s)"), "Signed-By", URI.c_str(), Dist.c_str(), "not a fingerprint");
  435. }
  436. SignedBy = pSignedBy;
  437. }
  438. else if (SignedBy != pSignedBy)
  439. return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Signed-By", URI.c_str(), Dist.c_str());
  440. return true;
  441. }
  442. /*}}}*/
  443. // ReleaseIndex::IsTrusted /*{{{*/
  444. bool debReleaseIndex::IsTrusted() const
  445. {
  446. if (Trusted == TRI_YES)
  447. return true;
  448. else if (Trusted == TRI_NO)
  449. return false;
  450. if(_config->FindB("APT::Authentication::TrustCDROM", false))
  451. if(URI.substr(0,strlen("cdrom:")) == "cdrom:")
  452. return true;
  453. if (FileExists(MetaIndexFile("Release.gpg")))
  454. return true;
  455. return FileExists(MetaIndexFile("InRelease"));
  456. }
  457. /*}}}*/
  458. std::vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() /*{{{*/
  459. {
  460. if (Indexes != NULL)
  461. return Indexes;
  462. Indexes = new std::vector<pkgIndexFile*>();
  463. std::vector<IndexTarget> const Targets = GetIndexTargets();
  464. bool const istrusted = IsTrusted();
  465. for (std::vector<IndexTarget>::const_iterator T = Targets.begin(); T != Targets.end(); ++T)
  466. {
  467. std::string const TargetName = T->Option(IndexTarget::CREATED_BY);
  468. if (TargetName == "Packages")
  469. Indexes->push_back(new debPackagesIndex(*T, istrusted));
  470. else if (TargetName == "Sources")
  471. Indexes->push_back(new debSourcesIndex(*T, istrusted));
  472. else if (TargetName == "Translations")
  473. Indexes->push_back(new debTranslationsIndex(*T));
  474. }
  475. return Indexes;
  476. }
  477. /*}}}*/
  478. static bool ReleaseFileName(debReleaseIndex const * const That, std::string &ReleaseFile)/*{{{*/
  479. {
  480. ReleaseFile = That->MetaIndexFile("InRelease");
  481. bool releaseExists = false;
  482. if (FileExists(ReleaseFile) == true)
  483. releaseExists = true;
  484. else
  485. {
  486. ReleaseFile = That->MetaIndexFile("Release");
  487. if (FileExists(ReleaseFile))
  488. releaseExists = true;
  489. }
  490. return releaseExists;
  491. }
  492. /*}}}*/
  493. bool debReleaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress * /*Prog*/) const/*{{{*/
  494. {
  495. std::string ReleaseFile;
  496. bool const releaseExists = ReleaseFileName(this, ReleaseFile);
  497. ::URI Tmp(URI);
  498. if (Gen.SelectReleaseFile(ReleaseFile, Tmp.Host) == false)
  499. return _error->Error("Problem with SelectReleaseFile %s", ReleaseFile.c_str());
  500. if (releaseExists == false)
  501. return true;
  502. FileFd Rel;
  503. // Beware: The 'Release' file might be clearsigned in case the
  504. // signature for an 'InRelease' file couldn't be checked
  505. if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false)
  506. return false;
  507. if (_error->PendingError() == true)
  508. return false;
  509. // Store the IMS information
  510. pkgCache::RlsFileIterator File = Gen.GetCurRlsFile();
  511. pkgCacheGenerator::Dynamic<pkgCache::RlsFileIterator> DynFile(File);
  512. // Rel can't be used as this is potentially a temporary file
  513. struct stat Buf;
  514. if (stat(ReleaseFile.c_str(), &Buf) != 0)
  515. return _error->Errno("fstat", "Unable to stat file %s", ReleaseFile.c_str());
  516. File->Size = Buf.st_size;
  517. File->mtime = Buf.st_mtime;
  518. pkgTagFile TagFile(&Rel, Rel.Size());
  519. pkgTagSection Section;
  520. if (_error->PendingError() == true || TagFile.Step(Section) == false)
  521. return false;
  522. std::string data;
  523. #define APT_INRELEASE(TYPE, TAG, STORE) \
  524. data = Section.FindS(TAG); \
  525. if (data.empty() == false) \
  526. { \
  527. map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::TYPE, data); \
  528. STORE = storage; \
  529. }
  530. APT_INRELEASE(MIXED, "Suite", File->Archive)
  531. APT_INRELEASE(VERSIONNUMBER, "Version", File->Version)
  532. APT_INRELEASE(MIXED, "Origin", File->Origin)
  533. APT_INRELEASE(MIXED, "Codename", File->Codename)
  534. APT_INRELEASE(MIXED, "Label", File->Label)
  535. #undef APT_INRELEASE
  536. Section.FindFlag("NotAutomatic", File->Flags, pkgCache::Flag::NotAutomatic);
  537. Section.FindFlag("ButAutomaticUpgrades", File->Flags, pkgCache::Flag::ButAutomaticUpgrades);
  538. return !_error->PendingError();
  539. }
  540. /*}}}*/
  541. // ReleaseIndex::FindInCache - Find this index /*{{{*/
  542. pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool const ModifyCheck) const
  543. {
  544. std::string ReleaseFile;
  545. bool const releaseExists = ReleaseFileName(this, ReleaseFile);
  546. pkgCache::RlsFileIterator File = Cache.RlsFileBegin();
  547. for (; File.end() == false; ++File)
  548. {
  549. if (File->FileName == 0 || ReleaseFile != File.FileName())
  550. continue;
  551. // empty means the file does not exist by "design"
  552. if (ModifyCheck == false || (releaseExists == false && File->Size == 0))
  553. return File;
  554. struct stat St;
  555. if (stat(File.FileName(),&St) != 0)
  556. {
  557. if (_config->FindB("Debug::pkgCacheGen", false))
  558. std::clog << "ReleaseIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
  559. return pkgCache::RlsFileIterator(Cache);
  560. }
  561. if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
  562. {
  563. if (_config->FindB("Debug::pkgCacheGen", false))
  564. std::clog << "ReleaseIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
  565. << ") or mtime (" << St.st_mtime << " <> " << File->mtime
  566. << ") doesn't match for " << File.FileName() << std::endl;
  567. return pkgCache::RlsFileIterator(Cache);
  568. }
  569. return File;
  570. }
  571. return File;
  572. }
  573. /*}}}*/
  574. static std::vector<std::string> parsePlusMinusOptions(std::string const &Name, /*{{{*/
  575. std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues)
  576. {
  577. std::map<std::string, std::string>::const_iterator val = Options.find(Name);
  578. std::vector<std::string> Values;
  579. if (val != Options.end())
  580. Values = VectorizeString(val->second, ',');
  581. else
  582. Values = defaultValues;
  583. if ((val = Options.find(Name + "+")) != Options.end())
  584. {
  585. std::vector<std::string> const plusArch = VectorizeString(val->second, ',');
  586. for (std::vector<std::string>::const_iterator plus = plusArch.begin(); plus != plusArch.end(); ++plus)
  587. if (std::find(Values.begin(), Values.end(), *plus) == Values.end())
  588. Values.push_back(*plus);
  589. }
  590. if ((val = Options.find(Name + "-")) != Options.end())
  591. {
  592. std::vector<std::string> const minusArch = VectorizeString(val->second, ',');
  593. for (std::vector<std::string>::const_iterator minus = minusArch.begin(); minus != minusArch.end(); ++minus)
  594. {
  595. std::vector<std::string>::iterator kill = std::find(Values.begin(), Values.end(), *minus);
  596. if (kill != Values.end())
  597. Values.erase(kill);
  598. }
  599. }
  600. return Values;
  601. }
  602. /*}}}*/
  603. class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/
  604. {
  605. metaIndex::TriState GetTriStateOption(std::map<std::string, std::string>const &Options, char const * const name) const
  606. {
  607. std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
  608. if (opt != Options.end())
  609. return StringToBool(opt->second, false) ? metaIndex::TRI_YES : metaIndex::TRI_NO;
  610. return metaIndex::TRI_DONTCARE;
  611. }
  612. time_t GetTimeOption(std::map<std::string, std::string>const &Options, char const * const name) const
  613. {
  614. std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
  615. if (opt == Options.end())
  616. return 0;
  617. return strtoull(opt->second.c_str(), NULL, 10);
  618. }
  619. protected:
  620. bool CreateItemInternal(std::vector<metaIndex *> &List, std::string const &URI,
  621. std::string const &Dist, std::string const &Section,
  622. bool const &IsSrc, std::map<std::string, std::string> const &Options) const
  623. {
  624. debReleaseIndex *Deb = NULL;
  625. for (std::vector<metaIndex *>::const_iterator I = List.begin();
  626. I != List.end(); ++I)
  627. {
  628. // We only worry about debian entries here
  629. if (strcmp((*I)->GetType(), "deb") != 0)
  630. continue;
  631. /* This check insures that there will be only one Release file
  632. queued for all the Packages files and Sources files it
  633. corresponds to. */
  634. if ((*I)->GetURI() == URI && (*I)->GetDist() == Dist)
  635. {
  636. Deb = dynamic_cast<debReleaseIndex*>(*I);
  637. if (Deb != NULL)
  638. break;
  639. }
  640. }
  641. // No currently created Release file indexes this entry, so we create a new one.
  642. if (Deb == NULL)
  643. {
  644. Deb = new debReleaseIndex(URI, Dist);
  645. List.push_back(Deb);
  646. }
  647. std::vector<std::string> const alltargets = _config->FindVector(std::string("Acquire::IndexTargets::") + Name, "", true);
  648. std::vector<std::string> mytargets = parsePlusMinusOptions("target", Options, alltargets);
  649. if (mytargets.empty() == false)
  650. for (auto const &target : alltargets)
  651. {
  652. std::map<std::string, std::string>::const_iterator const opt = Options.find(target);
  653. if (opt == Options.end())
  654. continue;
  655. auto const tarItr = std::find(mytargets.begin(), mytargets.end(), target);
  656. bool const optValue = StringToBool(opt->second);
  657. if (optValue == true && tarItr == mytargets.end())
  658. mytargets.push_back(target);
  659. else if (optValue == false && tarItr != mytargets.end())
  660. mytargets.erase(std::remove(mytargets.begin(), mytargets.end(), target), mytargets.end());
  661. }
  662. Deb->AddComponent(
  663. IsSrc,
  664. Section,
  665. mytargets,
  666. parsePlusMinusOptions("arch", Options, APT::Configuration::getArchitectures()),
  667. parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true))
  668. );
  669. if (Deb->SetTrusted(GetTriStateOption(Options, "trusted")) == false ||
  670. Deb->SetCheckValidUntil(GetTriStateOption(Options, "check-valid-until")) == false ||
  671. Deb->SetValidUntilMax(GetTimeOption(Options, "valid-until-max")) == false ||
  672. Deb->SetValidUntilMin(GetTimeOption(Options, "valid-until-min")) == false)
  673. return false;
  674. std::map<std::string, std::string>::const_iterator const signedby = Options.find("signed-by");
  675. if (signedby == Options.end())
  676. {
  677. if (Deb->SetSignedBy("") == false)
  678. return false;
  679. }
  680. else
  681. {
  682. if (Deb->SetSignedBy(signedby->second) == false)
  683. return false;
  684. }
  685. return true;
  686. }
  687. debSLTypeDebian(char const * const Name, char const * const Label) : Type(Name, Label)
  688. {
  689. }
  690. };
  691. /*}}}*/
  692. class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian /*{{{*/
  693. {
  694. public:
  695. bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI,
  696. std::string const &Dist, std::string const &Section,
  697. std::map<std::string, std::string> const &Options) const APT_OVERRIDE
  698. {
  699. return CreateItemInternal(List, URI, Dist, Section, false, Options);
  700. }
  701. debSLTypeDeb() : debSLTypeDebian("deb", "Debian binary tree")
  702. {
  703. }
  704. };
  705. /*}}}*/
  706. class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian /*{{{*/
  707. {
  708. public:
  709. bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI,
  710. std::string const &Dist, std::string const &Section,
  711. std::map<std::string, std::string> const &Options) const APT_OVERRIDE
  712. {
  713. return CreateItemInternal(List, URI, Dist, Section, true, Options);
  714. }
  715. debSLTypeDebSrc() : debSLTypeDebian("deb-src", "Debian source tree")
  716. {
  717. }
  718. };
  719. /*}}}*/
  720. APT_HIDDEN debSLTypeDeb _apt_DebType;
  721. APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType;