acquire-item.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire-item.cc,v 1.42 2001/02/20 07:03:17 jgg 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. #ifdef __GNUG__
  14. #pragma implementation "apt-pkg/acquire-item.h"
  15. #endif
  16. #include <apt-pkg/acquire-item.h>
  17. #include <apt-pkg/configuration.h>
  18. #include <apt-pkg/sourcelist.h>
  19. #include <apt-pkg/error.h>
  20. #include <apt-pkg/strutl.h>
  21. #include <apt-pkg/fileutl.h>
  22. #include <apti18n.h>
  23. #include <sys/stat.h>
  24. #include <unistd.h>
  25. #include <errno.h>
  26. #include <string.h>
  27. #include <stdio.h>
  28. /*}}}*/
  29. // Acquire::Item::Item - Constructor /*{{{*/
  30. // ---------------------------------------------------------------------
  31. /* */
  32. pkgAcquire::Item::Item(pkgAcquire *Owner) : Owner(Owner), FileSize(0),
  33. PartialSize(0), Mode(0), ID(0), Complete(false),
  34. Local(false), QueueCounter(0)
  35. {
  36. Owner->Add(this);
  37. Status = StatIdle;
  38. }
  39. /*}}}*/
  40. // Acquire::Item::~Item - Destructor /*{{{*/
  41. // ---------------------------------------------------------------------
  42. /* */
  43. pkgAcquire::Item::~Item()
  44. {
  45. Owner->Remove(this);
  46. }
  47. /*}}}*/
  48. // Acquire::Item::Failed - Item failed to download /*{{{*/
  49. // ---------------------------------------------------------------------
  50. /* We return to an idle state if there are still other queues that could
  51. fetch this object */
  52. void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
  53. {
  54. Status = StatIdle;
  55. ErrorText = LookupTag(Message,"Message");
  56. if (QueueCounter <= 1)
  57. {
  58. /* This indicates that the file is not available right now but might
  59. be sometime later. If we do a retry cycle then this should be
  60. retried [CDROMs] */
  61. if (Cnf->LocalOnly == true &&
  62. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  63. {
  64. Status = StatIdle;
  65. Dequeue();
  66. return;
  67. }
  68. Status = StatError;
  69. Dequeue();
  70. }
  71. }
  72. /*}}}*/
  73. // Acquire::Item::Start - Item has begun to download /*{{{*/
  74. // ---------------------------------------------------------------------
  75. /* Stash status and the file size. Note that setting Complete means
  76. sub-phases of the acquire process such as decompresion are operating */
  77. void pkgAcquire::Item::Start(string /*Message*/,unsigned long Size)
  78. {
  79. Status = StatFetching;
  80. if (FileSize == 0 && Complete == false)
  81. FileSize = Size;
  82. }
  83. /*}}}*/
  84. // Acquire::Item::Done - Item downloaded OK /*{{{*/
  85. // ---------------------------------------------------------------------
  86. /* */
  87. void pkgAcquire::Item::Done(string Message,unsigned long Size,string,
  88. pkgAcquire::MethodConfig *Cnf)
  89. {
  90. // We just downloaded something..
  91. string FileName = LookupTag(Message,"Filename");
  92. if (Complete == false && FileName == DestFile)
  93. {
  94. if (Owner->Log != 0)
  95. Owner->Log->Fetched(Size,atoi(LookupTag(Message,"Resume-Point","0").c_str()));
  96. }
  97. if (FileSize == 0)
  98. FileSize= Size;
  99. Status = StatDone;
  100. ErrorText = string();
  101. Owner->Dequeue(this);
  102. }
  103. /*}}}*/
  104. // Acquire::Item::Rename - Rename a file /*{{{*/
  105. // ---------------------------------------------------------------------
  106. /* This helper function is used by alot of item methods as thier final
  107. step */
  108. void pkgAcquire::Item::Rename(string From,string To)
  109. {
  110. if (rename(From.c_str(),To.c_str()) != 0)
  111. {
  112. char S[300];
  113. sprintf(S,_("rename failed, %s (%s -> %s)."),strerror(errno),
  114. From.c_str(),To.c_str());
  115. Status = StatError;
  116. ErrorText = S;
  117. }
  118. }
  119. /*}}}*/
  120. // AcqIndex::AcqIndex - Constructor /*{{{*/
  121. // ---------------------------------------------------------------------
  122. /* The package file is added to the queue and a second class is
  123. instantiated to fetch the revision file */
  124. pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,
  125. string URI,string URIDesc,string ShortDesc) :
  126. Item(Owner), RealURI(URI)
  127. {
  128. Decompression = false;
  129. Erase = false;
  130. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  131. DestFile += URItoFileName(URI);
  132. // Create the item
  133. Desc.URI = URI + ".gz";
  134. Desc.Description = URIDesc;
  135. Desc.Owner = this;
  136. Desc.ShortDesc = ShortDesc;
  137. QueueURI(Desc);
  138. }
  139. /*}}}*/
  140. // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
  141. // ---------------------------------------------------------------------
  142. /* The only header we use is the last-modified header. */
  143. string pkgAcqIndex::Custom600Headers()
  144. {
  145. string Final = _config->FindDir("Dir::State::lists");
  146. Final += URItoFileName(RealURI);
  147. struct stat Buf;
  148. if (stat(Final.c_str(),&Buf) != 0)
  149. return "\nIndex-File: true";
  150. return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  151. }
  152. /*}}}*/
  153. // AcqIndex::Done - Finished a fetch /*{{{*/
  154. // ---------------------------------------------------------------------
  155. /* This goes through a number of states.. On the initial fetch the
  156. method could possibly return an alternate filename which points
  157. to the uncompressed version of the file. If this is so the file
  158. is copied into the partial directory. In all other cases the file
  159. is decompressed with a gzip uri. */
  160. void pkgAcqIndex::Done(string Message,unsigned long Size,string MD5,
  161. pkgAcquire::MethodConfig *Cfg)
  162. {
  163. Item::Done(Message,Size,MD5,Cfg);
  164. if (Decompression == true)
  165. {
  166. // Done, move it into position
  167. string FinalFile = _config->FindDir("Dir::State::lists");
  168. FinalFile += URItoFileName(RealURI);
  169. Rename(DestFile,FinalFile);
  170. /* We restore the original name to DestFile so that the clean operation
  171. will work OK */
  172. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  173. DestFile += URItoFileName(RealURI);
  174. // Remove the compressed version.
  175. if (Erase == true)
  176. unlink(DestFile.c_str());
  177. return;
  178. }
  179. Erase = false;
  180. Complete = true;
  181. // Handle the unzipd case
  182. string FileName = LookupTag(Message,"Alt-Filename");
  183. if (FileName.empty() == false)
  184. {
  185. // The files timestamp matches
  186. if (StringToBool(LookupTag(Message,"Alt-IMS-Hit"),false) == true)
  187. return;
  188. Decompression = true;
  189. Local = true;
  190. DestFile += ".decomp";
  191. Desc.URI = "copy:" + FileName;
  192. QueueURI(Desc);
  193. Mode = "copy";
  194. return;
  195. }
  196. FileName = LookupTag(Message,"Filename");
  197. if (FileName.empty() == true)
  198. {
  199. Status = StatError;
  200. ErrorText = "Method gave a blank filename";
  201. }
  202. // The files timestamp matches
  203. if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
  204. return;
  205. if (FileName == DestFile)
  206. Erase = true;
  207. else
  208. Local = true;
  209. Decompression = true;
  210. DestFile += ".decomp";
  211. Desc.URI = "gzip:" + FileName;
  212. QueueURI(Desc);
  213. Mode = "gzip";
  214. }
  215. /*}}}*/
  216. // AcqIndexRel::pkgAcqIndexRel - Constructor /*{{{*/
  217. // ---------------------------------------------------------------------
  218. /* The Release file is added to the queue */
  219. pkgAcqIndexRel::pkgAcqIndexRel(pkgAcquire *Owner,
  220. string URI,string URIDesc,string ShortDesc) :
  221. Item(Owner), RealURI(URI)
  222. {
  223. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  224. DestFile += URItoFileName(URI);
  225. // Create the item
  226. Desc.URI = URI;
  227. Desc.Description = URIDesc;
  228. Desc.ShortDesc = ShortDesc;
  229. Desc.Owner = this;
  230. QueueURI(Desc);
  231. }
  232. /*}}}*/
  233. // AcqIndexRel::Custom600Headers - Insert custom request headers /*{{{*/
  234. // ---------------------------------------------------------------------
  235. /* The only header we use is the last-modified header. */
  236. string pkgAcqIndexRel::Custom600Headers()
  237. {
  238. string Final = _config->FindDir("Dir::State::lists");
  239. Final += URItoFileName(RealURI);
  240. struct stat Buf;
  241. if (stat(Final.c_str(),&Buf) != 0)
  242. return "\nIndex-File: true";
  243. return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  244. }
  245. /*}}}*/
  246. // AcqIndexRel::Done - Item downloaded OK /*{{{*/
  247. // ---------------------------------------------------------------------
  248. /* The release file was not placed into the download directory then
  249. a copy URI is generated and it is copied there otherwise the file
  250. in the partial directory is moved into .. and the URI is finished. */
  251. void pkgAcqIndexRel::Done(string Message,unsigned long Size,string MD5,
  252. pkgAcquire::MethodConfig *Cfg)
  253. {
  254. Item::Done(Message,Size,MD5,Cfg);
  255. string FileName = LookupTag(Message,"Filename");
  256. if (FileName.empty() == true)
  257. {
  258. Status = StatError;
  259. ErrorText = "Method gave a blank filename";
  260. return;
  261. }
  262. Complete = true;
  263. // The files timestamp matches
  264. if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
  265. return;
  266. // We have to copy it into place
  267. if (FileName != DestFile)
  268. {
  269. Local = true;
  270. Desc.URI = "copy:" + FileName;
  271. QueueURI(Desc);
  272. return;
  273. }
  274. // Done, move it into position
  275. string FinalFile = _config->FindDir("Dir::State::lists");
  276. FinalFile += URItoFileName(RealURI);
  277. Rename(DestFile,FinalFile);
  278. }
  279. /*}}}*/
  280. // AcqIndexRel::Failed - Silence failure messages for missing rel files /*{{{*/
  281. // ---------------------------------------------------------------------
  282. /* */
  283. void pkgAcqIndexRel::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
  284. {
  285. if (Cnf->LocalOnly == true ||
  286. StringToBool(LookupTag(Message,"Transient-Failure"),false) == false)
  287. {
  288. // Ignore this
  289. Status = StatDone;
  290. Complete = false;
  291. Dequeue();
  292. return;
  293. }
  294. Item::Failed(Message,Cnf);
  295. }
  296. /*}}}*/
  297. // AcqArchive::AcqArchive - Constructor /*{{{*/
  298. // ---------------------------------------------------------------------
  299. /* This just sets up the initial fetch environment and queues the first
  300. possibilitiy */
  301. pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
  302. pkgRecords *Recs,pkgCache::VerIterator const &Version,
  303. string &StoreFilename) :
  304. Item(Owner), Version(Version), Sources(Sources), Recs(Recs),
  305. StoreFilename(StoreFilename), Vf(Version.FileList())
  306. {
  307. Retries = _config->FindI("Acquire::Retries",0);
  308. if (Version.Arch() == 0)
  309. {
  310. _error->Error(_("I wasn't able to locate file for the %s package. "
  311. "This might mean you need to manually fix this package. (due to missing arch)"),
  312. Version.ParentPkg().Name());
  313. return;
  314. }
  315. /* We need to find a filename to determine the extension. We make the
  316. assumption here that all the available sources for this version share
  317. the same extension.. */
  318. // Skip not source sources, they do not have file fields.
  319. for (; Vf.end() == false; Vf++)
  320. {
  321. if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0)
  322. continue;
  323. break;
  324. }
  325. // Does not really matter here.. we are going to fail out below
  326. if (Vf.end() != true)
  327. {
  328. // If this fails to get a file name we will bomb out below.
  329. pkgRecords::Parser &Parse = Recs->Lookup(Vf);
  330. if (_error->PendingError() == true)
  331. return;
  332. // Generate the final file name as: package_version_arch.foo
  333. StoreFilename = QuoteString(Version.ParentPkg().Name(),"_:") + '_' +
  334. QuoteString(Version.VerStr(),"_:") + '_' +
  335. QuoteString(Version.Arch(),"_:.") +
  336. "." + flExtension(Parse.FileName());
  337. }
  338. // Select a source
  339. if (QueueNext() == false && _error->PendingError() == false)
  340. _error->Error(_("I wasn't able to locate file for the %s package. "
  341. "This might mean you need to manually fix this package."),
  342. Version.ParentPkg().Name());
  343. }
  344. /*}}}*/
  345. // AcqArchive::QueueNext - Queue the next file source /*{{{*/
  346. // ---------------------------------------------------------------------
  347. /* This queues the next available file version for download. It checks if
  348. the archive is already available in the cache and stashs the MD5 for
  349. checking later. */
  350. bool pkgAcqArchive::QueueNext()
  351. {
  352. for (; Vf.end() == false; Vf++)
  353. {
  354. // Ignore not source sources
  355. if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0)
  356. continue;
  357. // Try to cross match against the source list
  358. pkgIndexFile *Index;
  359. if (Sources->FindIndex(Vf.File(),Index) == false)
  360. continue;
  361. // Grab the text package record
  362. pkgRecords::Parser &Parse = Recs->Lookup(Vf);
  363. if (_error->PendingError() == true)
  364. return false;
  365. string PkgFile = Parse.FileName();
  366. MD5 = Parse.MD5Hash();
  367. if (PkgFile.empty() == true)
  368. return _error->Error(_("The package index files are corrupted. No Filename: "
  369. "field for package %s."),
  370. Version.ParentPkg().Name());
  371. // See if we already have the file. (Legacy filenames)
  372. FileSize = Version->Size;
  373. string FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile);
  374. struct stat Buf;
  375. if (stat(FinalFile.c_str(),&Buf) == 0)
  376. {
  377. // Make sure the size matches
  378. if ((unsigned)Buf.st_size == Version->Size)
  379. {
  380. Complete = true;
  381. Local = true;
  382. Status = StatDone;
  383. StoreFilename = DestFile = FinalFile;
  384. return true;
  385. }
  386. /* Hmm, we have a file and its size does not match, this means it is
  387. an old style mismatched arch */
  388. unlink(FinalFile.c_str());
  389. }
  390. // Check it again using the new style output filenames
  391. FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename);
  392. if (stat(FinalFile.c_str(),&Buf) == 0)
  393. {
  394. // Make sure the size matches
  395. if ((unsigned)Buf.st_size == Version->Size)
  396. {
  397. Complete = true;
  398. Local = true;
  399. Status = StatDone;
  400. StoreFilename = DestFile = FinalFile;
  401. return true;
  402. }
  403. /* Hmm, we have a file and its size does not match, this shouldnt
  404. happen.. */
  405. unlink(FinalFile.c_str());
  406. }
  407. DestFile = _config->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(StoreFilename);
  408. // Check the destination file
  409. if (stat(DestFile.c_str(),&Buf) == 0)
  410. {
  411. // Hmm, the partial file is too big, erase it
  412. if ((unsigned)Buf.st_size > Version->Size)
  413. unlink(DestFile.c_str());
  414. else
  415. PartialSize = Buf.st_size;
  416. }
  417. // Create the item
  418. Local = false;
  419. Desc.URI = Index->ArchiveURI(PkgFile);
  420. Desc.Description = Index->ArchiveInfo(Version);
  421. Desc.Owner = this;
  422. Desc.ShortDesc = Version.ParentPkg().Name();
  423. QueueURI(Desc);
  424. Vf++;
  425. return true;
  426. }
  427. return false;
  428. }
  429. /*}}}*/
  430. // AcqArchive::Done - Finished fetching /*{{{*/
  431. // ---------------------------------------------------------------------
  432. /* */
  433. void pkgAcqArchive::Done(string Message,unsigned long Size,string Md5Hash,
  434. pkgAcquire::MethodConfig *Cfg)
  435. {
  436. Item::Done(Message,Size,Md5Hash,Cfg);
  437. // Check the size
  438. if (Size != Version->Size)
  439. {
  440. Status = StatError;
  441. ErrorText = _("Size mismatch");
  442. return;
  443. }
  444. // Check the md5
  445. if (Md5Hash.empty() == false && MD5.empty() == false)
  446. {
  447. if (Md5Hash != MD5)
  448. {
  449. Status = StatError;
  450. ErrorText = _("MD5Sum mismatch");
  451. Rename(DestFile,DestFile + ".FAILED");
  452. return;
  453. }
  454. }
  455. // Grab the output filename
  456. string FileName = LookupTag(Message,"Filename");
  457. if (FileName.empty() == true)
  458. {
  459. Status = StatError;
  460. ErrorText = "Method gave a blank filename";
  461. return;
  462. }
  463. Complete = true;
  464. // Reference filename
  465. if (FileName != DestFile)
  466. {
  467. StoreFilename = DestFile = FileName;
  468. Local = true;
  469. return;
  470. }
  471. // Done, move it into position
  472. string FinalFile = _config->FindDir("Dir::Cache::Archives");
  473. FinalFile += flNotDir(StoreFilename);
  474. Rename(DestFile,FinalFile);
  475. StoreFilename = DestFile = FinalFile;
  476. Complete = true;
  477. }
  478. /*}}}*/
  479. // AcqArchive::Failed - Failure handler /*{{{*/
  480. // ---------------------------------------------------------------------
  481. /* Here we try other sources */
  482. void pkgAcqArchive::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
  483. {
  484. ErrorText = LookupTag(Message,"Message");
  485. /* We don't really want to retry on failed media swaps, this prevents
  486. that. An interesting observation is that permanent failures are not
  487. recorded. */
  488. if (Cnf->Removable == true &&
  489. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  490. {
  491. // Vf = Version.FileList();
  492. while (Vf.end() == false) Vf++;
  493. StoreFilename = string();
  494. Item::Failed(Message,Cnf);
  495. return;
  496. }
  497. if (QueueNext() == false)
  498. {
  499. // This is the retry counter
  500. if (Retries != 0 &&
  501. Cnf->LocalOnly == false &&
  502. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  503. {
  504. Retries--;
  505. Vf = Version.FileList();
  506. if (QueueNext() == true)
  507. return;
  508. }
  509. StoreFilename = string();
  510. Item::Failed(Message,Cnf);
  511. }
  512. }
  513. /*}}}*/
  514. // AcqArchive::Finished - Fetching has finished, tidy up /*{{{*/
  515. // ---------------------------------------------------------------------
  516. /* */
  517. void pkgAcqArchive::Finished()
  518. {
  519. if (Status == pkgAcquire::Item::StatDone &&
  520. Complete == true)
  521. return;
  522. StoreFilename = string();
  523. }
  524. /*}}}*/
  525. // AcqFile::pkgAcqFile - Constructor /*{{{*/
  526. // ---------------------------------------------------------------------
  527. /* The file is added to the queue */
  528. pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,
  529. unsigned long Size,string Dsc,string ShortDesc) :
  530. Item(Owner), Md5Hash(MD5)
  531. {
  532. Retries = _config->FindI("Acquire::Retries",0);
  533. DestFile = flNotDir(URI);
  534. // Create the item
  535. Desc.URI = URI;
  536. Desc.Description = Dsc;
  537. Desc.Owner = this;
  538. // Set the short description to the archive component
  539. Desc.ShortDesc = ShortDesc;
  540. // Get the transfer sizes
  541. FileSize = Size;
  542. struct stat Buf;
  543. if (stat(DestFile.c_str(),&Buf) == 0)
  544. {
  545. // Hmm, the partial file is too big, erase it
  546. if ((unsigned)Buf.st_size > Size)
  547. unlink(DestFile.c_str());
  548. else
  549. PartialSize = Buf.st_size;
  550. }
  551. QueueURI(Desc);
  552. }
  553. /*}}}*/
  554. // AcqFile::Done - Item downloaded OK /*{{{*/
  555. // ---------------------------------------------------------------------
  556. /* */
  557. void pkgAcqFile::Done(string Message,unsigned long Size,string MD5,
  558. pkgAcquire::MethodConfig *Cnf)
  559. {
  560. // Check the md5
  561. if (Md5Hash.empty() == false && MD5.empty() == false)
  562. {
  563. if (Md5Hash != MD5)
  564. {
  565. Status = StatError;
  566. ErrorText = "MD5Sum mismatch";
  567. Rename(DestFile,DestFile + ".FAILED");
  568. return;
  569. }
  570. }
  571. Item::Done(Message,Size,MD5,Cnf);
  572. string FileName = LookupTag(Message,"Filename");
  573. if (FileName.empty() == true)
  574. {
  575. Status = StatError;
  576. ErrorText = "Method gave a blank filename";
  577. return;
  578. }
  579. Complete = true;
  580. // The files timestamp matches
  581. if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
  582. return;
  583. // We have to copy it into place
  584. if (FileName != DestFile)
  585. {
  586. Local = true;
  587. if (_config->FindB("Acquire::Source-Symlinks",true) == false ||
  588. Cnf->Removable == true)
  589. {
  590. Desc.URI = "copy:" + FileName;
  591. QueueURI(Desc);
  592. return;
  593. }
  594. // Erase the file if it is a symlink so we can overwrite it
  595. struct stat St;
  596. if (lstat(DestFile.c_str(),&St) == 0)
  597. {
  598. if (S_ISLNK(St.st_mode) != 0)
  599. unlink(DestFile.c_str());
  600. }
  601. // Symlink the file
  602. if (symlink(FileName.c_str(),DestFile.c_str()) != 0)
  603. {
  604. ErrorText = "Link to " + DestFile + " failure ";
  605. Status = StatError;
  606. Complete = false;
  607. }
  608. }
  609. }
  610. /*}}}*/
  611. // AcqFile::Failed - Failure handler /*{{{*/
  612. // ---------------------------------------------------------------------
  613. /* Here we try other sources */
  614. void pkgAcqFile::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
  615. {
  616. ErrorText = LookupTag(Message,"Message");
  617. // This is the retry counter
  618. if (Retries != 0 &&
  619. Cnf->LocalOnly == false &&
  620. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  621. {
  622. Retries--;
  623. QueueURI(Desc);
  624. return;
  625. }
  626. Item::Failed(Message,Cnf);
  627. }
  628. /*}}}*/