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.
 
 
 
 
 
 

3471 lines
118 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire-item.cc,v 1.46.2.9 2004/01/16 18:51:11 mdz Exp $
  4. /* ######################################################################
  5. Acquire Item - Item to acquire
  6. Each item can download to exactly one file at a time. This means you
  7. cannot create an item that fetches two uri's to two files at the same
  8. time. The pkgAcqIndex class creates a second class upon instantiation
  9. to fetch the other index files because of this.
  10. ##################################################################### */
  11. /*}}}*/
  12. // Include Files /*{{{*/
  13. #include <config.h>
  14. #include <apt-pkg/acquire-item.h>
  15. #include <apt-pkg/configuration.h>
  16. #include <apt-pkg/aptconfiguration.h>
  17. #include <apt-pkg/sourcelist.h>
  18. #include <apt-pkg/error.h>
  19. #include <apt-pkg/strutl.h>
  20. #include <apt-pkg/fileutl.h>
  21. #include <apt-pkg/tagfile.h>
  22. #include <apt-pkg/metaindex.h>
  23. #include <apt-pkg/acquire.h>
  24. #include <apt-pkg/hashes.h>
  25. #include <apt-pkg/indexfile.h>
  26. #include <apt-pkg/pkgcache.h>
  27. #include <apt-pkg/cacheiterators.h>
  28. #include <apt-pkg/pkgrecords.h>
  29. #include <apt-pkg/gpgv.h>
  30. #include <algorithm>
  31. #include <stddef.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <iostream>
  35. #include <vector>
  36. #include <sys/stat.h>
  37. #include <unistd.h>
  38. #include <errno.h>
  39. #include <string>
  40. #include <stdio.h>
  41. #include <ctime>
  42. #include <sstream>
  43. #include <numeric>
  44. #include <apti18n.h>
  45. /*}}}*/
  46. using namespace std;
  47. static void printHashSumComparison(std::string const &URI, HashStringList const &Expected, HashStringList const &Actual) /*{{{*/
  48. {
  49. if (_config->FindB("Debug::Acquire::HashSumMismatch", false) == false)
  50. return;
  51. std::cerr << std::endl << URI << ":" << std::endl << " Expected Hash: " << std::endl;
  52. for (HashStringList::const_iterator hs = Expected.begin(); hs != Expected.end(); ++hs)
  53. std::cerr << "\t- " << hs->toStr() << std::endl;
  54. std::cerr << " Actual Hash: " << std::endl;
  55. for (HashStringList::const_iterator hs = Actual.begin(); hs != Actual.end(); ++hs)
  56. std::cerr << "\t- " << hs->toStr() << std::endl;
  57. }
  58. /*}}}*/
  59. static std::string GetPartialFileName(std::string const &file) /*{{{*/
  60. {
  61. std::string DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  62. DestFile += file;
  63. return DestFile;
  64. }
  65. /*}}}*/
  66. static std::string GetPartialFileNameFromURI(std::string const &uri) /*{{{*/
  67. {
  68. return GetPartialFileName(URItoFileName(uri));
  69. }
  70. /*}}}*/
  71. static std::string GetFinalFileNameFromURI(std::string const &uri) /*{{{*/
  72. {
  73. return _config->FindDir("Dir::State::lists") + URItoFileName(uri);
  74. }
  75. /*}}}*/
  76. static std::string GetKeepCompressedFileName(std::string file, IndexTarget const &Target)/*{{{*/
  77. {
  78. if (Target.KeepCompressed == false)
  79. return file;
  80. std::string const KeepCompressedAs = Target.Option(IndexTarget::KEEPCOMPRESSEDAS);
  81. if (KeepCompressedAs.empty() == false)
  82. {
  83. std::string const ext = KeepCompressedAs.substr(0, KeepCompressedAs.find(' '));
  84. if (ext != "uncompressed")
  85. file.append(".").append(ext);
  86. }
  87. return file;
  88. }
  89. /*}}}*/
  90. static std::string GetMergeDiffsPatchFileName(std::string const &Final, std::string const &Patch)/*{{{*/
  91. {
  92. // rred expects the patch as $FinalFile.ed.$patchname.gz
  93. return Final + ".ed." + Patch + ".gz";
  94. }
  95. /*}}}*/
  96. static std::string GetDiffsPatchFileName(std::string const &Final) /*{{{*/
  97. {
  98. // rred expects the patch as $FinalFile.ed
  99. return Final + ".ed";
  100. }
  101. /*}}}*/
  102. static std::string GetExistingFilename(std::string const &File) /*{{{*/
  103. {
  104. if (RealFileExists(File))
  105. return File;
  106. for (auto const &type : APT::Configuration::getCompressorExtensions())
  107. {
  108. std::string const Final = File + type;
  109. if (RealFileExists(Final))
  110. return Final;
  111. }
  112. return "";
  113. }
  114. /*}}}*/
  115. static std::string GetDiffIndexFileName(std::string const &Name) /*{{{*/
  116. {
  117. return Name + ".diff/Index";
  118. }
  119. /*}}}*/
  120. static std::string GetDiffIndexURI(IndexTarget const &Target) /*{{{*/
  121. {
  122. return Target.URI + ".diff/Index";
  123. }
  124. /*}}}*/
  125. static bool MessageInsecureRepository(bool const isError, std::string const &msg)/*{{{*/
  126. {
  127. if (isError)
  128. {
  129. _error->Error("%s", msg.c_str());
  130. _error->Notice("%s", _("Updating from such a repository can't be done securely, and is therefore disabled by default."));
  131. }
  132. else
  133. {
  134. _error->Warning("%s", msg.c_str());
  135. _error->Notice("%s", _("Data from such a repository can't be authenticated and is therefore potentially dangerous to use."));
  136. }
  137. _error->Notice("%s", _("See apt-secure(8) manpage for repository creation and user configuration details."));
  138. return false;
  139. }
  140. static bool MessageInsecureRepository(bool const isError, char const * const msg, std::string const &repo)
  141. {
  142. std::string m;
  143. strprintf(m, msg, repo.c_str());
  144. return MessageInsecureRepository(isError, m);
  145. }
  146. /*}}}*/
  147. static bool AllowInsecureRepositories(char const * const msg, std::string const &repo,/*{{{*/
  148. metaIndex const * const MetaIndexParser, pkgAcqMetaClearSig * const TransactionManager, pkgAcquire::Item * const I)
  149. {
  150. if(MetaIndexParser->GetTrusted() == metaIndex::TRI_YES)
  151. return true;
  152. if (_config->FindB("Acquire::AllowInsecureRepositories") == true)
  153. {
  154. MessageInsecureRepository(false, msg, repo);
  155. return true;
  156. }
  157. MessageInsecureRepository(true, msg, repo);
  158. TransactionManager->AbortTransaction();
  159. I->Status = pkgAcquire::Item::StatError;
  160. return false;
  161. }
  162. /*}}}*/
  163. static HashStringList GetExpectedHashesFromFor(metaIndex * const Parser, std::string const &MetaKey)/*{{{*/
  164. {
  165. if (Parser == NULL)
  166. return HashStringList();
  167. metaIndex::checkSum * const R = Parser->Lookup(MetaKey);
  168. if (R == NULL)
  169. return HashStringList();
  170. return R->Hashes;
  171. }
  172. /*}}}*/
  173. // all ::HashesRequired and ::GetExpectedHashes implementations /*{{{*/
  174. /* ::GetExpectedHashes is abstract and has to be implemented by all subclasses.
  175. It is best to implement it as broadly as possible, while ::HashesRequired defaults
  176. to true and should be as restrictive as possible for false cases. Note that if
  177. a hash is returned by ::GetExpectedHashes it must match. Only if it doesn't
  178. ::HashesRequired is called to evaluate if its okay to have no hashes. */
  179. APT_CONST bool pkgAcqTransactionItem::HashesRequired() const
  180. {
  181. /* signed repositories obviously have a parser and good hashes.
  182. unsigned repositories, too, as even if we can't trust them for security,
  183. we can at least trust them for integrity of the download itself.
  184. Only repositories without a Release file can (obviously) not have
  185. hashes – and they are very uncommon and strongly discouraged */
  186. return TransactionManager->MetaIndexParser != NULL &&
  187. TransactionManager->MetaIndexParser->GetLoadedSuccessfully() == metaIndex::TRI_YES;
  188. }
  189. HashStringList pkgAcqTransactionItem::GetExpectedHashes() const
  190. {
  191. return GetExpectedHashesFor(GetMetaKey());
  192. }
  193. APT_CONST bool pkgAcqMetaBase::HashesRequired() const
  194. {
  195. // Release and co have no hashes 'by design'.
  196. return false;
  197. }
  198. HashStringList pkgAcqMetaBase::GetExpectedHashes() const
  199. {
  200. return HashStringList();
  201. }
  202. APT_CONST bool pkgAcqIndexDiffs::HashesRequired() const
  203. {
  204. /* We can't check hashes of rred result as we don't know what the
  205. hash of the file will be. We just know the hash of the patch(es),
  206. the hash of the file they will apply on and the hash of the resulting
  207. file. */
  208. if (State == StateFetchDiff)
  209. return true;
  210. return false;
  211. }
  212. HashStringList pkgAcqIndexDiffs::GetExpectedHashes() const
  213. {
  214. if (State == StateFetchDiff)
  215. return available_patches[0].download_hashes;
  216. return HashStringList();
  217. }
  218. APT_CONST bool pkgAcqIndexMergeDiffs::HashesRequired() const
  219. {
  220. /* @see #pkgAcqIndexDiffs::HashesRequired, with the difference that
  221. we can check the rred result after all patches are applied as
  222. we know the expected result rather than potentially apply more patches */
  223. if (State == StateFetchDiff)
  224. return true;
  225. return State == StateApplyDiff;
  226. }
  227. HashStringList pkgAcqIndexMergeDiffs::GetExpectedHashes() const
  228. {
  229. if (State == StateFetchDiff)
  230. return patch.download_hashes;
  231. else if (State == StateApplyDiff)
  232. return GetExpectedHashesFor(Target.MetaKey);
  233. return HashStringList();
  234. }
  235. APT_CONST bool pkgAcqArchive::HashesRequired() const
  236. {
  237. return LocalSource == false;
  238. }
  239. HashStringList pkgAcqArchive::GetExpectedHashes() const
  240. {
  241. // figured out while parsing the records
  242. return ExpectedHashes;
  243. }
  244. APT_CONST bool pkgAcqFile::HashesRequired() const
  245. {
  246. // supplied as parameter at creation time, so the caller decides
  247. return ExpectedHashes.usable();
  248. }
  249. HashStringList pkgAcqFile::GetExpectedHashes() const
  250. {
  251. return ExpectedHashes;
  252. }
  253. /*}}}*/
  254. // Acquire::Item::QueueURI and specialisations from child classes /*{{{*/
  255. bool pkgAcquire::Item::QueueURI(pkgAcquire::ItemDesc &Item)
  256. {
  257. Owner->Enqueue(Item);
  258. return true;
  259. }
  260. /* The idea here is that an item isn't queued if it exists on disk and the
  261. transition manager was a hit as this means that the files it contains
  262. the checksums for can't be updated either (or they are and we are asking
  263. for a hashsum mismatch to happen which helps nobody) */
  264. bool pkgAcqTransactionItem::QueueURI(pkgAcquire::ItemDesc &Item)
  265. {
  266. if (TransactionManager->State != TransactionStarted)
  267. {
  268. if (_config->FindB("Debug::Acquire::Transaction", false))
  269. std::clog << "Skip " << Target.URI << " as transaction was already dealt with!" << std::endl;
  270. return false;
  271. }
  272. std::string const FinalFile = GetFinalFilename();
  273. if (TransactionManager != NULL && TransactionManager->IMSHit == true &&
  274. FileExists(FinalFile) == true)
  275. {
  276. PartialFile = DestFile = FinalFile;
  277. Status = StatDone;
  278. return false;
  279. }
  280. return pkgAcquire::Item::QueueURI(Item);
  281. }
  282. /* The transition manager InRelease itself (or its older sisters-in-law
  283. Release & Release.gpg) is always queued as this allows us to rerun gpgv
  284. on it to verify that we aren't stalled with old files */
  285. bool pkgAcqMetaBase::QueueURI(pkgAcquire::ItemDesc &Item)
  286. {
  287. return pkgAcquire::Item::QueueURI(Item);
  288. }
  289. /* the Diff/Index needs to queue also the up-to-date complete index file
  290. to ensure that the list cleaner isn't eating it */
  291. bool pkgAcqDiffIndex::QueueURI(pkgAcquire::ItemDesc &Item)
  292. {
  293. if (pkgAcqTransactionItem::QueueURI(Item) == true)
  294. return true;
  295. QueueOnIMSHit();
  296. return false;
  297. }
  298. /*}}}*/
  299. // Acquire::Item::GetFinalFilename and specialisations for child classes /*{{{*/
  300. std::string pkgAcquire::Item::GetFinalFilename() const
  301. {
  302. // Beware: Desc.URI is modified by redirections
  303. return GetFinalFileNameFromURI(Desc.URI);
  304. }
  305. std::string pkgAcqDiffIndex::GetFinalFilename() const
  306. {
  307. return GetFinalFileNameFromURI(GetDiffIndexURI(Target));
  308. }
  309. std::string pkgAcqIndex::GetFinalFilename() const
  310. {
  311. std::string const FinalFile = GetFinalFileNameFromURI(Target.URI);
  312. return GetKeepCompressedFileName(FinalFile, Target);
  313. }
  314. std::string pkgAcqMetaSig::GetFinalFilename() const
  315. {
  316. return GetFinalFileNameFromURI(Target.URI);
  317. }
  318. std::string pkgAcqBaseIndex::GetFinalFilename() const
  319. {
  320. return GetFinalFileNameFromURI(Target.URI);
  321. }
  322. std::string pkgAcqMetaBase::GetFinalFilename() const
  323. {
  324. return GetFinalFileNameFromURI(Target.URI);
  325. }
  326. std::string pkgAcqArchive::GetFinalFilename() const
  327. {
  328. return _config->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename);
  329. }
  330. /*}}}*/
  331. // pkgAcqTransactionItem::GetMetaKey and specialisations for child classes /*{{{*/
  332. std::string pkgAcqTransactionItem::GetMetaKey() const
  333. {
  334. return Target.MetaKey;
  335. }
  336. std::string pkgAcqIndex::GetMetaKey() const
  337. {
  338. if (Stage == STAGE_DECOMPRESS_AND_VERIFY || CurrentCompressionExtension == "uncompressed")
  339. return Target.MetaKey;
  340. return Target.MetaKey + "." + CurrentCompressionExtension;
  341. }
  342. std::string pkgAcqDiffIndex::GetMetaKey() const
  343. {
  344. return GetDiffIndexFileName(Target.MetaKey);
  345. }
  346. /*}}}*/
  347. //pkgAcqTransactionItem::TransactionState and specialisations for child classes /*{{{*/
  348. bool pkgAcqTransactionItem::TransactionState(TransactionStates const state)
  349. {
  350. bool const Debug = _config->FindB("Debug::Acquire::Transaction", false);
  351. switch(state)
  352. {
  353. case TransactionStarted: _error->Fatal("Item %s changed to invalid transaction start state!", Target.URI.c_str()); break;
  354. case TransactionAbort:
  355. if(Debug == true)
  356. std::clog << " Cancel: " << DestFile << std::endl;
  357. if (Status == pkgAcquire::Item::StatIdle)
  358. {
  359. Status = pkgAcquire::Item::StatDone;
  360. Dequeue();
  361. }
  362. break;
  363. case TransactionCommit:
  364. if(PartialFile.empty() == false)
  365. {
  366. bool sameFile = (PartialFile == DestFile);
  367. // we use symlinks on IMS-Hit to avoid copies
  368. if (RealFileExists(DestFile))
  369. {
  370. struct stat Buf;
  371. if (lstat(PartialFile.c_str(), &Buf) != -1)
  372. {
  373. if (S_ISLNK(Buf.st_mode) && Buf.st_size > 0)
  374. {
  375. char partial[Buf.st_size + 1];
  376. ssize_t const sp = readlink(PartialFile.c_str(), partial, Buf.st_size);
  377. if (sp == -1)
  378. _error->Errno("pkgAcqTransactionItem::TransactionState-sp", _("Failed to readlink %s"), PartialFile.c_str());
  379. else
  380. {
  381. partial[sp] = '\0';
  382. sameFile = (DestFile == partial);
  383. }
  384. }
  385. }
  386. else
  387. _error->Errno("pkgAcqTransactionItem::TransactionState-stat", _("Failed to stat %s"), PartialFile.c_str());
  388. }
  389. if (sameFile == false)
  390. {
  391. // ensure that even without lists-cleanup all compressions are nuked
  392. std::string FinalFile = GetFinalFileNameFromURI(Target.URI);
  393. if (FileExists(FinalFile))
  394. {
  395. if(Debug == true)
  396. std::clog << "rm " << FinalFile << " # " << DescURI() << std::endl;
  397. if (RemoveFile("TransactionStates-Cleanup", FinalFile) == false)
  398. return false;
  399. }
  400. for (auto const &ext: APT::Configuration::getCompressorExtensions())
  401. {
  402. auto const Final = FinalFile + ext;
  403. if (FileExists(Final))
  404. {
  405. if(Debug == true)
  406. std::clog << "rm " << Final << " # " << DescURI() << std::endl;
  407. if (RemoveFile("TransactionStates-Cleanup", Final) == false)
  408. return false;
  409. }
  410. }
  411. if(Debug == true)
  412. std::clog << "mv " << PartialFile << " -> "<< DestFile << " # " << DescURI() << std::endl;
  413. if (Rename(PartialFile, DestFile) == false)
  414. return false;
  415. }
  416. else if(Debug == true)
  417. std::clog << "keep " << PartialFile << " # " << DescURI() << std::endl;
  418. } else {
  419. if(Debug == true)
  420. std::clog << "rm " << DestFile << " # " << DescURI() << std::endl;
  421. if (RemoveFile("TransItem::TransactionCommit", DestFile) == false)
  422. return false;
  423. }
  424. break;
  425. }
  426. return true;
  427. }
  428. bool pkgAcqMetaBase::TransactionState(TransactionStates const state)
  429. {
  430. // Do not remove InRelease on IMSHit of Release.gpg [yes, this is very edgecasey]
  431. if (TransactionManager->IMSHit == false)
  432. return pkgAcqTransactionItem::TransactionState(state);
  433. return true;
  434. }
  435. bool pkgAcqIndex::TransactionState(TransactionStates const state)
  436. {
  437. if (pkgAcqTransactionItem::TransactionState(state) == false)
  438. return false;
  439. switch (state)
  440. {
  441. case TransactionStarted: _error->Fatal("AcqIndex %s changed to invalid transaction start state!", Target.URI.c_str()); break;
  442. case TransactionAbort:
  443. if (Stage == STAGE_DECOMPRESS_AND_VERIFY)
  444. {
  445. // keep the compressed file, but drop the decompressed
  446. EraseFileName.clear();
  447. if (PartialFile.empty() == false && flExtension(PartialFile) != CurrentCompressionExtension)
  448. RemoveFile("TransactionAbort", PartialFile);
  449. }
  450. break;
  451. case TransactionCommit:
  452. if (EraseFileName.empty() == false)
  453. RemoveFile("AcqIndex::TransactionCommit", EraseFileName);
  454. break;
  455. }
  456. return true;
  457. }
  458. bool pkgAcqDiffIndex::TransactionState(TransactionStates const state)
  459. {
  460. if (pkgAcqTransactionItem::TransactionState(state) == false)
  461. return false;
  462. switch (state)
  463. {
  464. case TransactionStarted: _error->Fatal("Item %s changed to invalid transaction start state!", Target.URI.c_str()); break;
  465. case TransactionCommit:
  466. break;
  467. case TransactionAbort:
  468. std::string const Partial = GetPartialFileNameFromURI(Target.URI);
  469. RemoveFile("TransactionAbort", Partial);
  470. break;
  471. }
  472. return true;
  473. }
  474. /*}}}*/
  475. class APT_HIDDEN NoActionItem : public pkgAcquire::Item /*{{{*/
  476. /* The sole purpose of this class is having an item which does nothing to
  477. reach its done state to prevent cleanup deleting the mentioned file.
  478. Handy in cases in which we know we have the file already, like IMS-Hits. */
  479. {
  480. IndexTarget const Target;
  481. public:
  482. virtual std::string DescURI() const APT_OVERRIDE {return Target.URI;};
  483. virtual HashStringList GetExpectedHashes() const APT_OVERRIDE {return HashStringList();};
  484. NoActionItem(pkgAcquire * const Owner, IndexTarget const &Target) :
  485. pkgAcquire::Item(Owner), Target(Target)
  486. {
  487. Status = StatDone;
  488. DestFile = GetFinalFileNameFromURI(Target.URI);
  489. }
  490. NoActionItem(pkgAcquire * const Owner, IndexTarget const &Target, std::string const &FinalFile) :
  491. pkgAcquire::Item(Owner), Target(Target)
  492. {
  493. Status = StatDone;
  494. DestFile = FinalFile;
  495. }
  496. };
  497. /*}}}*/
  498. // Acquire::Item::Item - Constructor /*{{{*/
  499. APT_IGNORE_DEPRECATED_PUSH
  500. pkgAcquire::Item::Item(pkgAcquire * const owner) :
  501. FileSize(0), PartialSize(0), Mode(0), ID(0), Complete(false), Local(false),
  502. QueueCounter(0), ExpectedAdditionalItems(0), Owner(owner), d(NULL)
  503. {
  504. Owner->Add(this);
  505. Status = StatIdle;
  506. }
  507. APT_IGNORE_DEPRECATED_POP
  508. /*}}}*/
  509. // Acquire::Item::~Item - Destructor /*{{{*/
  510. pkgAcquire::Item::~Item()
  511. {
  512. Owner->Remove(this);
  513. }
  514. /*}}}*/
  515. std::string pkgAcquire::Item::Custom600Headers() const /*{{{*/
  516. {
  517. return std::string();
  518. }
  519. /*}}}*/
  520. std::string pkgAcquire::Item::ShortDesc() const /*{{{*/
  521. {
  522. return DescURI();
  523. }
  524. /*}}}*/
  525. APT_CONST void pkgAcquire::Item::Finished() /*{{{*/
  526. {
  527. }
  528. /*}}}*/
  529. APT_PURE pkgAcquire * pkgAcquire::Item::GetOwner() const /*{{{*/
  530. {
  531. return Owner;
  532. }
  533. /*}}}*/
  534. APT_CONST pkgAcquire::ItemDesc &pkgAcquire::Item::GetItemDesc() /*{{{*/
  535. {
  536. return Desc;
  537. }
  538. /*}}}*/
  539. APT_CONST bool pkgAcquire::Item::IsTrusted() const /*{{{*/
  540. {
  541. return false;
  542. }
  543. /*}}}*/
  544. // Acquire::Item::Failed - Item failed to download /*{{{*/
  545. // ---------------------------------------------------------------------
  546. /* We return to an idle state if there are still other queues that could
  547. fetch this object */
  548. void pkgAcquire::Item::Failed(string const &Message,pkgAcquire::MethodConfig const * const Cnf)
  549. {
  550. if(ErrorText.empty())
  551. ErrorText = LookupTag(Message,"Message");
  552. if (QueueCounter <= 1)
  553. {
  554. /* This indicates that the file is not available right now but might
  555. be sometime later. If we do a retry cycle then this should be
  556. retried [CDROMs] */
  557. if (Cnf != NULL && Cnf->LocalOnly == true &&
  558. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  559. {
  560. Status = StatIdle;
  561. Dequeue();
  562. return;
  563. }
  564. switch (Status)
  565. {
  566. case StatIdle:
  567. case StatFetching:
  568. case StatDone:
  569. Status = StatError;
  570. break;
  571. case StatAuthError:
  572. case StatError:
  573. case StatTransientNetworkError:
  574. break;
  575. }
  576. Complete = false;
  577. Dequeue();
  578. }
  579. string const FailReason = LookupTag(Message, "FailReason");
  580. if (FailReason == "MaximumSizeExceeded")
  581. RenameOnError(MaximumSizeExceeded);
  582. else if (Status == StatAuthError)
  583. RenameOnError(HashSumMismatch);
  584. // report mirror failure back to LP if we actually use a mirror
  585. if (FailReason.empty() == false)
  586. ReportMirrorFailure(FailReason);
  587. else
  588. ReportMirrorFailure(ErrorText);
  589. if (QueueCounter > 1)
  590. Status = StatIdle;
  591. }
  592. /*}}}*/
  593. // Acquire::Item::Start - Item has begun to download /*{{{*/
  594. // ---------------------------------------------------------------------
  595. /* Stash status and the file size. Note that setting Complete means
  596. sub-phases of the acquire process such as decompresion are operating */
  597. void pkgAcquire::Item::Start(string const &/*Message*/, unsigned long long const Size)
  598. {
  599. Status = StatFetching;
  600. ErrorText.clear();
  601. if (FileSize == 0 && Complete == false)
  602. FileSize = Size;
  603. }
  604. /*}}}*/
  605. // Acquire::Item::VerifyDone - check if Item was downloaded OK /*{{{*/
  606. /* Note that hash-verification is 'hardcoded' in acquire-worker and has
  607. * already passed if this method is called. */
  608. bool pkgAcquire::Item::VerifyDone(std::string const &Message,
  609. pkgAcquire::MethodConfig const * const /*Cnf*/)
  610. {
  611. std::string const FileName = LookupTag(Message,"Filename");
  612. if (FileName.empty() == true)
  613. {
  614. Status = StatError;
  615. ErrorText = "Method gave a blank filename";
  616. return false;
  617. }
  618. return true;
  619. }
  620. /*}}}*/
  621. // Acquire::Item::Done - Item downloaded OK /*{{{*/
  622. void pkgAcquire::Item::Done(string const &/*Message*/, HashStringList const &Hashes,
  623. pkgAcquire::MethodConfig const * const /*Cnf*/)
  624. {
  625. // We just downloaded something..
  626. if (FileSize == 0)
  627. {
  628. unsigned long long const downloadedSize = Hashes.FileSize();
  629. if (downloadedSize != 0)
  630. {
  631. FileSize = downloadedSize;
  632. }
  633. }
  634. Status = StatDone;
  635. ErrorText = string();
  636. Owner->Dequeue(this);
  637. }
  638. /*}}}*/
  639. // Acquire::Item::Rename - Rename a file /*{{{*/
  640. // ---------------------------------------------------------------------
  641. /* This helper function is used by a lot of item methods as their final
  642. step */
  643. bool pkgAcquire::Item::Rename(string const &From,string const &To)
  644. {
  645. if (From == To || rename(From.c_str(),To.c_str()) == 0)
  646. return true;
  647. std::string S;
  648. strprintf(S, _("rename failed, %s (%s -> %s)."), strerror(errno),
  649. From.c_str(),To.c_str());
  650. Status = StatError;
  651. if (ErrorText.empty())
  652. ErrorText = S;
  653. else
  654. ErrorText = ErrorText + ": " + S;
  655. return false;
  656. }
  657. /*}}}*/
  658. void pkgAcquire::Item::Dequeue() /*{{{*/
  659. {
  660. Owner->Dequeue(this);
  661. }
  662. /*}}}*/
  663. bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState const error)/*{{{*/
  664. {
  665. if (RealFileExists(DestFile))
  666. Rename(DestFile, DestFile + ".FAILED");
  667. std::string errtext;
  668. switch (error)
  669. {
  670. case HashSumMismatch:
  671. errtext = _("Hash Sum mismatch");
  672. Status = StatAuthError;
  673. ReportMirrorFailure("HashChecksumFailure");
  674. break;
  675. case SizeMismatch:
  676. errtext = _("Size mismatch");
  677. Status = StatAuthError;
  678. ReportMirrorFailure("SizeFailure");
  679. break;
  680. case InvalidFormat:
  681. errtext = _("Invalid file format");
  682. Status = StatError;
  683. // do not report as usually its not the mirrors fault, but Portal/Proxy
  684. break;
  685. case SignatureError:
  686. errtext = _("Signature error");
  687. Status = StatError;
  688. break;
  689. case NotClearsigned:
  690. strprintf(errtext, _("Clearsigned file isn't valid, got '%s' (does the network require authentication?)"), "NOSPLIT");
  691. Status = StatAuthError;
  692. break;
  693. case MaximumSizeExceeded:
  694. // the method is expected to report a good error for this
  695. Status = StatError;
  696. break;
  697. case PDiffError:
  698. // no handling here, done by callers
  699. break;
  700. }
  701. if (ErrorText.empty())
  702. ErrorText = errtext;
  703. return false;
  704. }
  705. /*}}}*/
  706. void pkgAcquire::Item::SetActiveSubprocess(const std::string &subprocess)/*{{{*/
  707. {
  708. ActiveSubprocess = subprocess;
  709. APT_IGNORE_DEPRECATED(Mode = ActiveSubprocess.c_str();)
  710. }
  711. /*}}}*/
  712. // Acquire::Item::ReportMirrorFailure /*{{{*/
  713. void pkgAcquire::Item::ReportMirrorFailure(string const &FailCode)
  714. {
  715. // we only act if a mirror was used at all
  716. if(UsedMirror.empty())
  717. return;
  718. #if 0
  719. std::cerr << "\nReportMirrorFailure: "
  720. << UsedMirror
  721. << " Uri: " << DescURI()
  722. << " FailCode: "
  723. << FailCode << std::endl;
  724. #endif
  725. string report = _config->Find("Methods::Mirror::ProblemReporting",
  726. "/usr/lib/apt/apt-report-mirror-failure");
  727. if(!FileExists(report))
  728. return;
  729. std::vector<char const*> Args;
  730. Args.push_back(report.c_str());
  731. Args.push_back(UsedMirror.c_str());
  732. Args.push_back(DescURI().c_str());
  733. Args.push_back(FailCode.c_str());
  734. Args.push_back(NULL);
  735. pid_t pid = ExecFork();
  736. if(pid < 0)
  737. {
  738. _error->Error("ReportMirrorFailure Fork failed");
  739. return;
  740. }
  741. else if(pid == 0)
  742. {
  743. execvp(Args[0], (char**)Args.data());
  744. std::cerr << "Could not exec " << Args[0] << std::endl;
  745. _exit(100);
  746. }
  747. if(!ExecWait(pid, "report-mirror-failure"))
  748. {
  749. _error->Warning("Couldn't report problem to '%s'",
  750. _config->Find("Methods::Mirror::ProblemReporting").c_str());
  751. }
  752. }
  753. /*}}}*/
  754. std::string pkgAcquire::Item::HashSum() const /*{{{*/
  755. {
  756. HashStringList const hashes = GetExpectedHashes();
  757. HashString const * const hs = hashes.find(NULL);
  758. return hs != NULL ? hs->toStr() : "";
  759. }
  760. /*}}}*/
  761. pkgAcqTransactionItem::pkgAcqTransactionItem(pkgAcquire * const Owner, /*{{{*/
  762. pkgAcqMetaClearSig * const transactionManager, IndexTarget const &target) :
  763. pkgAcquire::Item(Owner), d(NULL), Target(target), TransactionManager(transactionManager)
  764. {
  765. if (TransactionManager != this)
  766. TransactionManager->Add(this);
  767. }
  768. /*}}}*/
  769. pkgAcqTransactionItem::~pkgAcqTransactionItem() /*{{{*/
  770. {
  771. }
  772. /*}}}*/
  773. HashStringList pkgAcqTransactionItem::GetExpectedHashesFor(std::string const &MetaKey) const /*{{{*/
  774. {
  775. return GetExpectedHashesFromFor(TransactionManager->MetaIndexParser, MetaKey);
  776. }
  777. /*}}}*/
  778. static void LoadLastMetaIndexParser(pkgAcqMetaClearSig * const TransactionManager, std::string const &FinalRelease, std::string const &FinalInRelease)/*{{{*/
  779. {
  780. if (TransactionManager->IMSHit == true)
  781. return;
  782. if (RealFileExists(FinalInRelease) || RealFileExists(FinalRelease))
  783. {
  784. TransactionManager->LastMetaIndexParser = TransactionManager->MetaIndexParser->UnloadedClone();
  785. if (TransactionManager->LastMetaIndexParser != NULL)
  786. {
  787. _error->PushToStack();
  788. if (RealFileExists(FinalInRelease))
  789. TransactionManager->LastMetaIndexParser->Load(FinalInRelease, NULL);
  790. else
  791. TransactionManager->LastMetaIndexParser->Load(FinalRelease, NULL);
  792. // its unlikely to happen, but if what we have is bad ignore it
  793. if (_error->PendingError())
  794. {
  795. delete TransactionManager->LastMetaIndexParser;
  796. TransactionManager->LastMetaIndexParser = NULL;
  797. }
  798. _error->RevertToStack();
  799. }
  800. }
  801. }
  802. /*}}}*/
  803. // AcqMetaBase - Constructor /*{{{*/
  804. pkgAcqMetaBase::pkgAcqMetaBase(pkgAcquire * const Owner,
  805. pkgAcqMetaClearSig * const TransactionManager,
  806. std::vector<IndexTarget> const &IndexTargets,
  807. IndexTarget const &DataTarget)
  808. : pkgAcqTransactionItem(Owner, TransactionManager, DataTarget), d(NULL),
  809. IndexTargets(IndexTargets),
  810. AuthPass(false), IMSHit(false), State(TransactionStarted)
  811. {
  812. }
  813. /*}}}*/
  814. // AcqMetaBase::Add - Add a item to the current Transaction /*{{{*/
  815. void pkgAcqMetaBase::Add(pkgAcqTransactionItem * const I)
  816. {
  817. Transaction.push_back(I);
  818. }
  819. /*}}}*/
  820. // AcqMetaBase::AbortTransaction - Abort the current Transaction /*{{{*/
  821. void pkgAcqMetaBase::AbortTransaction()
  822. {
  823. if(_config->FindB("Debug::Acquire::Transaction", false) == true)
  824. std::clog << "AbortTransaction: " << TransactionManager << std::endl;
  825. switch (TransactionManager->State)
  826. {
  827. case TransactionStarted: break;
  828. case TransactionAbort: _error->Fatal("Transaction %s was already aborted and is aborted again", TransactionManager->Target.URI.c_str()); return;
  829. case TransactionCommit: _error->Fatal("Transaction %s was already aborted and is now commited", TransactionManager->Target.URI.c_str()); return;
  830. }
  831. TransactionManager->State = TransactionAbort;
  832. // ensure the toplevel is in error state too
  833. for (std::vector<pkgAcqTransactionItem*>::iterator I = Transaction.begin();
  834. I != Transaction.end(); ++I)
  835. {
  836. if ((*I)->Status != pkgAcquire::Item::StatFetching)
  837. Owner->Dequeue(*I);
  838. (*I)->TransactionState(TransactionAbort);
  839. }
  840. Transaction.clear();
  841. }
  842. /*}}}*/
  843. // AcqMetaBase::TransactionHasError - Check for errors in Transaction /*{{{*/
  844. APT_PURE bool pkgAcqMetaBase::TransactionHasError() const
  845. {
  846. for (std::vector<pkgAcqTransactionItem*>::const_iterator I = Transaction.begin();
  847. I != Transaction.end(); ++I)
  848. {
  849. switch((*I)->Status) {
  850. case StatDone: break;
  851. case StatIdle: break;
  852. case StatAuthError: return true;
  853. case StatError: return true;
  854. case StatTransientNetworkError: return true;
  855. case StatFetching: break;
  856. }
  857. }
  858. return false;
  859. }
  860. /*}}}*/
  861. // AcqMetaBase::CommitTransaction - Commit a transaction /*{{{*/
  862. void pkgAcqMetaBase::CommitTransaction()
  863. {
  864. if(_config->FindB("Debug::Acquire::Transaction", false) == true)
  865. std::clog << "CommitTransaction: " << this << std::endl;
  866. switch (TransactionManager->State)
  867. {
  868. case TransactionStarted: break;
  869. case TransactionAbort: _error->Fatal("Transaction %s was already commited and is now aborted", TransactionManager->Target.URI.c_str()); return;
  870. case TransactionCommit: _error->Fatal("Transaction %s was already commited and is again commited", TransactionManager->Target.URI.c_str()); return;
  871. }
  872. TransactionManager->State = TransactionCommit;
  873. // move new files into place *and* remove files that are not
  874. // part of the transaction but are still on disk
  875. for (std::vector<pkgAcqTransactionItem*>::iterator I = Transaction.begin();
  876. I != Transaction.end(); ++I)
  877. {
  878. (*I)->TransactionState(TransactionCommit);
  879. }
  880. Transaction.clear();
  881. }
  882. /*}}}*/
  883. // AcqMetaBase::TransactionStageCopy - Stage a file for copying /*{{{*/
  884. void pkgAcqMetaBase::TransactionStageCopy(pkgAcqTransactionItem * const I,
  885. const std::string &From,
  886. const std::string &To)
  887. {
  888. I->PartialFile = From;
  889. I->DestFile = To;
  890. }
  891. /*}}}*/
  892. // AcqMetaBase::TransactionStageRemoval - Stage a file for removal /*{{{*/
  893. void pkgAcqMetaBase::TransactionStageRemoval(pkgAcqTransactionItem * const I,
  894. const std::string &FinalFile)
  895. {
  896. I->PartialFile = "";
  897. I->DestFile = FinalFile;
  898. }
  899. /*}}}*/
  900. // AcqMetaBase::GenerateAuthWarning - Check gpg authentication error /*{{{*/
  901. bool pkgAcqMetaBase::CheckStopAuthentication(pkgAcquire::Item * const I, const std::string &Message)
  902. {
  903. // FIXME: this entire function can do now that we disallow going to
  904. // a unauthenticated state and can cleanly rollback
  905. string const Final = I->GetFinalFilename();
  906. if(FileExists(Final))
  907. {
  908. I->Status = StatTransientNetworkError;
  909. _error->Warning(_("An error occurred during the signature "
  910. "verification. The repository is not updated "
  911. "and the previous index files will be used. "
  912. "GPG error: %s: %s"),
  913. Desc.Description.c_str(),
  914. LookupTag(Message,"Message").c_str());
  915. RunScripts("APT::Update::Auth-Failure");
  916. return true;
  917. } else if (LookupTag(Message,"Message").find("NODATA") != string::npos) {
  918. /* Invalid signature file, reject (LP: #346386) (Closes: #627642) */
  919. _error->Error(_("GPG error: %s: %s"),
  920. Desc.Description.c_str(),
  921. LookupTag(Message,"Message").c_str());
  922. I->Status = StatAuthError;
  923. return true;
  924. } else {
  925. _error->Warning(_("GPG error: %s: %s"),
  926. Desc.Description.c_str(),
  927. LookupTag(Message,"Message").c_str());
  928. }
  929. // gpgv method failed
  930. ReportMirrorFailure("GPGFailure");
  931. return false;
  932. }
  933. /*}}}*/
  934. // AcqMetaBase::Custom600Headers - Get header for AcqMetaBase /*{{{*/
  935. // ---------------------------------------------------------------------
  936. string pkgAcqMetaBase::Custom600Headers() const
  937. {
  938. std::string Header = "\nIndex-File: true";
  939. std::string MaximumSize;
  940. strprintf(MaximumSize, "\nMaximum-Size: %i",
  941. _config->FindI("Acquire::MaxReleaseFileSize", 10*1000*1000));
  942. Header += MaximumSize;
  943. string const FinalFile = GetFinalFilename();
  944. struct stat Buf;
  945. if (stat(FinalFile.c_str(),&Buf) == 0)
  946. Header += "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  947. return Header;
  948. }
  949. /*}}}*/
  950. // AcqMetaBase::QueueForSignatureVerify /*{{{*/
  951. void pkgAcqMetaBase::QueueForSignatureVerify(pkgAcqTransactionItem * const I, std::string const &File, std::string const &Signature)
  952. {
  953. AuthPass = true;
  954. I->Desc.URI = "gpgv:" + Signature;
  955. I->DestFile = File;
  956. QueueURI(I->Desc);
  957. I->SetActiveSubprocess("gpgv");
  958. }
  959. /*}}}*/
  960. // AcqMetaBase::CheckDownloadDone /*{{{*/
  961. bool pkgAcqMetaBase::CheckDownloadDone(pkgAcqTransactionItem * const I, const std::string &Message, HashStringList const &Hashes) const
  962. {
  963. // We have just finished downloading a Release file (it is not
  964. // verified yet)
  965. std::string const FileName = LookupTag(Message,"Filename");
  966. if (FileName != I->DestFile && RealFileExists(I->DestFile) == false)
  967. {
  968. I->Local = true;
  969. I->Desc.URI = "copy:" + FileName;
  970. I->QueueURI(I->Desc);
  971. return false;
  972. }
  973. // make sure to verify against the right file on I-M-S hit
  974. bool IMSHit = StringToBool(LookupTag(Message,"IMS-Hit"), false);
  975. if (IMSHit == false && Hashes.usable())
  976. {
  977. // detect IMS-Hits servers haven't detected by Hash comparison
  978. std::string const FinalFile = I->GetFinalFilename();
  979. if (RealFileExists(FinalFile) && Hashes.VerifyFile(FinalFile) == true)
  980. {
  981. IMSHit = true;
  982. RemoveFile("CheckDownloadDone", I->DestFile);
  983. }
  984. }
  985. if(IMSHit == true)
  986. {
  987. // for simplicity, the transaction manager is always InRelease
  988. // even if it doesn't exist.
  989. if (TransactionManager != NULL)
  990. TransactionManager->IMSHit = true;
  991. I->PartialFile = I->DestFile = I->GetFinalFilename();
  992. }
  993. // set Item to complete as the remaining work is all local (verify etc)
  994. I->Complete = true;
  995. return true;
  996. }
  997. /*}}}*/
  998. bool pkgAcqMetaBase::CheckAuthDone(string const &Message) /*{{{*/
  999. {
  1000. // At this point, the gpgv method has succeeded, so there is a
  1001. // valid signature from a key in the trusted keyring. We
  1002. // perform additional verification of its contents, and use them
  1003. // to verify the indexes we are about to download
  1004. if (TransactionManager->IMSHit == false)
  1005. {
  1006. // open the last (In)Release if we have it
  1007. std::string const FinalFile = GetFinalFilename();
  1008. std::string FinalRelease;
  1009. std::string FinalInRelease;
  1010. if (APT::String::Endswith(FinalFile, "InRelease"))
  1011. {
  1012. FinalInRelease = FinalFile;
  1013. FinalRelease = FinalFile.substr(0, FinalFile.length() - strlen("InRelease")) + "Release";
  1014. }
  1015. else
  1016. {
  1017. FinalInRelease = FinalFile.substr(0, FinalFile.length() - strlen("Release")) + "InRelease";
  1018. FinalRelease = FinalFile;
  1019. }
  1020. LoadLastMetaIndexParser(TransactionManager, FinalRelease, FinalInRelease);
  1021. }
  1022. if (TransactionManager->MetaIndexParser->Load(DestFile, &ErrorText) == false)
  1023. {
  1024. Status = StatAuthError;
  1025. return false;
  1026. }
  1027. if (!VerifyVendor(Message))
  1028. {
  1029. Status = StatAuthError;
  1030. return false;
  1031. }
  1032. if (_config->FindB("Debug::pkgAcquire::Auth", false))
  1033. std::cerr << "Signature verification succeeded: "
  1034. << DestFile << std::endl;
  1035. // Download further indexes with verification
  1036. QueueIndexes(true);
  1037. return true;
  1038. }
  1039. /*}}}*/
  1040. void pkgAcqMetaBase::QueueIndexes(bool const verify) /*{{{*/
  1041. {
  1042. // at this point the real Items are loaded in the fetcher
  1043. ExpectedAdditionalItems = 0;
  1044. bool metaBaseSupportsByHash = false;
  1045. if (TransactionManager != NULL && TransactionManager->MetaIndexParser != NULL)
  1046. metaBaseSupportsByHash = TransactionManager->MetaIndexParser->GetSupportsAcquireByHash();
  1047. for (std::vector <IndexTarget>::iterator Target = IndexTargets.begin();
  1048. Target != IndexTargets.end();
  1049. ++Target)
  1050. {
  1051. // all is an implementation detail. Users shouldn't use this as arch
  1052. // We need this support trickery here as e.g. Debian has binary-all files already,
  1053. // but arch:all packages are still in the arch:any files, so we would waste precious
  1054. // download time, bandwidth and diskspace for nothing, BUT Debian doesn't feature all
  1055. // in the set of supported architectures, so we can filter based on this property rather
  1056. // than invent an entirely new flag we would need to carry for all of eternity.
  1057. if (Target->Option(IndexTarget::ARCHITECTURE) == "all")
  1058. {
  1059. if (TransactionManager->MetaIndexParser->IsArchitectureSupported("all") == false)
  1060. continue;
  1061. if (TransactionManager->MetaIndexParser->IsArchitectureAllSupportedFor(*Target) == false)
  1062. continue;
  1063. }
  1064. bool trypdiff = Target->OptionBool(IndexTarget::PDIFFS);
  1065. if (verify == true)
  1066. {
  1067. if (TransactionManager->MetaIndexParser->Exists(Target->MetaKey) == false)
  1068. {
  1069. // optional targets that we do not have in the Release file are skipped
  1070. if (Target->IsOptional)
  1071. continue;
  1072. std::string const &arch = Target->Option(IndexTarget::ARCHITECTURE);
  1073. if (arch.empty() == false)
  1074. {
  1075. if (TransactionManager->MetaIndexParser->IsArchitectureSupported(arch) == false)
  1076. {
  1077. _error->Notice(_("Skipping acquire of configured file '%s' as repository '%s' doesn't support architecture '%s'"),
  1078. Target->MetaKey.c_str(), TransactionManager->Target.Description.c_str(), arch.c_str());
  1079. continue;
  1080. }
  1081. // if the architecture is officially supported but currently no packages for it available,
  1082. // ignore silently as this is pretty much the same as just shipping an empty file.
  1083. // if we don't know which architectures are supported, we do NOT ignore it to notify user about this
  1084. if (TransactionManager->MetaIndexParser->IsArchitectureSupported("*undefined*") == false)
  1085. continue;
  1086. }
  1087. Status = StatAuthError;
  1088. strprintf(ErrorText, _("Unable to find expected entry '%s' in Release file (Wrong sources.list entry or malformed file)"), Target->MetaKey.c_str());
  1089. return;
  1090. }
  1091. else
  1092. {
  1093. auto const hashes = GetExpectedHashesFor(Target->MetaKey);
  1094. if (hashes.empty() == false)
  1095. {
  1096. if (hashes.usable() == false)
  1097. {
  1098. _error->Warning(_("Skipping acquire of configured file '%s' as repository '%s' provides only weak security information for it"),
  1099. Target->MetaKey.c_str(), TransactionManager->Target.Description.c_str());
  1100. continue;
  1101. }
  1102. // empty files are skipped as acquiring the very small compressed files is a waste of time
  1103. else if (hashes.FileSize() == 0)
  1104. continue;
  1105. }
  1106. }
  1107. // autoselect the compression method
  1108. std::vector<std::string> types = VectorizeString(Target->Option(IndexTarget::COMPRESSIONTYPES), ' ');
  1109. types.erase(std::remove_if(types.begin(), types.end(), [&](std::string const &t) {
  1110. if (t == "uncompressed")
  1111. return TransactionManager->MetaIndexParser->Exists(Target->MetaKey) == false;
  1112. std::string const MetaKey = Target->MetaKey + "." + t;
  1113. return TransactionManager->MetaIndexParser->Exists(MetaKey) == false;
  1114. }), types.end());
  1115. if (types.empty() == false)
  1116. {
  1117. std::ostringstream os;
  1118. // add the special compressiontype byhash first if supported
  1119. std::string const useByHashConf = Target->Option(IndexTarget::BY_HASH);
  1120. bool useByHash = false;
  1121. if(useByHashConf == "force")
  1122. useByHash = true;
  1123. else
  1124. useByHash = StringToBool(useByHashConf) == true && metaBaseSupportsByHash;
  1125. if (useByHash == true)
  1126. os << "by-hash ";
  1127. std::copy(types.begin(), types.end()-1, std::ostream_iterator<std::string>(os, " "));
  1128. os << *types.rbegin();
  1129. Target->Options["COMPRESSIONTYPES"] = os.str();
  1130. }
  1131. else
  1132. Target->Options["COMPRESSIONTYPES"].clear();
  1133. std::string filename = GetExistingFilename(GetFinalFileNameFromURI(Target->URI));
  1134. if (filename.empty() == false)
  1135. {
  1136. // if the Release file is a hit and we have an index it must be the current one
  1137. if (TransactionManager->IMSHit == true)
  1138. ;
  1139. else if (TransactionManager->LastMetaIndexParser != NULL)
  1140. {
  1141. // see if the file changed since the last Release file
  1142. // we use the uncompressed files as we might compress differently compared to the server,
  1143. // so the hashes might not match, even if they contain the same data.
  1144. HashStringList const newFile = GetExpectedHashesFromFor(TransactionManager->MetaIndexParser, Target->MetaKey);
  1145. HashStringList const oldFile = GetExpectedHashesFromFor(TransactionManager->LastMetaIndexParser, Target->MetaKey);
  1146. if (newFile != oldFile)
  1147. filename.clear();
  1148. }
  1149. else
  1150. filename.clear();
  1151. }
  1152. else
  1153. trypdiff = false; // no file to patch
  1154. if (filename.empty() == false)
  1155. {
  1156. new NoActionItem(Owner, *Target, filename);
  1157. std::string const idxfilename = GetFinalFileNameFromURI(GetDiffIndexURI(*Target));
  1158. if (FileExists(idxfilename))
  1159. new NoActionItem(Owner, *Target, idxfilename);
  1160. continue;
  1161. }
  1162. // check if we have patches available
  1163. trypdiff &= TransactionManager->MetaIndexParser->Exists(GetDiffIndexFileName(Target->MetaKey));
  1164. }
  1165. else
  1166. {
  1167. // if we have no file to patch, no point in trying
  1168. trypdiff &= (GetExistingFilename(GetFinalFileNameFromURI(Target->URI)).empty() == false);
  1169. }
  1170. // no point in patching from local sources
  1171. if (trypdiff)
  1172. {
  1173. std::string const proto = Target->URI.substr(0, strlen("file:/"));
  1174. if (proto == "file:/" || proto == "copy:/" || proto == "cdrom:")
  1175. trypdiff = false;
  1176. }
  1177. // Queue the Index file (Packages, Sources, Translation-$foo, …)
  1178. if (trypdiff)
  1179. new pkgAcqDiffIndex(Owner, TransactionManager, *Target);
  1180. else
  1181. new pkgAcqIndex(Owner, TransactionManager, *Target);
  1182. }
  1183. }
  1184. /*}}}*/
  1185. bool pkgAcqMetaBase::VerifyVendor(string const &Message) /*{{{*/
  1186. {
  1187. string::size_type pos;
  1188. // check for missing sigs (that where not fatal because otherwise we had
  1189. // bombed earlier)
  1190. string missingkeys;
  1191. string msg = _("There is no public key available for the "
  1192. "following key IDs:\n");
  1193. pos = Message.find("NO_PUBKEY ");
  1194. if (pos != std::string::npos)
  1195. {
  1196. string::size_type start = pos+strlen("NO_PUBKEY ");
  1197. string Fingerprint = Message.substr(start, Message.find("\n")-start);
  1198. missingkeys += (Fingerprint);
  1199. }
  1200. if(!missingkeys.empty())
  1201. _error->Warning("%s", (msg + missingkeys).c_str());
  1202. string Transformed = TransactionManager->MetaIndexParser->GetExpectedDist();
  1203. if (Transformed == "../project/experimental")
  1204. {
  1205. Transformed = "experimental";
  1206. }
  1207. pos = Transformed.rfind('/');
  1208. if (pos != string::npos)
  1209. {
  1210. Transformed = Transformed.substr(0, pos);
  1211. }
  1212. if (Transformed == ".")
  1213. {
  1214. Transformed = "";
  1215. }
  1216. if (TransactionManager->MetaIndexParser->GetValidUntil() > 0)
  1217. {
  1218. time_t const invalid_since = time(NULL) - TransactionManager->MetaIndexParser->GetValidUntil();
  1219. if (invalid_since > 0)
  1220. {
  1221. std::string errmsg;
  1222. strprintf(errmsg,
  1223. // TRANSLATOR: The first %s is the URL of the bad Release file, the second is
  1224. // the time since then the file is invalid - formatted in the same way as in
  1225. // the download progress display (e.g. 7d 3h 42min 1s)
  1226. _("Release file for %s is expired (invalid since %s). "
  1227. "Updates for this repository will not be applied."),
  1228. Target.URI.c_str(), TimeToStr(invalid_since).c_str());
  1229. if (ErrorText.empty())
  1230. ErrorText = errmsg;
  1231. return _error->Error("%s", errmsg.c_str());
  1232. }
  1233. }
  1234. /* Did we get a file older than what we have? This is a last minute IMS hit and doubles
  1235. as a prevention of downgrading us to older (still valid) files */
  1236. if (TransactionManager->IMSHit == false && TransactionManager->LastMetaIndexParser != NULL &&
  1237. TransactionManager->LastMetaIndexParser->GetDate() > TransactionManager->MetaIndexParser->GetDate())
  1238. {
  1239. TransactionManager->IMSHit = true;
  1240. RemoveFile("VerifyVendor", DestFile);
  1241. PartialFile = DestFile = GetFinalFilename();
  1242. // load the 'old' file in the 'new' one instead of flipping pointers as
  1243. // the new one isn't owned by us, while the old one is so cleanup would be confused.
  1244. TransactionManager->MetaIndexParser->swapLoad(TransactionManager->LastMetaIndexParser);
  1245. delete TransactionManager->LastMetaIndexParser;
  1246. TransactionManager->LastMetaIndexParser = NULL;
  1247. }
  1248. if (_config->FindB("Debug::pkgAcquire::Auth", false))
  1249. {
  1250. std::cerr << "Got Codename: " << TransactionManager->MetaIndexParser->GetCodename() << std::endl;
  1251. std::cerr << "Expecting Dist: " << TransactionManager->MetaIndexParser->GetExpectedDist() << std::endl;
  1252. std::cerr << "Transformed Dist: " << Transformed << std::endl;
  1253. }
  1254. if (TransactionManager->MetaIndexParser->CheckDist(Transformed) == false)
  1255. {
  1256. // This might become fatal one day
  1257. // Status = StatAuthError;
  1258. // ErrorText = "Conflicting distribution; expected "
  1259. // + MetaIndexParser->GetExpectedDist() + " but got "
  1260. // + MetaIndexParser->GetCodename();
  1261. // return false;
  1262. if (!Transformed.empty())
  1263. {
  1264. _error->Warning(_("Conflicting distribution: %s (expected %s but got %s)"),
  1265. Desc.Description.c_str(),
  1266. Transformed.c_str(),
  1267. TransactionManager->MetaIndexParser->GetCodename().c_str());
  1268. }
  1269. }
  1270. return true;
  1271. }
  1272. /*}}}*/
  1273. pkgAcqMetaBase::~pkgAcqMetaBase()
  1274. {
  1275. }
  1276. pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire * const Owner, /*{{{*/
  1277. IndexTarget const &ClearsignedTarget,
  1278. IndexTarget const &DetachedDataTarget, IndexTarget const &DetachedSigTarget,
  1279. std::vector<IndexTarget> const &IndexTargets,
  1280. metaIndex * const MetaIndexParser) :
  1281. pkgAcqMetaIndex(Owner, this, ClearsignedTarget, DetachedSigTarget, IndexTargets),
  1282. d(NULL), ClearsignedTarget(ClearsignedTarget),
  1283. DetachedDataTarget(DetachedDataTarget),
  1284. MetaIndexParser(MetaIndexParser), LastMetaIndexParser(NULL)
  1285. {
  1286. // index targets + (worst case:) Release/Release.gpg
  1287. ExpectedAdditionalItems = IndexTargets.size() + 2;
  1288. TransactionManager->Add(this);
  1289. }
  1290. /*}}}*/
  1291. pkgAcqMetaClearSig::~pkgAcqMetaClearSig() /*{{{*/
  1292. {
  1293. if (LastMetaIndexParser != NULL)
  1294. delete LastMetaIndexParser;
  1295. }
  1296. /*}}}*/
  1297. // pkgAcqMetaClearSig::Custom600Headers - Insert custom request headers /*{{{*/
  1298. string pkgAcqMetaClearSig::Custom600Headers() const
  1299. {
  1300. string Header = pkgAcqMetaBase::Custom600Headers();
  1301. Header += "\nFail-Ignore: true";
  1302. std::string const key = TransactionManager->MetaIndexParser->GetSignedBy();
  1303. if (key.empty() == false)
  1304. Header += "\nSigned-By: " + key;
  1305. return Header;
  1306. }
  1307. /*}}}*/
  1308. void pkgAcqMetaClearSig::Finished() /*{{{*/
  1309. {
  1310. if(_config->FindB("Debug::Acquire::Transaction", false) == true)
  1311. std::clog << "Finished: " << DestFile <<std::endl;
  1312. if(TransactionManager != NULL && TransactionManager->State == TransactionStarted &&
  1313. TransactionManager->TransactionHasError() == false)
  1314. TransactionManager->CommitTransaction();
  1315. }
  1316. /*}}}*/
  1317. bool pkgAcqMetaClearSig::VerifyDone(std::string const &Message, /*{{{*/
  1318. pkgAcquire::MethodConfig const * const Cnf)
  1319. {
  1320. Item::VerifyDone(Message, Cnf);
  1321. if (FileExists(DestFile) && !StartsWithGPGClearTextSignature(DestFile))
  1322. return RenameOnError(NotClearsigned);
  1323. return true;
  1324. }
  1325. /*}}}*/
  1326. // pkgAcqMetaClearSig::Done - We got a file /*{{{*/
  1327. void pkgAcqMetaClearSig::Done(std::string const &Message,
  1328. HashStringList const &Hashes,
  1329. pkgAcquire::MethodConfig const * const Cnf)
  1330. {
  1331. Item::Done(Message, Hashes, Cnf);
  1332. if(AuthPass == false)
  1333. {
  1334. if(CheckDownloadDone(this, Message, Hashes) == true)
  1335. QueueForSignatureVerify(this, DestFile, DestFile);
  1336. return;
  1337. }
  1338. else if(CheckAuthDone(Message) == true)
  1339. {
  1340. if (TransactionManager->IMSHit == false)
  1341. TransactionManager->TransactionStageCopy(this, DestFile, GetFinalFilename());
  1342. else if (RealFileExists(GetFinalFilename()) == false)
  1343. {
  1344. // We got an InRelease file IMSHit, but we haven't one, which means
  1345. // we had a valid Release/Release.gpg combo stepping in, which we have
  1346. // to 'acquire' now to ensure list cleanup isn't removing them
  1347. new NoActionItem(Owner, DetachedDataTarget);
  1348. new NoActionItem(Owner, DetachedSigTarget);
  1349. }
  1350. }
  1351. }
  1352. /*}}}*/
  1353. void pkgAcqMetaClearSig::Failed(string const &Message,pkgAcquire::MethodConfig const * const Cnf) /*{{{*/
  1354. {
  1355. Item::Failed(Message, Cnf);
  1356. // we failed, we will not get additional items from this method
  1357. ExpectedAdditionalItems = 0;
  1358. if (AuthPass == false)
  1359. {
  1360. if (Status == StatAuthError || Status == StatTransientNetworkError)
  1361. {
  1362. // if we expected a ClearTextSignature (InRelease) but got a network
  1363. // error or got a file, but it wasn't valid, we end up here (see VerifyDone).
  1364. // As these is usually called by web-portals we do not try Release/Release.gpg
  1365. // as this is gonna fail anyway and instead abort our try (LP#346386)
  1366. TransactionManager->AbortTransaction();
  1367. return;
  1368. }
  1369. // Queue the 'old' InRelease file for removal if we try Release.gpg
  1370. // as otherwise the file will stay around and gives a false-auth
  1371. // impression (CVE-2012-0214)
  1372. TransactionManager->TransactionStageRemoval(this, GetFinalFilename());
  1373. Status = StatDone;
  1374. new pkgAcqMetaIndex(Owner, TransactionManager, DetachedDataTarget, DetachedSigTarget, IndexTargets);
  1375. }
  1376. else
  1377. {
  1378. if(CheckStopAuthentication(this, Message))
  1379. return;
  1380. // No Release file was present, or verification failed, so fall
  1381. // back to queueing Packages files without verification
  1382. // only allow going further if the user explicitly wants it
  1383. if(AllowInsecureRepositories(_("The repository '%s' is not signed."), ClearsignedTarget.Description, TransactionManager->MetaIndexParser, TransactionManager, this) == true)
  1384. {
  1385. Status = StatDone;
  1386. /* InRelease files become Release files, otherwise
  1387. * they would be considered as trusted later on */
  1388. string const FinalRelease = GetFinalFileNameFromURI(DetachedDataTarget.URI);
  1389. string const PartialRelease = GetPartialFileNameFromURI(DetachedDataTarget.URI);
  1390. string const FinalReleasegpg = GetFinalFileNameFromURI(DetachedSigTarget.URI);
  1391. string const FinalInRelease = GetFinalFilename();
  1392. Rename(DestFile, PartialRelease);
  1393. TransactionManager->TransactionStageCopy(this, PartialRelease, FinalRelease);
  1394. LoadLastMetaIndexParser(TransactionManager, FinalRelease, FinalInRelease);
  1395. // we parse the indexes here because at this point the user wanted
  1396. // a repository that may potentially harm him
  1397. if (TransactionManager->MetaIndexParser->Load(PartialRelease, &ErrorText) == false || VerifyVendor(Message) == false)
  1398. /* expired Release files are still a problem you need extra force for */;
  1399. else
  1400. QueueIndexes(true);
  1401. }
  1402. }
  1403. }
  1404. /*}}}*/
  1405. pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire * const Owner, /*{{{*/
  1406. pkgAcqMetaClearSig * const TransactionManager,
  1407. IndexTarget const &DataTarget,
  1408. IndexTarget const &DetachedSigTarget,
  1409. vector<IndexTarget> const &IndexTargets) :
  1410. pkgAcqMetaBase(Owner, TransactionManager, IndexTargets, DataTarget), d(NULL),
  1411. DetachedSigTarget(DetachedSigTarget)
  1412. {
  1413. if(_config->FindB("Debug::Acquire::Transaction", false) == true)
  1414. std::clog << "New pkgAcqMetaIndex with TransactionManager "
  1415. << this->TransactionManager << std::endl;
  1416. DestFile = GetPartialFileNameFromURI(DataTarget.URI);
  1417. // Create the item
  1418. Desc.Description = DataTarget.Description;
  1419. Desc.Owner = this;
  1420. Desc.ShortDesc = DataTarget.ShortDesc;
  1421. Desc.URI = DataTarget.URI;
  1422. // we expect more item
  1423. ExpectedAdditionalItems = IndexTargets.size();
  1424. QueueURI(Desc);
  1425. }
  1426. /*}}}*/
  1427. void pkgAcqMetaIndex::Done(string const &Message, /*{{{*/
  1428. HashStringList const &Hashes,
  1429. pkgAcquire::MethodConfig const * const Cfg)
  1430. {
  1431. Item::Done(Message,Hashes,Cfg);
  1432. if(CheckDownloadDone(this, Message, Hashes))
  1433. {
  1434. // we have a Release file, now download the Signature, all further
  1435. // verify/queue for additional downloads will be done in the
  1436. // pkgAcqMetaSig::Done() code
  1437. new pkgAcqMetaSig(Owner, TransactionManager, DetachedSigTarget, this);
  1438. }
  1439. }
  1440. /*}}}*/
  1441. // pkgAcqMetaIndex::Failed - no Release file present /*{{{*/
  1442. void pkgAcqMetaIndex::Failed(string const &Message,
  1443. pkgAcquire::MethodConfig const * const Cnf)
  1444. {
  1445. pkgAcquire::Item::Failed(Message, Cnf);
  1446. Status = StatDone;
  1447. // No Release file was present so fall
  1448. // back to queueing Packages files without verification
  1449. // only allow going further if the user explicitly wants it
  1450. if(AllowInsecureRepositories(_("The repository '%s' does not have a Release file."), Target.Description, TransactionManager->MetaIndexParser, TransactionManager, this) == true)
  1451. {
  1452. // ensure old Release files are removed
  1453. TransactionManager->TransactionStageRemoval(this, GetFinalFilename());
  1454. // queue without any kind of hashsum support
  1455. QueueIndexes(false);
  1456. }
  1457. }
  1458. /*}}}*/
  1459. std::string pkgAcqMetaIndex::DescURI() const /*{{{*/
  1460. {
  1461. return Target.URI;
  1462. }
  1463. /*}}}*/
  1464. pkgAcqMetaIndex::~pkgAcqMetaIndex() {}
  1465. // AcqMetaSig::AcqMetaSig - Constructor /*{{{*/
  1466. pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire * const Owner,
  1467. pkgAcqMetaClearSig * const TransactionManager,
  1468. IndexTarget const &Target,
  1469. pkgAcqMetaIndex * const MetaIndex) :
  1470. pkgAcqTransactionItem(Owner, TransactionManager, Target), d(NULL), MetaIndex(MetaIndex)
  1471. {
  1472. DestFile = GetPartialFileNameFromURI(Target.URI);
  1473. // remove any partial downloaded sig-file in partial/.
  1474. // it may confuse proxies and is too small to warrant a
  1475. // partial download anyway
  1476. RemoveFile("pkgAcqMetaSig", DestFile);
  1477. // set the TransactionManager
  1478. if(_config->FindB("Debug::Acquire::Transaction", false) == true)
  1479. std::clog << "New pkgAcqMetaSig with TransactionManager "
  1480. << TransactionManager << std::endl;
  1481. // Create the item
  1482. Desc.Description = Target.Description;
  1483. Desc.Owner = this;
  1484. Desc.ShortDesc = Target.ShortDesc;
  1485. Desc.URI = Target.URI;
  1486. // If we got a hit for Release, we will get one for Release.gpg too (or obscure errors),
  1487. // so we skip the download step and go instantly to verification
  1488. if (TransactionManager->IMSHit == true && RealFileExists(GetFinalFilename()))
  1489. {
  1490. Complete = true;
  1491. Status = StatDone;
  1492. PartialFile = DestFile = GetFinalFilename();
  1493. MetaIndexFileSignature = DestFile;
  1494. MetaIndex->QueueForSignatureVerify(this, MetaIndex->DestFile, DestFile);
  1495. }
  1496. else
  1497. QueueURI(Desc);
  1498. }
  1499. /*}}}*/
  1500. pkgAcqMetaSig::~pkgAcqMetaSig() /*{{{*/
  1501. {
  1502. }
  1503. /*}}}*/
  1504. // pkgAcqMetaSig::Custom600Headers - Insert custom request headers /*{{{*/
  1505. std::string pkgAcqMetaSig::Custom600Headers() const
  1506. {
  1507. std::string Header = pkgAcqTransactionItem::Custom600Headers();
  1508. std::string const key = TransactionManager->MetaIndexParser->GetSignedBy();
  1509. if (key.empty() == false)
  1510. Header += "\nSigned-By: " + key;
  1511. return Header;
  1512. }
  1513. /*}}}*/
  1514. // AcqMetaSig::Done - The signature was downloaded/verified /*{{{*/
  1515. void pkgAcqMetaSig::Done(string const &Message, HashStringList const &Hashes,
  1516. pkgAcquire::MethodConfig const * const Cfg)
  1517. {
  1518. if (MetaIndexFileSignature.empty() == false)
  1519. {
  1520. DestFile = MetaIndexFileSignature;
  1521. MetaIndexFileSignature.clear();
  1522. }
  1523. Item::Done(Message, Hashes, Cfg);
  1524. if(MetaIndex->AuthPass == false)
  1525. {
  1526. if(MetaIndex->CheckDownloadDone(this, Message, Hashes) == true)
  1527. {
  1528. // destfile will be modified to point to MetaIndexFile for the
  1529. // gpgv method, so we need to save it here
  1530. MetaIndexFileSignature = DestFile;
  1531. MetaIndex->QueueForSignatureVerify(this, MetaIndex->DestFile, DestFile);
  1532. }
  1533. return;
  1534. }
  1535. else if(MetaIndex->CheckAuthDone(Message) == true)
  1536. {
  1537. if (TransactionManager->IMSHit == false)
  1538. {
  1539. TransactionManager->TransactionStageCopy(this, DestFile, GetFinalFilename());
  1540. TransactionManager->TransactionStageCopy(MetaIndex, MetaIndex->DestFile, MetaIndex->GetFinalFilename());
  1541. }
  1542. }
  1543. }
  1544. /*}}}*/
  1545. void pkgAcqMetaSig::Failed(string const &Message,pkgAcquire::MethodConfig const * const Cnf)/*{{{*/
  1546. {
  1547. Item::Failed(Message,Cnf);
  1548. // check if we need to fail at this point
  1549. if (MetaIndex->AuthPass == true && MetaIndex->CheckStopAuthentication(this, Message))
  1550. return;
  1551. string const FinalRelease = MetaIndex->GetFinalFilename();
  1552. string const FinalReleasegpg = GetFinalFilename();
  1553. string const FinalInRelease = TransactionManager->GetFinalFilename();
  1554. if (RealFileExists(FinalReleasegpg) || RealFileExists(FinalInRelease))
  1555. {
  1556. std::string downgrade_msg;
  1557. strprintf(downgrade_msg, _("The repository '%s' is no longer signed."),
  1558. MetaIndex->Target.Description.c_str());
  1559. if(_config->FindB("Acquire::AllowDowngradeToInsecureRepositories"))
  1560. {
  1561. // meh, the users wants to take risks (we still mark the packages
  1562. // from this repository as unauthenticated)
  1563. _error->Warning("%s", downgrade_msg.c_str());
  1564. _error->Warning(_("This is normally not allowed, but the option "
  1565. "Acquire::AllowDowngradeToInsecureRepositories was "
  1566. "given to override it."));
  1567. Status = StatDone;
  1568. } else {
  1569. MessageInsecureRepository(true, downgrade_msg);
  1570. if (TransactionManager->IMSHit == false)
  1571. Rename(MetaIndex->DestFile, MetaIndex->DestFile + ".FAILED");
  1572. Item::Failed("Message: " + downgrade_msg, Cnf);
  1573. TransactionManager->AbortTransaction();
  1574. return;
  1575. }
  1576. }
  1577. // ensures that a Release.gpg file in the lists/ is removed by the transaction
  1578. TransactionManager->TransactionStageRemoval(this, DestFile);
  1579. // only allow going further if the user explicitly wants it
  1580. if (AllowInsecureRepositories(_("The repository '%s' is not signed."), MetaIndex->Target.Description, TransactionManager->MetaIndexParser, TransactionManager, this) == true)
  1581. {
  1582. LoadLastMetaIndexParser(TransactionManager, FinalRelease, FinalInRelease);
  1583. // we parse the indexes here because at this point the user wanted
  1584. // a repository that may potentially harm him
  1585. bool const GoodLoad = TransactionManager->MetaIndexParser->Load(MetaIndex->DestFile, &ErrorText);
  1586. if (MetaIndex->VerifyVendor(Message) == false)
  1587. /* expired Release files are still a problem you need extra force for */;
  1588. else
  1589. MetaIndex->QueueIndexes(GoodLoad);
  1590. TransactionManager->TransactionStageCopy(MetaIndex, MetaIndex->DestFile, MetaIndex->GetFinalFilename());
  1591. }
  1592. // FIXME: this is used often (e.g. in pkgAcqIndexTrans) so refactor
  1593. if (Cnf->LocalOnly == true ||
  1594. StringToBool(LookupTag(Message,"Transient-Failure"),false) == false)
  1595. {
  1596. // Ignore this
  1597. Status = StatDone;
  1598. }
  1599. }
  1600. /*}}}*/
  1601. // AcqBaseIndex - Constructor /*{{{*/
  1602. pkgAcqBaseIndex::pkgAcqBaseIndex(pkgAcquire * const Owner,
  1603. pkgAcqMetaClearSig * const TransactionManager,
  1604. IndexTarget const &Target)
  1605. : pkgAcqTransactionItem(Owner, TransactionManager, Target), d(NULL)
  1606. {
  1607. }
  1608. /*}}}*/
  1609. pkgAcqBaseIndex::~pkgAcqBaseIndex() {}
  1610. // AcqDiffIndex::AcqDiffIndex - Constructor /*{{{*/
  1611. // ---------------------------------------------------------------------
  1612. /* Get the DiffIndex file first and see if there are patches available
  1613. * If so, create a pkgAcqIndexDiffs fetcher that will get and apply the
  1614. * patches. If anything goes wrong in that process, it will fall back to
  1615. * the original packages file
  1616. */
  1617. pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire * const Owner,
  1618. pkgAcqMetaClearSig * const TransactionManager,
  1619. IndexTarget const &Target)
  1620. : pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL), diffs(NULL)
  1621. {
  1622. Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
  1623. Desc.Owner = this;
  1624. Desc.Description = GetDiffIndexFileName(Target.Description);
  1625. Desc.ShortDesc = Target.ShortDesc;
  1626. Desc.URI = GetDiffIndexURI(Target);
  1627. DestFile = GetPartialFileNameFromURI(Desc.URI);
  1628. if(Debug)
  1629. std::clog << "pkgAcqDiffIndex: " << Desc.URI << std::endl;
  1630. QueueURI(Desc);
  1631. }
  1632. /*}}}*/
  1633. // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
  1634. // ---------------------------------------------------------------------
  1635. /* The only header we use is the last-modified header. */
  1636. string pkgAcqDiffIndex::Custom600Headers() const
  1637. {
  1638. if (TransactionManager->LastMetaIndexParser != NULL)
  1639. return "\nIndex-File: true";
  1640. string const Final = GetFinalFilename();
  1641. if(Debug)
  1642. std::clog << "Custom600Header-IMS: " << Final << std::endl;
  1643. struct stat Buf;
  1644. if (stat(Final.c_str(),&Buf) != 0)
  1645. return "\nIndex-File: true";
  1646. return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  1647. }
  1648. /*}}}*/
  1649. void pkgAcqDiffIndex::QueueOnIMSHit() const /*{{{*/
  1650. {
  1651. // list cleanup needs to know that this file as well as the already
  1652. // present index is ours, so we create an empty diff to save it for us
  1653. new pkgAcqIndexDiffs(Owner, TransactionManager, Target);
  1654. }
  1655. /*}}}*/
  1656. bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
  1657. {
  1658. // failing here is fine: our caller will take care of trying to
  1659. // get the complete file if patching fails
  1660. if(Debug)
  1661. std::clog << "pkgAcqDiffIndex::ParseIndexDiff() " << IndexDiffFile
  1662. << std::endl;
  1663. FileFd Fd(IndexDiffFile,FileFd::ReadOnly);
  1664. pkgTagFile TF(&Fd);
  1665. if (Fd.IsOpen() == false || Fd.Failed())
  1666. return false;
  1667. pkgTagSection Tags;
  1668. if(unlikely(TF.Step(Tags) == false))
  1669. return false;
  1670. HashStringList ServerHashes;
  1671. unsigned long long ServerSize = 0;
  1672. for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
  1673. {
  1674. std::string tagname = *type;
  1675. tagname.append("-Current");
  1676. std::string const tmp = Tags.FindS(tagname.c_str());
  1677. if (tmp.empty() == true)
  1678. continue;
  1679. string hash;
  1680. unsigned long long size;
  1681. std::stringstream ss(tmp);
  1682. ss >> hash >> size;
  1683. if (unlikely(hash.empty() == true))
  1684. continue;
  1685. if (unlikely(ServerSize != 0 && ServerSize != size))
  1686. continue;
  1687. ServerHashes.push_back(HashString(*type, hash));
  1688. ServerSize = size;
  1689. }
  1690. if (ServerHashes.usable() == false)
  1691. {
  1692. if (Debug == true)
  1693. std::clog << "pkgAcqDiffIndex: " << IndexDiffFile << ": Did not find a good hashsum in the index" << std::endl;
  1694. return false;
  1695. }
  1696. std::string const CurrentPackagesFile = GetFinalFileNameFromURI(Target.URI);
  1697. HashStringList const TargetFileHashes = GetExpectedHashesFor(Target.MetaKey);
  1698. if (TargetFileHashes.usable() == false || ServerHashes != TargetFileHashes)
  1699. {
  1700. if (Debug == true)
  1701. {
  1702. std::clog << "pkgAcqDiffIndex: " << IndexDiffFile << ": Index has different hashes than parser, probably older, so fail pdiffing" << std::endl;
  1703. printHashSumComparison(CurrentPackagesFile, ServerHashes, TargetFileHashes);
  1704. }
  1705. return false;
  1706. }
  1707. HashStringList LocalHashes;
  1708. // try avoiding calculating the hash here as this is costly
  1709. if (TransactionManager->LastMetaIndexParser != NULL)
  1710. LocalHashes = GetExpectedHashesFromFor(TransactionManager->LastMetaIndexParser, Target.MetaKey);
  1711. if (LocalHashes.usable() == false)
  1712. {
  1713. FileFd fd(CurrentPackagesFile, FileFd::ReadOnly, FileFd::Auto);
  1714. Hashes LocalHashesCalc(ServerHashes);
  1715. LocalHashesCalc.AddFD(fd);
  1716. LocalHashes = LocalHashesCalc.GetHashStringList();
  1717. }
  1718. if (ServerHashes == LocalHashes)
  1719. {
  1720. // we have the same sha1 as the server so we are done here
  1721. if(Debug)
  1722. std::clog << "pkgAcqDiffIndex: Package file " << CurrentPackagesFile << " is up-to-date" << std::endl;
  1723. QueueOnIMSHit();
  1724. return true;
  1725. }
  1726. if(Debug)
  1727. std::clog << "Server-Current: " << ServerHashes.find(NULL)->toStr() << " and we start at "
  1728. << CurrentPackagesFile << " " << LocalHashes.FileSize() << " " << LocalHashes.find(NULL)->toStr() << std::endl;
  1729. // historically, older hashes have more info than newer ones, so start
  1730. // collecting with older ones first to avoid implementing complicated
  1731. // information merging techniques… a failure is after all always
  1732. // recoverable with a complete file and hashes aren't changed that often.
  1733. std::vector<char const *> types;
  1734. for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
  1735. types.push_back(*type);
  1736. // parse all of (provided) history
  1737. vector<DiffInfo> available_patches;
  1738. bool firstAcceptedHashes = true;
  1739. for (auto type = types.crbegin(); type != types.crend(); ++type)
  1740. {
  1741. if (LocalHashes.find(*type) == NULL)
  1742. continue;
  1743. std::string tagname = *type;
  1744. tagname.append("-History");
  1745. std::string const tmp = Tags.FindS(tagname.c_str());
  1746. if (tmp.empty() == true)
  1747. continue;
  1748. string hash, filename;
  1749. unsigned long long size;
  1750. std::stringstream ss(tmp);
  1751. while (ss >> hash >> size >> filename)
  1752. {
  1753. if (unlikely(hash.empty() == true || filename.empty() == true))
  1754. continue;
  1755. // see if we have a record for this file already
  1756. std::vector<DiffInfo>::iterator cur = available_patches.begin();
  1757. for (; cur != available_patches.end(); ++cur)
  1758. {
  1759. if (cur->file != filename)
  1760. continue;
  1761. cur->result_hashes.push_back(HashString(*type, hash));
  1762. break;
  1763. }
  1764. if (cur != available_patches.end())
  1765. continue;
  1766. if (firstAcceptedHashes == true)
  1767. {
  1768. DiffInfo next;
  1769. next.file = filename;
  1770. next.result_hashes.push_back(HashString(*type, hash));
  1771. next.result_hashes.FileSize(size);
  1772. available_patches.push_back(next);
  1773. }
  1774. else
  1775. {
  1776. if (Debug == true)
  1777. std::clog << "pkgAcqDiffIndex: " << IndexDiffFile << ": File " << filename
  1778. << " wasn't in the list for the first parsed hash! (history)" << std::endl;
  1779. break;
  1780. }
  1781. }
  1782. firstAcceptedHashes = false;
  1783. }
  1784. if (unlikely(available_patches.empty() == true))
  1785. {
  1786. if (Debug)
  1787. std::clog << "pkgAcqDiffIndex: " << IndexDiffFile << ": "
  1788. << "Couldn't find any patches for the patch series." << std::endl;
  1789. return false;
  1790. }
  1791. for (auto type = types.crbegin(); type != types.crend(); ++type)
  1792. {
  1793. if (LocalHashes.find(*type) == NULL)
  1794. continue;
  1795. std::string tagname = *type;
  1796. tagname.append("-Patches");
  1797. std::string const tmp = Tags.FindS(tagname.c_str());
  1798. if (tmp.empty() == true)
  1799. continue;
  1800. string hash, filename;
  1801. unsigned long long size;
  1802. std::stringstream ss(tmp);
  1803. while (ss >> hash >> size >> filename)
  1804. {
  1805. if (unlikely(hash.empty() == true || filename.empty() == true))
  1806. continue;
  1807. // see if we have a record for this file already
  1808. std::vector<DiffInfo>::iterator cur = available_patches.begin();
  1809. for (; cur != available_patches.end(); ++cur)
  1810. {
  1811. if (cur->file != filename)
  1812. continue;
  1813. if (cur->patch_hashes.empty())
  1814. cur->patch_hashes.FileSize(size);
  1815. cur->patch_hashes.push_back(HashString(*type, hash));
  1816. break;
  1817. }
  1818. if (cur != available_patches.end())
  1819. continue;
  1820. if (Debug == true)
  1821. std::clog << "pkgAcqDiffIndex: " << IndexDiffFile << ": File " << filename
  1822. << " wasn't in the list for the first parsed hash! (patches)" << std::endl;
  1823. break;
  1824. }
  1825. }
  1826. for (auto type = types.crbegin(); type != types.crend(); ++type)
  1827. {
  1828. std::string tagname = *type;
  1829. tagname.append("-Download");
  1830. std::string const tmp = Tags.FindS(tagname.c_str());
  1831. if (tmp.empty() == true)
  1832. continue;
  1833. string hash, filename;
  1834. unsigned long long size;
  1835. std::stringstream ss(tmp);
  1836. // FIXME: all of pdiff supports only .gz compressed patches
  1837. while (ss >> hash >> size >> filename)
  1838. {
  1839. if (unlikely(hash.empty() == true || filename.empty() == true))
  1840. continue;
  1841. if (unlikely(APT::String::Endswith(filename, ".gz") == false))
  1842. continue;
  1843. filename.erase(filename.length() - 3);
  1844. // see if we have a record for this file already
  1845. std::vector<DiffInfo>::iterator cur = available_patches.begin();
  1846. for (; cur != available_patches.end(); ++cur)
  1847. {
  1848. if (cur->file != filename)
  1849. continue;
  1850. if (cur->download_hashes.empty())
  1851. cur->download_hashes.FileSize(size);
  1852. cur->download_hashes.push_back(HashString(*type, hash));
  1853. break;
  1854. }
  1855. if (cur != available_patches.end())
  1856. continue;
  1857. if (Debug == true)
  1858. std::clog << "pkgAcqDiffIndex: " << IndexDiffFile << ": File " << filename
  1859. << " wasn't in the list for the first parsed hash! (download)" << std::endl;
  1860. break;
  1861. }
  1862. }
  1863. bool foundStart = false;
  1864. for (std::vector<DiffInfo>::iterator cur = available_patches.begin();
  1865. cur != available_patches.end(); ++cur)
  1866. {
  1867. if (LocalHashes != cur->result_hashes)
  1868. continue;
  1869. available_patches.erase(available_patches.begin(), cur);
  1870. foundStart = true;
  1871. break;
  1872. }
  1873. if (foundStart == false || unlikely(available_patches.empty() == true))
  1874. {
  1875. if (Debug)
  1876. std::clog << "pkgAcqDiffIndex: " << IndexDiffFile << ": "
  1877. << "Couldn't find the start of the patch series." << std::endl;
  1878. return false;
  1879. }
  1880. for (auto const &patch: available_patches)
  1881. if (patch.result_hashes.usable() == false ||
  1882. patch.patch_hashes.usable() == false ||
  1883. patch.download_hashes.usable() == false)
  1884. {
  1885. if (Debug)
  1886. std::clog << "pkgAcqDiffIndex: " << IndexDiffFile << ": provides no usable hashes for " << patch.file
  1887. << " so fallback to complete download" << std::endl;
  1888. return false;
  1889. }
  1890. // patching with too many files is rather slow compared to a fast download
  1891. unsigned long const fileLimit = _config->FindI("Acquire::PDiffs::FileLimit", 0);
  1892. if (fileLimit != 0 && fileLimit < available_patches.size())
  1893. {
  1894. if (Debug)
  1895. std::clog << "Need " << available_patches.size() << " diffs (Limit is " << fileLimit
  1896. << ") so fallback to complete download" << std::endl;
  1897. return false;
  1898. }
  1899. // calculate the size of all patches we have to get
  1900. unsigned short const sizeLimitPercent = _config->FindI("Acquire::PDiffs::SizeLimit", 100);
  1901. if (sizeLimitPercent > 0 && TransactionManager->MetaIndexParser != nullptr)
  1902. {
  1903. unsigned long long downloadSize = std::accumulate(available_patches.begin(),
  1904. available_patches.end(), 0llu, [](unsigned long long const T, DiffInfo const &I) {
  1905. return T + I.download_hashes.FileSize();
  1906. });
  1907. if (downloadSize != 0)
  1908. {
  1909. unsigned long long downloadSizeIdx = 0;
  1910. auto const types = VectorizeString(Target.Option(IndexTarget::COMPRESSIONTYPES), ' ');
  1911. for (auto const &t : types)
  1912. {
  1913. std::string MetaKey = Target.MetaKey;
  1914. if (t != "uncompressed")
  1915. MetaKey += '.' + t;
  1916. HashStringList const hsl = GetExpectedHashesFor(MetaKey);
  1917. if (unlikely(hsl.usable() == false))
  1918. continue;
  1919. downloadSizeIdx = hsl.FileSize();
  1920. break;
  1921. }
  1922. unsigned long long const sizeLimit = downloadSizeIdx * sizeLimitPercent;
  1923. if ((sizeLimit/100) < downloadSize)
  1924. {
  1925. if (Debug)
  1926. std::clog << "Need " << downloadSize << " compressed bytes (Limit is " << (sizeLimit/100) << ", "
  1927. << "original is " << downloadSizeIdx << ") so fallback to complete download" << std::endl;
  1928. return false;
  1929. }
  1930. }
  1931. }
  1932. // we have something, queue the diffs
  1933. string::size_type const last_space = Description.rfind(" ");
  1934. if(last_space != string::npos)
  1935. Description.erase(last_space, Description.size()-last_space);
  1936. /* decide if we should download patches one by one or in one go:
  1937. The first is good if the server merges patches, but many don't so client
  1938. based merging can be attempt in which case the second is better.
  1939. "bad things" will happen if patches are merged on the server,
  1940. but client side merging is attempt as well */
  1941. bool pdiff_merge = _config->FindB("Acquire::PDiffs::Merge", true);
  1942. if (pdiff_merge == true)
  1943. {
  1944. // reprepro adds this flag if it has merged patches on the server
  1945. std::string const precedence = Tags.FindS("X-Patch-Precedence");
  1946. pdiff_merge = (precedence != "merged");
  1947. }
  1948. // clean the plate
  1949. {
  1950. std::string const Final = GetExistingFilename(CurrentPackagesFile);
  1951. if (unlikely(Final.empty())) // because we wouldn't be called in such a case
  1952. return false;
  1953. std::string const PartialFile = GetPartialFileNameFromURI(Target.URI);
  1954. if (FileExists(PartialFile) && RemoveFile("Bootstrap-linking", PartialFile) == false)
  1955. {
  1956. if (Debug)
  1957. std::clog << "Bootstrap-linking for patching " << CurrentPackagesFile
  1958. << " by removing stale " << PartialFile << " failed!" << std::endl;
  1959. return false;
  1960. }
  1961. for (auto const &ext : APT::Configuration::getCompressorExtensions())
  1962. {
  1963. std::string const Partial = PartialFile + ext;
  1964. if (FileExists(Partial) && RemoveFile("Bootstrap-linking", Partial) == false)
  1965. {
  1966. if (Debug)
  1967. std::clog << "Bootstrap-linking for patching " << CurrentPackagesFile
  1968. << " by removing stale " << Partial << " failed!" << std::endl;
  1969. return false;
  1970. }
  1971. }
  1972. std::string const Ext = Final.substr(CurrentPackagesFile.length());
  1973. std::string const Partial = PartialFile + Ext;
  1974. if (symlink(Final.c_str(), Partial.c_str()) != 0)
  1975. {
  1976. if (Debug)
  1977. std::clog << "Bootstrap-linking for patching " << CurrentPackagesFile
  1978. << " by linking " << Final << " to " << Partial << " failed!" << std::endl;
  1979. return false;
  1980. }
  1981. }
  1982. if (pdiff_merge == false)
  1983. new pkgAcqIndexDiffs(Owner, TransactionManager, Target, available_patches);
  1984. else
  1985. {
  1986. diffs = new std::vector<pkgAcqIndexMergeDiffs*>(available_patches.size());
  1987. for(size_t i = 0; i < available_patches.size(); ++i)
  1988. (*diffs)[i] = new pkgAcqIndexMergeDiffs(Owner, TransactionManager,
  1989. Target,
  1990. available_patches[i],
  1991. diffs);
  1992. }
  1993. Complete = false;
  1994. Status = StatDone;
  1995. Dequeue();
  1996. return true;
  1997. }
  1998. /*}}}*/
  1999. void pkgAcqDiffIndex::Failed(string const &Message,pkgAcquire::MethodConfig const * const Cnf)/*{{{*/
  2000. {
  2001. Item::Failed(Message,Cnf);
  2002. Status = StatDone;
  2003. if(Debug)
  2004. std::clog << "pkgAcqDiffIndex failed: " << Desc.URI << " with " << Message << std::endl
  2005. << "Falling back to normal index file acquire" << std::endl;
  2006. new pkgAcqIndex(Owner, TransactionManager, Target);
  2007. }
  2008. /*}}}*/
  2009. void pkgAcqDiffIndex::Done(string const &Message,HashStringList const &Hashes, /*{{{*/
  2010. pkgAcquire::MethodConfig const * const Cnf)
  2011. {
  2012. if(Debug)
  2013. std::clog << "pkgAcqDiffIndex::Done(): " << Desc.URI << std::endl;
  2014. Item::Done(Message, Hashes, Cnf);
  2015. string const FinalFile = GetFinalFilename();
  2016. if(StringToBool(LookupTag(Message,"IMS-Hit"),false))
  2017. DestFile = FinalFile;
  2018. if(ParseDiffIndex(DestFile) == false)
  2019. {
  2020. Failed("Message: Couldn't parse pdiff index", Cnf);
  2021. // queue for final move - this should happen even if we fail
  2022. // while parsing (e.g. on sizelimit) and download the complete file.
  2023. TransactionManager->TransactionStageCopy(this, DestFile, FinalFile);
  2024. return;
  2025. }
  2026. TransactionManager->TransactionStageCopy(this, DestFile, FinalFile);
  2027. Complete = true;
  2028. Status = StatDone;
  2029. Dequeue();
  2030. return;
  2031. }
  2032. /*}}}*/
  2033. pkgAcqDiffIndex::~pkgAcqDiffIndex()
  2034. {
  2035. if (diffs != NULL)
  2036. delete diffs;
  2037. }
  2038. // AcqIndexDiffs::AcqIndexDiffs - Constructor /*{{{*/
  2039. // ---------------------------------------------------------------------
  2040. /* The package diff is added to the queue. one object is constructed
  2041. * for each diff and the index
  2042. */
  2043. pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire * const Owner,
  2044. pkgAcqMetaClearSig * const TransactionManager,
  2045. IndexTarget const &Target,
  2046. vector<DiffInfo> const &diffs)
  2047. : pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL),
  2048. available_patches(diffs)
  2049. {
  2050. DestFile = GetKeepCompressedFileName(GetPartialFileNameFromURI(Target.URI), Target);
  2051. Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
  2052. Desc.Owner = this;
  2053. Description = Target.Description;
  2054. Desc.ShortDesc = Target.ShortDesc;
  2055. if(available_patches.empty() == true)
  2056. {
  2057. // we are done (yeah!), check hashes against the final file
  2058. DestFile = GetKeepCompressedFileName(GetFinalFileNameFromURI(Target.URI), Target);
  2059. Finish(true);
  2060. }
  2061. else
  2062. {
  2063. State = StateFetchDiff;
  2064. QueueNextDiff();
  2065. }
  2066. }
  2067. /*}}}*/
  2068. void pkgAcqIndexDiffs::Failed(string const &Message,pkgAcquire::MethodConfig const * const Cnf)/*{{{*/
  2069. {
  2070. Item::Failed(Message,Cnf);
  2071. Status = StatDone;
  2072. DestFile = GetKeepCompressedFileName(GetPartialFileNameFromURI(Target.URI), Target);
  2073. if(Debug)
  2074. std::clog << "pkgAcqIndexDiffs failed: " << Desc.URI << " with " << Message << std::endl
  2075. << "Falling back to normal index file acquire " << std::endl;
  2076. RenameOnError(PDiffError);
  2077. std::string const patchname = GetDiffsPatchFileName(DestFile);
  2078. if (RealFileExists(patchname))
  2079. Rename(patchname, patchname + ".FAILED");
  2080. std::string const UnpatchedFile = GetExistingFilename(GetPartialFileNameFromURI(Target.URI));
  2081. if (UnpatchedFile.empty() == false && FileExists(UnpatchedFile))
  2082. Rename(UnpatchedFile, UnpatchedFile + ".FAILED");
  2083. new pkgAcqIndex(Owner, TransactionManager, Target);
  2084. Finish();
  2085. }
  2086. /*}}}*/
  2087. // Finish - helper that cleans the item out of the fetcher queue /*{{{*/
  2088. void pkgAcqIndexDiffs::Finish(bool allDone)
  2089. {
  2090. if(Debug)
  2091. std::clog << "pkgAcqIndexDiffs::Finish(): "
  2092. << allDone << " "
  2093. << Desc.URI << std::endl;
  2094. // we restore the original name, this is required, otherwise
  2095. // the file will be cleaned
  2096. if(allDone)
  2097. {
  2098. std::string const Final = GetKeepCompressedFileName(GetFinalFilename(), Target);
  2099. TransactionManager->TransactionStageCopy(this, DestFile, Final);
  2100. // this is for the "real" finish
  2101. Complete = true;
  2102. Status = StatDone;
  2103. Dequeue();
  2104. if(Debug)
  2105. std::clog << "\n\nallDone: " << DestFile << "\n" << std::endl;
  2106. return;
  2107. }
  2108. else
  2109. DestFile.clear();
  2110. if(Debug)
  2111. std::clog << "Finishing: " << Desc.URI << std::endl;
  2112. Complete = false;
  2113. Status = StatDone;
  2114. Dequeue();
  2115. return;
  2116. }
  2117. /*}}}*/
  2118. bool pkgAcqIndexDiffs::QueueNextDiff() /*{{{*/
  2119. {
  2120. // calc sha1 of the just patched file
  2121. std::string const PartialFile = GetExistingFilename(GetPartialFileNameFromURI(Target.URI));
  2122. if(unlikely(PartialFile.empty()))
  2123. {
  2124. Failed("Message: The file " + GetPartialFileNameFromURI(Target.URI) + " isn't available", NULL);
  2125. return false;
  2126. }
  2127. FileFd fd(PartialFile, FileFd::ReadOnly, FileFd::Extension);
  2128. Hashes LocalHashesCalc;
  2129. LocalHashesCalc.AddFD(fd);
  2130. HashStringList const LocalHashes = LocalHashesCalc.GetHashStringList();
  2131. if(Debug)
  2132. std::clog << "QueueNextDiff: " << PartialFile << " (" << LocalHashes.find(NULL)->toStr() << ")" << std::endl;
  2133. HashStringList const TargetFileHashes = GetExpectedHashesFor(Target.MetaKey);
  2134. if (unlikely(LocalHashes.usable() == false || TargetFileHashes.usable() == false))
  2135. {
  2136. Failed("Local/Expected hashes are not usable for " + PartialFile, NULL);
  2137. return false;
  2138. }
  2139. // final file reached before all patches are applied
  2140. if(LocalHashes == TargetFileHashes)
  2141. {
  2142. Finish(true);
  2143. return true;
  2144. }
  2145. // remove all patches until the next matching patch is found
  2146. // this requires the Index file to be ordered
  2147. available_patches.erase(available_patches.begin(),
  2148. std::find_if(available_patches.begin(), available_patches.end(), [&](DiffInfo const &I) {
  2149. return I.result_hashes == LocalHashes;
  2150. }));
  2151. // error checking and falling back if no patch was found
  2152. if(available_patches.empty() == true)
  2153. {
  2154. Failed("No patches left to reach target for " + PartialFile, NULL);
  2155. return false;
  2156. }
  2157. // queue the right diff
  2158. Desc.URI = Target.URI + ".diff/" + available_patches[0].file + ".gz";
  2159. Desc.Description = Description + " " + available_patches[0].file + string(".pdiff");
  2160. DestFile = GetKeepCompressedFileName(GetPartialFileNameFromURI(Target.URI + ".diff/" + available_patches[0].file), Target);
  2161. if(Debug)
  2162. std::clog << "pkgAcqIndexDiffs::QueueNextDiff(): " << Desc.URI << std::endl;
  2163. QueueURI(Desc);
  2164. return true;
  2165. }
  2166. /*}}}*/
  2167. void pkgAcqIndexDiffs::Done(string const &Message, HashStringList const &Hashes, /*{{{*/
  2168. pkgAcquire::MethodConfig const * const Cnf)
  2169. {
  2170. if (Debug)
  2171. std::clog << "pkgAcqIndexDiffs::Done(): " << Desc.URI << std::endl;
  2172. Item::Done(Message, Hashes, Cnf);
  2173. std::string const UncompressedUnpatchedFile = GetPartialFileNameFromURI(Target.URI);
  2174. std::string const UnpatchedFile = GetExistingFilename(UncompressedUnpatchedFile);
  2175. std::string const PatchFile = GetDiffsPatchFileName(UnpatchedFile);
  2176. std::string const PatchedFile = GetKeepCompressedFileName(UncompressedUnpatchedFile, Target);
  2177. switch (State)
  2178. {
  2179. // success in downloading a diff, enter ApplyDiff state
  2180. case StateFetchDiff:
  2181. Rename(DestFile, PatchFile);
  2182. DestFile = GetKeepCompressedFileName(UncompressedUnpatchedFile + "-patched", Target);
  2183. if(Debug)
  2184. std::clog << "Sending to rred method: " << UnpatchedFile << std::endl;
  2185. State = StateApplyDiff;
  2186. Local = true;
  2187. Desc.URI = "rred:" + UnpatchedFile;
  2188. QueueURI(Desc);
  2189. SetActiveSubprocess("rred");
  2190. return;
  2191. // success in download/apply a diff, queue next (if needed)
  2192. case StateApplyDiff:
  2193. // remove the just applied patch and base file
  2194. available_patches.erase(available_patches.begin());
  2195. RemoveFile("pkgAcqIndexDiffs::Done", PatchFile);
  2196. RemoveFile("pkgAcqIndexDiffs::Done", UnpatchedFile);
  2197. if(Debug)
  2198. std::clog << "Moving patched file in place: " << std::endl
  2199. << DestFile << " -> " << PatchedFile << std::endl;
  2200. Rename(DestFile, PatchedFile);
  2201. // see if there is more to download
  2202. if(available_patches.empty() == false)
  2203. {
  2204. new pkgAcqIndexDiffs(Owner, TransactionManager, Target, available_patches);
  2205. Finish();
  2206. } else {
  2207. DestFile = PatchedFile;
  2208. Finish(true);
  2209. }
  2210. return;
  2211. }
  2212. }
  2213. /*}}}*/
  2214. std::string pkgAcqIndexDiffs::Custom600Headers() const /*{{{*/
  2215. {
  2216. if(State != StateApplyDiff)
  2217. return pkgAcqBaseIndex::Custom600Headers();
  2218. std::ostringstream patchhashes;
  2219. HashStringList const ExpectedHashes = available_patches[0].patch_hashes;
  2220. for (HashStringList::const_iterator hs = ExpectedHashes.begin(); hs != ExpectedHashes.end(); ++hs)
  2221. patchhashes << "\nPatch-0-" << hs->HashType() << "-Hash: " << hs->HashValue();
  2222. patchhashes << pkgAcqBaseIndex::Custom600Headers();
  2223. return patchhashes.str();
  2224. }
  2225. /*}}}*/
  2226. pkgAcqIndexDiffs::~pkgAcqIndexDiffs() {}
  2227. // AcqIndexMergeDiffs::AcqIndexMergeDiffs - Constructor /*{{{*/
  2228. pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire * const Owner,
  2229. pkgAcqMetaClearSig * const TransactionManager,
  2230. IndexTarget const &Target,
  2231. DiffInfo const &patch,
  2232. std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches)
  2233. : pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL),
  2234. patch(patch), allPatches(allPatches), State(StateFetchDiff)
  2235. {
  2236. Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
  2237. Desc.Owner = this;
  2238. Description = Target.Description;
  2239. Desc.ShortDesc = Target.ShortDesc;
  2240. Desc.URI = Target.URI + ".diff/" + patch.file + ".gz";
  2241. Desc.Description = Description + " " + patch.file + ".pdiff";
  2242. DestFile = GetPartialFileNameFromURI(Desc.URI);
  2243. if(Debug)
  2244. std::clog << "pkgAcqIndexMergeDiffs: " << Desc.URI << std::endl;
  2245. QueueURI(Desc);
  2246. }
  2247. /*}}}*/
  2248. void pkgAcqIndexMergeDiffs::Failed(string const &Message,pkgAcquire::MethodConfig const * const Cnf)/*{{{*/
  2249. {
  2250. if(Debug)
  2251. std::clog << "pkgAcqIndexMergeDiffs failed: " << Desc.URI << " with " << Message << std::endl;
  2252. Item::Failed(Message,Cnf);
  2253. Status = StatDone;
  2254. // check if we are the first to fail, otherwise we are done here
  2255. State = StateDoneDiff;
  2256. for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
  2257. I != allPatches->end(); ++I)
  2258. if ((*I)->State == StateErrorDiff)
  2259. {
  2260. State = StateErrorDiff;
  2261. return;
  2262. }
  2263. // first failure means we should fallback
  2264. State = StateErrorDiff;
  2265. if (Debug)
  2266. std::clog << "Falling back to normal index file acquire" << std::endl;
  2267. RenameOnError(PDiffError);
  2268. if (RealFileExists(DestFile))
  2269. Rename(DestFile, DestFile + ".FAILED");
  2270. std::string const UnpatchedFile = GetExistingFilename(GetPartialFileNameFromURI(Target.URI));
  2271. if (UnpatchedFile.empty() == false && FileExists(UnpatchedFile))
  2272. Rename(UnpatchedFile, UnpatchedFile + ".FAILED");
  2273. DestFile.clear();
  2274. new pkgAcqIndex(Owner, TransactionManager, Target);
  2275. }
  2276. /*}}}*/
  2277. void pkgAcqIndexMergeDiffs::Done(string const &Message, HashStringList const &Hashes, /*{{{*/
  2278. pkgAcquire::MethodConfig const * const Cnf)
  2279. {
  2280. if(Debug)
  2281. std::clog << "pkgAcqIndexMergeDiffs::Done(): " << Desc.URI << std::endl;
  2282. Item::Done(Message, Hashes, Cnf);
  2283. if (std::any_of(allPatches->begin(), allPatches->end(),
  2284. [](pkgAcqIndexMergeDiffs const * const P) { return P->State == StateErrorDiff; }))
  2285. {
  2286. if(Debug)
  2287. std::clog << "Another patch failed already, no point in processing this one." << std::endl;
  2288. State = StateErrorDiff;
  2289. return;
  2290. }
  2291. std::string const UncompressedUnpatchedFile = GetPartialFileNameFromURI(Target.URI);
  2292. std::string const UnpatchedFile = GetExistingFilename(UncompressedUnpatchedFile);
  2293. if (UnpatchedFile.empty())
  2294. {
  2295. _error->Fatal("Unpatched file %s doesn't exist (anymore)!", UncompressedUnpatchedFile.c_str());
  2296. State = StateErrorDiff;
  2297. return;
  2298. }
  2299. std::string const PatchFile = GetMergeDiffsPatchFileName(UnpatchedFile, patch.file);
  2300. std::string const PatchedFile = GetKeepCompressedFileName(UncompressedUnpatchedFile, Target);
  2301. switch (State)
  2302. {
  2303. case StateFetchDiff:
  2304. Rename(DestFile, PatchFile);
  2305. // check if this is the last completed diff
  2306. State = StateDoneDiff;
  2307. for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
  2308. I != allPatches->end(); ++I)
  2309. if ((*I)->State != StateDoneDiff)
  2310. {
  2311. if(Debug)
  2312. std::clog << "Not the last done diff in the batch: " << Desc.URI << std::endl;
  2313. return;
  2314. }
  2315. // this is the last completed diff, so we are ready to apply now
  2316. DestFile = GetKeepCompressedFileName(UncompressedUnpatchedFile + "-patched", Target);
  2317. if(Debug)
  2318. std::clog << "Sending to rred method: " << UnpatchedFile << std::endl;
  2319. State = StateApplyDiff;
  2320. Local = true;
  2321. Desc.URI = "rred:" + UnpatchedFile;
  2322. QueueURI(Desc);
  2323. SetActiveSubprocess("rred");
  2324. return;
  2325. case StateApplyDiff:
  2326. // success in download & apply all diffs, finialize and clean up
  2327. if(Debug)
  2328. std::clog << "Queue patched file in place: " << std::endl
  2329. << DestFile << " -> " << PatchedFile << std::endl;
  2330. // queue for copy by the transaction manager
  2331. TransactionManager->TransactionStageCopy(this, DestFile, GetKeepCompressedFileName(GetFinalFilename(), Target));
  2332. // ensure the ed's are gone regardless of list-cleanup
  2333. for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
  2334. I != allPatches->end(); ++I)
  2335. RemoveFile("pkgAcqIndexMergeDiffs::Done", GetMergeDiffsPatchFileName(UnpatchedFile, (*I)->patch.file));
  2336. RemoveFile("pkgAcqIndexMergeDiffs::Done", UnpatchedFile);
  2337. // all set and done
  2338. Complete = true;
  2339. if(Debug)
  2340. std::clog << "allDone: " << DestFile << "\n" << std::endl;
  2341. return;
  2342. case StateDoneDiff: _error->Fatal("Done called for %s which is in an invalid Done state", PatchFile.c_str()); break;
  2343. case StateErrorDiff: _error->Fatal("Done called for %s which is in an invalid Error state", PatchFile.c_str()); break;
  2344. }
  2345. }
  2346. /*}}}*/
  2347. std::string pkgAcqIndexMergeDiffs::Custom600Headers() const /*{{{*/
  2348. {
  2349. if(State != StateApplyDiff)
  2350. return pkgAcqBaseIndex::Custom600Headers();
  2351. std::ostringstream patchhashes;
  2352. unsigned int seen_patches = 0;
  2353. for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
  2354. I != allPatches->end(); ++I)
  2355. {
  2356. HashStringList const ExpectedHashes = (*I)->patch.patch_hashes;
  2357. for (HashStringList::const_iterator hs = ExpectedHashes.begin(); hs != ExpectedHashes.end(); ++hs)
  2358. patchhashes << "\nPatch-" << seen_patches << "-" << hs->HashType() << "-Hash: " << hs->HashValue();
  2359. ++seen_patches;
  2360. }
  2361. patchhashes << pkgAcqBaseIndex::Custom600Headers();
  2362. return patchhashes.str();
  2363. }
  2364. /*}}}*/
  2365. pkgAcqIndexMergeDiffs::~pkgAcqIndexMergeDiffs() {}
  2366. // AcqIndex::AcqIndex - Constructor /*{{{*/
  2367. pkgAcqIndex::pkgAcqIndex(pkgAcquire * const Owner,
  2368. pkgAcqMetaClearSig * const TransactionManager,
  2369. IndexTarget const &Target)
  2370. : pkgAcqBaseIndex(Owner, TransactionManager, Target), d(NULL), Stage(STAGE_DOWNLOAD),
  2371. CompressionExtensions(Target.Option(IndexTarget::COMPRESSIONTYPES))
  2372. {
  2373. Init(Target.URI, Target.Description, Target.ShortDesc);
  2374. if(_config->FindB("Debug::Acquire::Transaction", false) == true)
  2375. std::clog << "New pkgIndex with TransactionManager "
  2376. << TransactionManager << std::endl;
  2377. }
  2378. /*}}}*/
  2379. // AcqIndex::Init - defered Constructor /*{{{*/
  2380. static void NextCompressionExtension(std::string &CurrentCompressionExtension, std::string &CompressionExtensions, bool const preview)
  2381. {
  2382. size_t const nextExt = CompressionExtensions.find(' ');
  2383. if (nextExt == std::string::npos)
  2384. {
  2385. CurrentCompressionExtension = CompressionExtensions;
  2386. if (preview == false)
  2387. CompressionExtensions.clear();
  2388. }
  2389. else
  2390. {
  2391. CurrentCompressionExtension = CompressionExtensions.substr(0, nextExt);
  2392. if (preview == false)
  2393. CompressionExtensions = CompressionExtensions.substr(nextExt+1);
  2394. }
  2395. }
  2396. void pkgAcqIndex::Init(string const &URI, string const &URIDesc,
  2397. string const &ShortDesc)
  2398. {
  2399. Stage = STAGE_DOWNLOAD;
  2400. DestFile = GetPartialFileNameFromURI(URI);
  2401. NextCompressionExtension(CurrentCompressionExtension, CompressionExtensions, false);
  2402. // store file size of the download to ensure the fetcher gives
  2403. // accurate progress reporting
  2404. FileSize = GetExpectedHashes().FileSize();
  2405. if (CurrentCompressionExtension == "uncompressed")
  2406. {
  2407. Desc.URI = URI;
  2408. }
  2409. else if (CurrentCompressionExtension == "by-hash")
  2410. {
  2411. NextCompressionExtension(CurrentCompressionExtension, CompressionExtensions, true);
  2412. if(unlikely(TransactionManager->MetaIndexParser == NULL || CurrentCompressionExtension.empty()))
  2413. return;
  2414. if (CurrentCompressionExtension != "uncompressed")
  2415. {
  2416. Desc.URI = URI + '.' + CurrentCompressionExtension;
  2417. DestFile = DestFile + '.' + CurrentCompressionExtension;
  2418. }
  2419. HashStringList const Hashes = GetExpectedHashes();
  2420. HashString const * const TargetHash = Hashes.find(NULL);
  2421. if (unlikely(TargetHash == nullptr))
  2422. return;
  2423. std::string const ByHash = "/by-hash/" + TargetHash->HashType() + "/" + TargetHash->HashValue();
  2424. size_t const trailing_slash = Desc.URI.find_last_of("/");
  2425. if (unlikely(trailing_slash == std::string::npos))
  2426. return;
  2427. Desc.URI = Desc.URI.replace(
  2428. trailing_slash,
  2429. Desc.URI.substr(trailing_slash+1).size()+1,
  2430. ByHash);
  2431. }
  2432. else if (unlikely(CurrentCompressionExtension.empty()))
  2433. return;
  2434. else
  2435. {
  2436. Desc.URI = URI + '.' + CurrentCompressionExtension;
  2437. DestFile = DestFile + '.' + CurrentCompressionExtension;
  2438. }
  2439. Desc.Description = URIDesc;
  2440. Desc.Owner = this;
  2441. Desc.ShortDesc = ShortDesc;
  2442. QueueURI(Desc);
  2443. }
  2444. /*}}}*/
  2445. // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
  2446. // ---------------------------------------------------------------------
  2447. /* The only header we use is the last-modified header. */
  2448. string pkgAcqIndex::Custom600Headers() const
  2449. {
  2450. string msg = "\nIndex-File: true";
  2451. if (TransactionManager->LastMetaIndexParser == NULL)
  2452. {
  2453. std::string const Final = GetFinalFilename();
  2454. struct stat Buf;
  2455. if (stat(Final.c_str(),&Buf) == 0)
  2456. msg += "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  2457. }
  2458. if(Target.IsOptional)
  2459. msg += "\nFail-Ignore: true";
  2460. return msg;
  2461. }
  2462. /*}}}*/
  2463. // AcqIndex::Failed - getting the indexfile failed /*{{{*/
  2464. void pkgAcqIndex::Failed(string const &Message,pkgAcquire::MethodConfig const * const Cnf)
  2465. {
  2466. Item::Failed(Message,Cnf);
  2467. // authorisation matches will not be fixed by other compression types
  2468. if (Status != StatAuthError)
  2469. {
  2470. if (CompressionExtensions.empty() == false)
  2471. {
  2472. Init(Target.URI, Desc.Description, Desc.ShortDesc);
  2473. Status = StatIdle;
  2474. return;
  2475. }
  2476. }
  2477. if(Target.IsOptional && GetExpectedHashes().empty() && Stage == STAGE_DOWNLOAD)
  2478. Status = StatDone;
  2479. else
  2480. TransactionManager->AbortTransaction();
  2481. }
  2482. /*}}}*/
  2483. // AcqIndex::Done - Finished a fetch /*{{{*/
  2484. // ---------------------------------------------------------------------
  2485. /* This goes through a number of states.. On the initial fetch the
  2486. method could possibly return an alternate filename which points
  2487. to the uncompressed version of the file. If this is so the file
  2488. is copied into the partial directory. In all other cases the file
  2489. is decompressed with a compressed uri. */
  2490. void pkgAcqIndex::Done(string const &Message,
  2491. HashStringList const &Hashes,
  2492. pkgAcquire::MethodConfig const * const Cfg)
  2493. {
  2494. Item::Done(Message,Hashes,Cfg);
  2495. switch(Stage)
  2496. {
  2497. case STAGE_DOWNLOAD:
  2498. StageDownloadDone(Message);
  2499. break;
  2500. case STAGE_DECOMPRESS_AND_VERIFY:
  2501. StageDecompressDone();
  2502. break;
  2503. }
  2504. }
  2505. /*}}}*/
  2506. // AcqIndex::StageDownloadDone - Queue for decompress and verify /*{{{*/
  2507. void pkgAcqIndex::StageDownloadDone(string const &Message)
  2508. {
  2509. Local = true;
  2510. Complete = true;
  2511. std::string const AltFilename = LookupTag(Message,"Alt-Filename");
  2512. std::string Filename = LookupTag(Message,"Filename");
  2513. // we need to verify the file against the current Release file again
  2514. // on if-modfied-since hit to avoid a stale attack against us
  2515. if(StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
  2516. {
  2517. // copy FinalFile into partial/ so that we check the hash again
  2518. string const FinalFile = GetExistingFilename(GetFinalFileNameFromURI(Target.URI));
  2519. if (symlink(FinalFile.c_str(), DestFile.c_str()) != 0)
  2520. _error->WarningE("pkgAcqIndex::StageDownloadDone", "Symlinking final file %s back to %s failed", FinalFile.c_str(), DestFile.c_str());
  2521. else
  2522. {
  2523. EraseFileName = DestFile;
  2524. Filename = DestFile;
  2525. }
  2526. Stage = STAGE_DECOMPRESS_AND_VERIFY;
  2527. Desc.URI = "store:" + Filename;
  2528. QueueURI(Desc);
  2529. SetActiveSubprocess(::URI(Desc.URI).Access);
  2530. return;
  2531. }
  2532. // methods like file:// give us an alternative (uncompressed) file
  2533. else if (Target.KeepCompressed == false && AltFilename.empty() == false)
  2534. {
  2535. Filename = AltFilename;
  2536. EraseFileName.clear();
  2537. }
  2538. // Methods like e.g. "file:" will give us a (compressed) FileName that is
  2539. // not the "DestFile" we set, in this case we uncompress from the local file
  2540. else if (Filename != DestFile && RealFileExists(DestFile) == false)
  2541. {
  2542. // symlinking ensures that the filename can be used for compression detection
  2543. // that is e.g. needed for by-hash which has no extension over file
  2544. if (symlink(Filename.c_str(),DestFile.c_str()) != 0)
  2545. _error->WarningE("pkgAcqIndex::StageDownloadDone", "Symlinking file %s to %s failed", Filename.c_str(), DestFile.c_str());
  2546. else
  2547. {
  2548. EraseFileName = DestFile;
  2549. Filename = DestFile;
  2550. }
  2551. }
  2552. Stage = STAGE_DECOMPRESS_AND_VERIFY;
  2553. DestFile = GetKeepCompressedFileName(GetPartialFileNameFromURI(Target.URI), Target);
  2554. if (Filename != DestFile && flExtension(Filename) == flExtension(DestFile))
  2555. Desc.URI = "copy:" + Filename;
  2556. else
  2557. Desc.URI = "store:" + Filename;
  2558. if (DestFile == Filename)
  2559. {
  2560. if (CurrentCompressionExtension == "uncompressed")
  2561. return StageDecompressDone();
  2562. DestFile = "/dev/null";
  2563. }
  2564. if (EraseFileName.empty() && Filename != AltFilename)
  2565. EraseFileName = Filename;
  2566. // queue uri for the next stage
  2567. QueueURI(Desc);
  2568. SetActiveSubprocess(::URI(Desc.URI).Access);
  2569. }
  2570. /*}}}*/
  2571. // AcqIndex::StageDecompressDone - Final verification /*{{{*/
  2572. void pkgAcqIndex::StageDecompressDone()
  2573. {
  2574. if (DestFile == "/dev/null")
  2575. DestFile = GetKeepCompressedFileName(GetPartialFileNameFromURI(Target.URI), Target);
  2576. // Done, queue for rename on transaction finished
  2577. TransactionManager->TransactionStageCopy(this, DestFile, GetFinalFilename());
  2578. }
  2579. /*}}}*/
  2580. pkgAcqIndex::~pkgAcqIndex() {}
  2581. // AcqArchive::AcqArchive - Constructor /*{{{*/
  2582. // ---------------------------------------------------------------------
  2583. /* This just sets up the initial fetch environment and queues the first
  2584. possibilitiy */
  2585. pkgAcqArchive::pkgAcqArchive(pkgAcquire * const Owner,pkgSourceList * const Sources,
  2586. pkgRecords * const Recs,pkgCache::VerIterator const &Version,
  2587. string &StoreFilename) :
  2588. Item(Owner), d(NULL), LocalSource(false), Version(Version), Sources(Sources), Recs(Recs),
  2589. StoreFilename(StoreFilename), Vf(Version.FileList()),
  2590. Trusted(false)
  2591. {
  2592. Retries = _config->FindI("Acquire::Retries",0);
  2593. if (Version.Arch() == 0)
  2594. {
  2595. _error->Error(_("I wasn't able to locate a file for the %s package. "
  2596. "This might mean you need to manually fix this package. "
  2597. "(due to missing arch)"),
  2598. Version.ParentPkg().FullName().c_str());
  2599. return;
  2600. }
  2601. /* We need to find a filename to determine the extension. We make the
  2602. assumption here that all the available sources for this version share
  2603. the same extension.. */
  2604. // Skip not source sources, they do not have file fields.
  2605. for (; Vf.end() == false; ++Vf)
  2606. {
  2607. if (Vf.File().Flagged(pkgCache::Flag::NotSource))
  2608. continue;
  2609. break;
  2610. }
  2611. // Does not really matter here.. we are going to fail out below
  2612. if (Vf.end() != true)
  2613. {
  2614. // If this fails to get a file name we will bomb out below.
  2615. pkgRecords::Parser &Parse = Recs->Lookup(Vf);
  2616. if (_error->PendingError() == true)
  2617. return;
  2618. // Generate the final file name as: package_version_arch.foo
  2619. StoreFilename = QuoteString(Version.ParentPkg().Name(),"_:") + '_' +
  2620. QuoteString(Version.VerStr(),"_:") + '_' +
  2621. QuoteString(Version.Arch(),"_:.") +
  2622. "." + flExtension(Parse.FileName());
  2623. }
  2624. // check if we have one trusted source for the package. if so, switch
  2625. // to "TrustedOnly" mode - but only if not in AllowUnauthenticated mode
  2626. bool const allowUnauth = _config->FindB("APT::Get::AllowUnauthenticated", false);
  2627. bool const debugAuth = _config->FindB("Debug::pkgAcquire::Auth", false);
  2628. bool seenUntrusted = false;
  2629. for (pkgCache::VerFileIterator i = Version.FileList(); i.end() == false; ++i)
  2630. {
  2631. pkgIndexFile *Index;
  2632. if (Sources->FindIndex(i.File(),Index) == false)
  2633. continue;
  2634. if (debugAuth == true)
  2635. std::cerr << "Checking index: " << Index->Describe()
  2636. << "(Trusted=" << Index->IsTrusted() << ")" << std::endl;
  2637. if (Index->IsTrusted() == true)
  2638. {
  2639. Trusted = true;
  2640. if (allowUnauth == false)
  2641. break;
  2642. }
  2643. else
  2644. seenUntrusted = true;
  2645. }
  2646. // "allow-unauthenticated" restores apts old fetching behaviour
  2647. // that means that e.g. unauthenticated file:// uris are higher
  2648. // priority than authenticated http:// uris
  2649. if (allowUnauth == true && seenUntrusted == true)
  2650. Trusted = false;
  2651. // Select a source
  2652. if (QueueNext() == false && _error->PendingError() == false)
  2653. _error->Error(_("Can't find a source to download version '%s' of '%s'"),
  2654. Version.VerStr(), Version.ParentPkg().FullName(false).c_str());
  2655. }
  2656. /*}}}*/
  2657. // AcqArchive::QueueNext - Queue the next file source /*{{{*/
  2658. // ---------------------------------------------------------------------
  2659. /* This queues the next available file version for download. It checks if
  2660. the archive is already available in the cache and stashs the MD5 for
  2661. checking later. */
  2662. bool pkgAcqArchive::QueueNext()
  2663. {
  2664. for (; Vf.end() == false; ++Vf)
  2665. {
  2666. pkgCache::PkgFileIterator const PkgF = Vf.File();
  2667. // Ignore not source sources
  2668. if (PkgF.Flagged(pkgCache::Flag::NotSource))
  2669. continue;
  2670. // Try to cross match against the source list
  2671. pkgIndexFile *Index;
  2672. if (Sources->FindIndex(PkgF, Index) == false)
  2673. continue;
  2674. LocalSource = PkgF.Flagged(pkgCache::Flag::LocalSource);
  2675. // only try to get a trusted package from another source if that source
  2676. // is also trusted
  2677. if(Trusted && !Index->IsTrusted())
  2678. continue;
  2679. // Grab the text package record
  2680. pkgRecords::Parser &Parse = Recs->Lookup(Vf);
  2681. if (_error->PendingError() == true)
  2682. return false;
  2683. string PkgFile = Parse.FileName();
  2684. ExpectedHashes = Parse.Hashes();
  2685. if (PkgFile.empty() == true)
  2686. return _error->Error(_("The package index files are corrupted. No Filename: "
  2687. "field for package %s."),
  2688. Version.ParentPkg().Name());
  2689. Desc.URI = Index->ArchiveURI(PkgFile);
  2690. Desc.Description = Index->ArchiveInfo(Version);
  2691. Desc.Owner = this;
  2692. Desc.ShortDesc = Version.ParentPkg().FullName(true);
  2693. // See if we already have the file. (Legacy filenames)
  2694. FileSize = Version->Size;
  2695. string FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile);
  2696. struct stat Buf;
  2697. if (stat(FinalFile.c_str(),&Buf) == 0)
  2698. {
  2699. // Make sure the size matches
  2700. if ((unsigned long long)Buf.st_size == Version->Size)
  2701. {
  2702. Complete = true;
  2703. Local = true;
  2704. Status = StatDone;
  2705. StoreFilename = DestFile = FinalFile;
  2706. return true;
  2707. }
  2708. /* Hmm, we have a file and its size does not match, this means it is
  2709. an old style mismatched arch */
  2710. RemoveFile("pkgAcqArchive::QueueNext", FinalFile);
  2711. }
  2712. // Check it again using the new style output filenames
  2713. FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename);
  2714. if (stat(FinalFile.c_str(),&Buf) == 0)
  2715. {
  2716. // Make sure the size matches
  2717. if ((unsigned long long)Buf.st_size == Version->Size)
  2718. {
  2719. Complete = true;
  2720. Local = true;
  2721. Status = StatDone;
  2722. StoreFilename = DestFile = FinalFile;
  2723. return true;
  2724. }
  2725. /* Hmm, we have a file and its size does not match, this shouldn't
  2726. happen.. */
  2727. RemoveFile("pkgAcqArchive::QueueNext", FinalFile);
  2728. }
  2729. DestFile = _config->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(StoreFilename);
  2730. // Check the destination file
  2731. if (stat(DestFile.c_str(),&Buf) == 0)
  2732. {
  2733. // Hmm, the partial file is too big, erase it
  2734. if ((unsigned long long)Buf.st_size > Version->Size)
  2735. RemoveFile("pkgAcqArchive::QueueNext", DestFile);
  2736. else
  2737. PartialSize = Buf.st_size;
  2738. }
  2739. // Disables download of archives - useful if no real installation follows,
  2740. // e.g. if we are just interested in proposed installation order
  2741. if (_config->FindB("Debug::pkgAcqArchive::NoQueue", false) == true)
  2742. {
  2743. Complete = true;
  2744. Local = true;
  2745. Status = StatDone;
  2746. StoreFilename = DestFile = FinalFile;
  2747. return true;
  2748. }
  2749. // Create the item
  2750. Local = false;
  2751. QueueURI(Desc);
  2752. ++Vf;
  2753. return true;
  2754. }
  2755. return false;
  2756. }
  2757. /*}}}*/
  2758. // AcqArchive::Done - Finished fetching /*{{{*/
  2759. // ---------------------------------------------------------------------
  2760. /* */
  2761. void pkgAcqArchive::Done(string const &Message, HashStringList const &Hashes,
  2762. pkgAcquire::MethodConfig const * const Cfg)
  2763. {
  2764. Item::Done(Message, Hashes, Cfg);
  2765. // Grab the output filename
  2766. std::string const FileName = LookupTag(Message,"Filename");
  2767. if (DestFile != FileName && RealFileExists(DestFile) == false)
  2768. {
  2769. StoreFilename = DestFile = FileName;
  2770. Local = true;
  2771. Complete = true;
  2772. return;
  2773. }
  2774. // Done, move it into position
  2775. string const FinalFile = GetFinalFilename();
  2776. Rename(DestFile,FinalFile);
  2777. StoreFilename = DestFile = FinalFile;
  2778. Complete = true;
  2779. }
  2780. /*}}}*/
  2781. // AcqArchive::Failed - Failure handler /*{{{*/
  2782. // ---------------------------------------------------------------------
  2783. /* Here we try other sources */
  2784. void pkgAcqArchive::Failed(string const &Message,pkgAcquire::MethodConfig const * const Cnf)
  2785. {
  2786. Item::Failed(Message,Cnf);
  2787. /* We don't really want to retry on failed media swaps, this prevents
  2788. that. An interesting observation is that permanent failures are not
  2789. recorded. */
  2790. if (Cnf->Removable == true &&
  2791. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  2792. {
  2793. // Vf = Version.FileList();
  2794. while (Vf.end() == false) ++Vf;
  2795. StoreFilename = string();
  2796. return;
  2797. }
  2798. Status = StatIdle;
  2799. if (QueueNext() == false)
  2800. {
  2801. // This is the retry counter
  2802. if (Retries != 0 &&
  2803. Cnf->LocalOnly == false &&
  2804. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  2805. {
  2806. Retries--;
  2807. Vf = Version.FileList();
  2808. if (QueueNext() == true)
  2809. return;
  2810. }
  2811. StoreFilename = string();
  2812. Status = StatError;
  2813. }
  2814. }
  2815. /*}}}*/
  2816. APT_PURE bool pkgAcqArchive::IsTrusted() const /*{{{*/
  2817. {
  2818. return Trusted;
  2819. }
  2820. /*}}}*/
  2821. void pkgAcqArchive::Finished() /*{{{*/
  2822. {
  2823. if (Status == pkgAcquire::Item::StatDone &&
  2824. Complete == true)
  2825. return;
  2826. StoreFilename = string();
  2827. }
  2828. /*}}}*/
  2829. std::string pkgAcqArchive::DescURI() const /*{{{*/
  2830. {
  2831. return Desc.URI;
  2832. }
  2833. /*}}}*/
  2834. std::string pkgAcqArchive::ShortDesc() const /*{{{*/
  2835. {
  2836. return Desc.ShortDesc;
  2837. }
  2838. /*}}}*/
  2839. pkgAcqArchive::~pkgAcqArchive() {}
  2840. // AcqChangelog::pkgAcqChangelog - Constructors /*{{{*/
  2841. class pkgAcqChangelog::Private
  2842. {
  2843. public:
  2844. std::string FinalFile;
  2845. };
  2846. pkgAcqChangelog::pkgAcqChangelog(pkgAcquire * const Owner, pkgCache::VerIterator const &Ver,
  2847. std::string const &DestDir, std::string const &DestFilename) :
  2848. pkgAcquire::Item(Owner), d(new pkgAcqChangelog::Private()), SrcName(Ver.SourcePkgName()), SrcVersion(Ver.SourceVerStr())
  2849. {
  2850. Desc.URI = URI(Ver);
  2851. Init(DestDir, DestFilename);
  2852. }
  2853. // some parameters are char* here as they come likely from char* interfaces – which can also return NULL
  2854. pkgAcqChangelog::pkgAcqChangelog(pkgAcquire * const Owner, pkgCache::RlsFileIterator const &RlsFile,
  2855. char const * const Component, char const * const SrcName, char const * const SrcVersion,
  2856. const string &DestDir, const string &DestFilename) :
  2857. pkgAcquire::Item(Owner), d(new pkgAcqChangelog::Private()), SrcName(SrcName), SrcVersion(SrcVersion)
  2858. {
  2859. Desc.URI = URI(RlsFile, Component, SrcName, SrcVersion);
  2860. Init(DestDir, DestFilename);
  2861. }
  2862. pkgAcqChangelog::pkgAcqChangelog(pkgAcquire * const Owner,
  2863. std::string const &URI, char const * const SrcName, char const * const SrcVersion,
  2864. const string &DestDir, const string &DestFilename) :
  2865. pkgAcquire::Item(Owner), d(new pkgAcqChangelog::Private()), SrcName(SrcName), SrcVersion(SrcVersion)
  2866. {
  2867. Desc.URI = URI;
  2868. Init(DestDir, DestFilename);
  2869. }
  2870. void pkgAcqChangelog::Init(std::string const &DestDir, std::string const &DestFilename)
  2871. {
  2872. if (Desc.URI.empty())
  2873. {
  2874. Status = StatError;
  2875. // TRANSLATOR: %s=%s is sourcename=sourceversion, e.g. apt=1.1
  2876. strprintf(ErrorText, _("Changelog unavailable for %s=%s"), SrcName.c_str(), SrcVersion.c_str());
  2877. // Let the error message print something sensible rather than "Failed to fetch /"
  2878. if (DestFilename.empty())
  2879. DestFile = SrcName + ".changelog";
  2880. else
  2881. DestFile = DestFilename;
  2882. Desc.URI = "changelog:/" + DestFile;
  2883. return;
  2884. }
  2885. std::string DestFileName;
  2886. if (DestFilename.empty())
  2887. DestFileName = flCombine(DestFile, SrcName + ".changelog");
  2888. else
  2889. DestFileName = flCombine(DestFile, DestFilename);
  2890. std::string const SandboxUser = _config->Find("APT::Sandbox::User");
  2891. std::string const systemTemp = GetTempDir(SandboxUser);
  2892. char tmpname[1000];
  2893. snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX", systemTemp.c_str());
  2894. if (NULL == mkdtemp(tmpname))
  2895. {
  2896. _error->Errno("mkdtemp", "mkdtemp failed in changelog acquire of %s %s", SrcName.c_str(), SrcVersion.c_str());
  2897. Status = StatError;
  2898. return;
  2899. }
  2900. TemporaryDirectory = tmpname;
  2901. ChangeOwnerAndPermissionOfFile("Item::QueueURI", TemporaryDirectory.c_str(),
  2902. SandboxUser.c_str(), "root", 0700);
  2903. DestFile = flCombine(TemporaryDirectory, DestFileName);
  2904. if (DestDir.empty() == false)
  2905. {
  2906. d->FinalFile = flCombine(DestDir, DestFileName);
  2907. if (RealFileExists(d->FinalFile))
  2908. {
  2909. FileFd file1, file2;
  2910. if (file1.Open(DestFile, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive) &&
  2911. file2.Open(d->FinalFile, FileFd::ReadOnly) && CopyFile(file2, file1))
  2912. {
  2913. struct timeval times[2];
  2914. times[0].tv_sec = times[1].tv_sec = file2.ModificationTime();
  2915. times[0].tv_usec = times[1].tv_usec = 0;
  2916. utimes(DestFile.c_str(), times);
  2917. }
  2918. }
  2919. }
  2920. Desc.ShortDesc = "Changelog";
  2921. strprintf(Desc.Description, "%s %s %s Changelog", URI::SiteOnly(Desc.URI).c_str(), SrcName.c_str(), SrcVersion.c_str());
  2922. Desc.Owner = this;
  2923. QueueURI(Desc);
  2924. }
  2925. /*}}}*/
  2926. std::string pkgAcqChangelog::URI(pkgCache::VerIterator const &Ver) /*{{{*/
  2927. {
  2928. std::string const confOnline = "Acquire::Changelogs::AlwaysOnline";
  2929. bool AlwaysOnline = _config->FindB(confOnline, false);
  2930. if (AlwaysOnline == false)
  2931. for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; ++VF)
  2932. {
  2933. pkgCache::PkgFileIterator const PF = VF.File();
  2934. if (PF.Flagged(pkgCache::Flag::NotSource) || PF->Release == 0)
  2935. continue;
  2936. pkgCache::RlsFileIterator const RF = PF.ReleaseFile();
  2937. if (RF->Origin != 0 && _config->FindB(confOnline + "::Origin::" + RF.Origin(), false))
  2938. {
  2939. AlwaysOnline = true;
  2940. break;
  2941. }
  2942. }
  2943. if (AlwaysOnline == false)
  2944. {
  2945. pkgCache::PkgIterator const Pkg = Ver.ParentPkg();
  2946. if (Pkg->CurrentVer != 0 && Pkg.CurrentVer() == Ver)
  2947. {
  2948. std::string const basename = std::string("/usr/share/doc/") + Pkg.Name() + "/changelog";
  2949. std::string const debianname = basename + ".Debian";
  2950. if (FileExists(debianname))
  2951. return "copy://" + debianname;
  2952. else if (FileExists(debianname + ".gz"))
  2953. return "gzip://" + debianname + ".gz";
  2954. else if (FileExists(basename))
  2955. return "copy://" + basename;
  2956. else if (FileExists(basename + ".gz"))
  2957. return "gzip://" + basename + ".gz";
  2958. }
  2959. }
  2960. char const * const SrcName = Ver.SourcePkgName();
  2961. char const * const SrcVersion = Ver.SourceVerStr();
  2962. // find the first source for this version which promises a changelog
  2963. for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; ++VF)
  2964. {
  2965. pkgCache::PkgFileIterator const PF = VF.File();
  2966. if (PF.Flagged(pkgCache::Flag::NotSource) || PF->Release == 0)
  2967. continue;
  2968. pkgCache::RlsFileIterator const RF = PF.ReleaseFile();
  2969. std::string const uri = URI(RF, PF.Component(), SrcName, SrcVersion);
  2970. if (uri.empty())
  2971. continue;
  2972. return uri;
  2973. }
  2974. return "";
  2975. }
  2976. std::string pkgAcqChangelog::URITemplate(pkgCache::RlsFileIterator const &Rls)
  2977. {
  2978. if (Rls.end() == true || (Rls->Label == 0 && Rls->Origin == 0))
  2979. return "";
  2980. std::string const serverConfig = "Acquire::Changelogs::URI";
  2981. std::string server;
  2982. #define APT_EMPTY_SERVER \
  2983. if (server.empty() == false) \
  2984. { \
  2985. if (server != "no") \
  2986. return server; \
  2987. return ""; \
  2988. }
  2989. #define APT_CHECK_SERVER(X, Y) \
  2990. if (Rls->X != 0) \
  2991. { \
  2992. std::string const specialServerConfig = serverConfig + "::" + Y + #X + "::" + Rls.X(); \
  2993. server = _config->Find(specialServerConfig); \
  2994. APT_EMPTY_SERVER \
  2995. }
  2996. // this way e.g. Debian-Security can fallback to Debian
  2997. APT_CHECK_SERVER(Label, "Override::")
  2998. APT_CHECK_SERVER(Origin, "Override::")
  2999. if (RealFileExists(Rls.FileName()))
  3000. {
  3001. _error->PushToStack();
  3002. FileFd rf;
  3003. /* This can be costly. A caller wanting to get millions of URIs might
  3004. want to do this on its own once and use Override settings.
  3005. We don't do this here as Origin/Label are not as unique as they
  3006. should be so this could produce request order-dependent anomalies */
  3007. if (OpenMaybeClearSignedFile(Rls.FileName(), rf) == true)
  3008. {
  3009. pkgTagFile TagFile(&rf, rf.Size());
  3010. pkgTagSection Section;
  3011. if (TagFile.Step(Section) == true)
  3012. server = Section.FindS("Changelogs");
  3013. }
  3014. _error->RevertToStack();
  3015. APT_EMPTY_SERVER
  3016. }
  3017. APT_CHECK_SERVER(Label, "")
  3018. APT_CHECK_SERVER(Origin, "")
  3019. #undef APT_CHECK_SERVER
  3020. #undef APT_EMPTY_SERVER
  3021. return "";
  3022. }
  3023. std::string pkgAcqChangelog::URI(pkgCache::RlsFileIterator const &Rls,
  3024. char const * const Component, char const * const SrcName,
  3025. char const * const SrcVersion)
  3026. {
  3027. return URI(URITemplate(Rls), Component, SrcName, SrcVersion);
  3028. }
  3029. std::string pkgAcqChangelog::URI(std::string const &Template,
  3030. char const * const Component, char const * const SrcName,
  3031. char const * const SrcVersion)
  3032. {
  3033. if (Template.find("@CHANGEPATH@") == std::string::npos)
  3034. return "";
  3035. // the path is: COMPONENT/SRC/SRCNAME/SRCNAME_SRCVER, e.g. main/a/apt/1.1 or contrib/liba/libapt/2.0
  3036. std::string Src = SrcName;
  3037. std::string path = APT::String::Startswith(SrcName, "lib") ? Src.substr(0, 4) : Src.substr(0,1);
  3038. path.append("/").append(Src).append("/");
  3039. path.append(Src).append("_").append(StripEpoch(SrcVersion));
  3040. // we omit component for releases without one (= flat-style repositories)
  3041. if (Component != NULL && strlen(Component) != 0)
  3042. path = std::string(Component) + "/" + path;
  3043. return SubstVar(Template, "@CHANGEPATH@", path);
  3044. }
  3045. /*}}}*/
  3046. // AcqChangelog::Failed - Failure handler /*{{{*/
  3047. void pkgAcqChangelog::Failed(string const &Message, pkgAcquire::MethodConfig const * const Cnf)
  3048. {
  3049. Item::Failed(Message,Cnf);
  3050. std::string errText;
  3051. // TRANSLATOR: %s=%s is sourcename=sourceversion, e.g. apt=1.1
  3052. strprintf(errText, _("Changelog unavailable for %s=%s"), SrcName.c_str(), SrcVersion.c_str());
  3053. // Error is probably something techy like 404 Not Found
  3054. if (ErrorText.empty())
  3055. ErrorText = errText;
  3056. else
  3057. ErrorText = errText + " (" + ErrorText + ")";
  3058. }
  3059. /*}}}*/
  3060. // AcqChangelog::Done - Item downloaded OK /*{{{*/
  3061. void pkgAcqChangelog::Done(string const &Message,HashStringList const &CalcHashes,
  3062. pkgAcquire::MethodConfig const * const Cnf)
  3063. {
  3064. Item::Done(Message,CalcHashes,Cnf);
  3065. if (d->FinalFile.empty() == false)
  3066. {
  3067. if (RemoveFile("pkgAcqChangelog::Done", d->FinalFile) == false ||
  3068. Rename(DestFile, d->FinalFile) == false)
  3069. Status = StatError;
  3070. }
  3071. Complete = true;
  3072. }
  3073. /*}}}*/
  3074. pkgAcqChangelog::~pkgAcqChangelog() /*{{{*/
  3075. {
  3076. if (TemporaryDirectory.empty() == false)
  3077. {
  3078. RemoveFile("~pkgAcqChangelog", DestFile);
  3079. rmdir(TemporaryDirectory.c_str());
  3080. }
  3081. delete d;
  3082. }
  3083. /*}}}*/
  3084. // AcqFile::pkgAcqFile - Constructor /*{{{*/
  3085. pkgAcqFile::pkgAcqFile(pkgAcquire * const Owner,string const &URI, HashStringList const &Hashes,
  3086. unsigned long long const Size,string const &Dsc,string const &ShortDesc,
  3087. const string &DestDir, const string &DestFilename,
  3088. bool const IsIndexFile) :
  3089. Item(Owner), d(NULL), IsIndexFile(IsIndexFile), ExpectedHashes(Hashes)
  3090. {
  3091. Retries = _config->FindI("Acquire::Retries",0);
  3092. if(!DestFilename.empty())
  3093. DestFile = DestFilename;
  3094. else if(!DestDir.empty())
  3095. DestFile = DestDir + "/" + flNotDir(URI);
  3096. else
  3097. DestFile = flNotDir(URI);
  3098. // Create the item
  3099. Desc.URI = URI;
  3100. Desc.Description = Dsc;
  3101. Desc.Owner = this;
  3102. // Set the short description to the archive component
  3103. Desc.ShortDesc = ShortDesc;
  3104. // Get the transfer sizes
  3105. FileSize = Size;
  3106. struct stat Buf;
  3107. if (stat(DestFile.c_str(),&Buf) == 0)
  3108. {
  3109. // Hmm, the partial file is too big, erase it
  3110. if ((Size > 0) && (unsigned long long)Buf.st_size > Size)
  3111. RemoveFile("pkgAcqFile", DestFile);
  3112. else
  3113. PartialSize = Buf.st_size;
  3114. }
  3115. QueueURI(Desc);
  3116. }
  3117. /*}}}*/
  3118. // AcqFile::Done - Item downloaded OK /*{{{*/
  3119. void pkgAcqFile::Done(string const &Message,HashStringList const &CalcHashes,
  3120. pkgAcquire::MethodConfig const * const Cnf)
  3121. {
  3122. Item::Done(Message,CalcHashes,Cnf);
  3123. std::string const FileName = LookupTag(Message,"Filename");
  3124. Complete = true;
  3125. // The files timestamp matches
  3126. if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
  3127. return;
  3128. // We have to copy it into place
  3129. if (RealFileExists(DestFile.c_str()) == false)
  3130. {
  3131. Local = true;
  3132. if (_config->FindB("Acquire::Source-Symlinks",true) == false ||
  3133. Cnf->Removable == true)
  3134. {
  3135. Desc.URI = "copy:" + FileName;
  3136. QueueURI(Desc);
  3137. return;
  3138. }
  3139. // Erase the file if it is a symlink so we can overwrite it
  3140. struct stat St;
  3141. if (lstat(DestFile.c_str(),&St) == 0)
  3142. {
  3143. if (S_ISLNK(St.st_mode) != 0)
  3144. RemoveFile("pkgAcqFile::Done", DestFile);
  3145. }
  3146. // Symlink the file
  3147. if (symlink(FileName.c_str(),DestFile.c_str()) != 0)
  3148. {
  3149. _error->PushToStack();
  3150. _error->Errno("pkgAcqFile::Done", "Symlinking file %s failed", DestFile.c_str());
  3151. std::stringstream msg;
  3152. _error->DumpErrors(msg, GlobalError::DEBUG, false);
  3153. _error->RevertToStack();
  3154. ErrorText = msg.str();
  3155. Status = StatError;
  3156. Complete = false;
  3157. }
  3158. }
  3159. }
  3160. /*}}}*/
  3161. // AcqFile::Failed - Failure handler /*{{{*/
  3162. // ---------------------------------------------------------------------
  3163. /* Here we try other sources */
  3164. void pkgAcqFile::Failed(string const &Message, pkgAcquire::MethodConfig const * const Cnf)
  3165. {
  3166. Item::Failed(Message,Cnf);
  3167. // This is the retry counter
  3168. if (Retries != 0 &&
  3169. Cnf->LocalOnly == false &&
  3170. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  3171. {
  3172. --Retries;
  3173. QueueURI(Desc);
  3174. Status = StatIdle;
  3175. return;
  3176. }
  3177. }
  3178. /*}}}*/
  3179. string pkgAcqFile::Custom600Headers() const /*{{{*/
  3180. {
  3181. if (IsIndexFile)
  3182. return "\nIndex-File: true";
  3183. return "";
  3184. }
  3185. /*}}}*/
  3186. pkgAcqFile::~pkgAcqFile() {}