acquire-item.cc 21 KB

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