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.
 
 
 
 
 
 

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