acquire-item.cc 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359
  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/sha1.h>
  22. #include <apt-pkg/tagfile.h>
  23. #include <apt-pkg/indexrecords.h>
  24. #include <apt-pkg/acquire.h>
  25. #include <apt-pkg/hashes.h>
  26. #include <apt-pkg/indexfile.h>
  27. #include <apt-pkg/pkgcache.h>
  28. #include <apt-pkg/cacheiterators.h>
  29. #include <apt-pkg/pkgrecords.h>
  30. #include <stddef.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <iostream>
  34. #include <vector>
  35. #include <sys/stat.h>
  36. #include <unistd.h>
  37. #include <errno.h>
  38. #include <string>
  39. #include <sstream>
  40. #include <stdio.h>
  41. #include <ctime>
  42. #include <apti18n.h>
  43. /*}}}*/
  44. using namespace std;
  45. // Acquire::Item::Item - Constructor /*{{{*/
  46. // ---------------------------------------------------------------------
  47. /* */
  48. pkgAcquire::Item::Item(pkgAcquire *Owner) : Owner(Owner), FileSize(0),
  49. PartialSize(0), Mode(0), ID(0), Complete(false),
  50. Local(false), QueueCounter(0),
  51. ExpectedAdditionalItems(0)
  52. {
  53. Owner->Add(this);
  54. Status = StatIdle;
  55. }
  56. /*}}}*/
  57. // Acquire::Item::~Item - Destructor /*{{{*/
  58. // ---------------------------------------------------------------------
  59. /* */
  60. pkgAcquire::Item::~Item()
  61. {
  62. Owner->Remove(this);
  63. }
  64. /*}}}*/
  65. // Acquire::Item::Failed - Item failed to download /*{{{*/
  66. // ---------------------------------------------------------------------
  67. /* We return to an idle state if there are still other queues that could
  68. fetch this object */
  69. void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
  70. {
  71. Status = StatIdle;
  72. ErrorText = LookupTag(Message,"Message");
  73. UsedMirror = LookupTag(Message,"UsedMirror");
  74. if (QueueCounter <= 1)
  75. {
  76. /* This indicates that the file is not available right now but might
  77. be sometime later. If we do a retry cycle then this should be
  78. retried [CDROMs] */
  79. if (Cnf->LocalOnly == true &&
  80. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  81. {
  82. Status = StatIdle;
  83. Dequeue();
  84. return;
  85. }
  86. Status = StatError;
  87. Dequeue();
  88. }
  89. // report mirror failure back to LP if we actually use a mirror
  90. string FailReason = LookupTag(Message, "FailReason");
  91. if(FailReason.size() != 0)
  92. ReportMirrorFailure(FailReason);
  93. else
  94. ReportMirrorFailure(ErrorText);
  95. }
  96. /*}}}*/
  97. // Acquire::Item::Start - Item has begun to download /*{{{*/
  98. // ---------------------------------------------------------------------
  99. /* Stash status and the file size. Note that setting Complete means
  100. sub-phases of the acquire process such as decompresion are operating */
  101. void pkgAcquire::Item::Start(string /*Message*/,unsigned long long Size)
  102. {
  103. Status = StatFetching;
  104. if (FileSize == 0 && Complete == false)
  105. FileSize = Size;
  106. }
  107. /*}}}*/
  108. // Acquire::Item::Done - Item downloaded OK /*{{{*/
  109. // ---------------------------------------------------------------------
  110. /* */
  111. void pkgAcquire::Item::Done(string Message,unsigned long long Size,string /*Hash*/,
  112. pkgAcquire::MethodConfig * /*Cnf*/)
  113. {
  114. // We just downloaded something..
  115. string FileName = LookupTag(Message,"Filename");
  116. UsedMirror = LookupTag(Message,"UsedMirror");
  117. if (Complete == false && !Local && FileName == DestFile)
  118. {
  119. if (Owner->Log != 0)
  120. Owner->Log->Fetched(Size,atoi(LookupTag(Message,"Resume-Point","0").c_str()));
  121. }
  122. if (FileSize == 0)
  123. FileSize= Size;
  124. Status = StatDone;
  125. ErrorText = string();
  126. Owner->Dequeue(this);
  127. }
  128. /*}}}*/
  129. // Acquire::Item::Rename - Rename a file /*{{{*/
  130. // ---------------------------------------------------------------------
  131. /* This helper function is used by a lot of item methods as their final
  132. step */
  133. void pkgAcquire::Item::Rename(string From,string To)
  134. {
  135. if (rename(From.c_str(),To.c_str()) != 0)
  136. {
  137. char S[300];
  138. snprintf(S,sizeof(S),_("rename failed, %s (%s -> %s)."),strerror(errno),
  139. From.c_str(),To.c_str());
  140. Status = StatError;
  141. ErrorText = S;
  142. }
  143. }
  144. /*}}}*/
  145. bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState const error)/*{{{*/
  146. {
  147. if(FileExists(DestFile))
  148. Rename(DestFile, DestFile + ".FAILED");
  149. switch (error)
  150. {
  151. case HashSumMismatch:
  152. ErrorText = _("Hash Sum mismatch");
  153. Status = StatAuthError;
  154. ReportMirrorFailure("HashChecksumFailure");
  155. break;
  156. case SizeMismatch:
  157. ErrorText = _("Size mismatch");
  158. Status = StatAuthError;
  159. ReportMirrorFailure("SizeFailure");
  160. break;
  161. case InvalidFormat:
  162. ErrorText = _("Invalid file format");
  163. Status = StatError;
  164. // do not report as usually its not the mirrors fault, but Portal/Proxy
  165. break;
  166. }
  167. return false;
  168. }
  169. /*}}}*/
  170. // Acquire::Item::ReportMirrorFailure /*{{{*/
  171. // ---------------------------------------------------------------------
  172. void pkgAcquire::Item::ReportMirrorFailure(string FailCode)
  173. {
  174. // we only act if a mirror was used at all
  175. if(UsedMirror.empty())
  176. return;
  177. #if 0
  178. std::cerr << "\nReportMirrorFailure: "
  179. << UsedMirror
  180. << " Uri: " << DescURI()
  181. << " FailCode: "
  182. << FailCode << std::endl;
  183. #endif
  184. const char *Args[40];
  185. unsigned int i = 0;
  186. string report = _config->Find("Methods::Mirror::ProblemReporting",
  187. "/usr/lib/apt/apt-report-mirror-failure");
  188. if(!FileExists(report))
  189. return;
  190. Args[i++] = report.c_str();
  191. Args[i++] = UsedMirror.c_str();
  192. Args[i++] = DescURI().c_str();
  193. Args[i++] = FailCode.c_str();
  194. Args[i++] = NULL;
  195. pid_t pid = ExecFork();
  196. if(pid < 0)
  197. {
  198. _error->Error("ReportMirrorFailure Fork failed");
  199. return;
  200. }
  201. else if(pid == 0)
  202. {
  203. execvp(Args[0], (char**)Args);
  204. std::cerr << "Could not exec " << Args[0] << std::endl;
  205. _exit(100);
  206. }
  207. if(!ExecWait(pid, "report-mirror-failure"))
  208. {
  209. _error->Warning("Couldn't report problem to '%s'",
  210. _config->Find("Methods::Mirror::ProblemReporting").c_str());
  211. }
  212. }
  213. /*}}}*/
  214. // AcqSubIndex::AcqSubIndex - Constructor /*{{{*/
  215. // ---------------------------------------------------------------------
  216. /* Get a sub-index file based on checksums from a 'master' file and
  217. possibly query additional files */
  218. pkgAcqSubIndex::pkgAcqSubIndex(pkgAcquire *Owner, string const &URI,
  219. string const &URIDesc, string const &ShortDesc,
  220. HashString const &ExpectedHash)
  221. : Item(Owner), ExpectedHash(ExpectedHash)
  222. {
  223. /* XXX: Beware: Currently this class does nothing (of value) anymore ! */
  224. Debug = _config->FindB("Debug::pkgAcquire::SubIndex",false);
  225. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  226. DestFile += URItoFileName(URI);
  227. Desc.URI = URI;
  228. Desc.Description = URIDesc;
  229. Desc.Owner = this;
  230. Desc.ShortDesc = ShortDesc;
  231. QueueURI(Desc);
  232. if(Debug)
  233. std::clog << "pkgAcqSubIndex: " << Desc.URI << std::endl;
  234. }
  235. /*}}}*/
  236. // AcqSubIndex::Custom600Headers - Insert custom request headers /*{{{*/
  237. // ---------------------------------------------------------------------
  238. /* The only header we use is the last-modified header. */
  239. string pkgAcqSubIndex::Custom600Headers()
  240. {
  241. string Final = _config->FindDir("Dir::State::lists");
  242. Final += URItoFileName(Desc.URI);
  243. struct stat Buf;
  244. if (stat(Final.c_str(),&Buf) != 0)
  245. return "\nIndex-File: true\nFail-Ignore: true\n";
  246. return "\nIndex-File: true\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  247. }
  248. /*}}}*/
  249. void pkgAcqSubIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)/*{{{*/
  250. {
  251. if(Debug)
  252. std::clog << "pkgAcqSubIndex failed: " << Desc.URI << " with " << Message << std::endl;
  253. Complete = false;
  254. Status = StatDone;
  255. Dequeue();
  256. // No good Index is provided
  257. }
  258. /*}}}*/
  259. void pkgAcqSubIndex::Done(string Message,unsigned long long Size,string Md5Hash, /*{{{*/
  260. pkgAcquire::MethodConfig *Cnf)
  261. {
  262. if(Debug)
  263. std::clog << "pkgAcqSubIndex::Done(): " << Desc.URI << std::endl;
  264. string FileName = LookupTag(Message,"Filename");
  265. if (FileName.empty() == true)
  266. {
  267. Status = StatError;
  268. ErrorText = "Method gave a blank filename";
  269. return;
  270. }
  271. if (FileName != DestFile)
  272. {
  273. Local = true;
  274. Desc.URI = "copy:" + FileName;
  275. QueueURI(Desc);
  276. return;
  277. }
  278. Item::Done(Message,Size,Md5Hash,Cnf);
  279. string FinalFile = _config->FindDir("Dir::State::lists")+URItoFileName(Desc.URI);
  280. /* Downloaded invalid transindex => Error (LP: #346386) (Closes: #627642) */
  281. indexRecords SubIndexParser;
  282. if (FileExists(DestFile) == true && !SubIndexParser.Load(DestFile)) {
  283. Status = StatError;
  284. ErrorText = SubIndexParser.ErrorText;
  285. return;
  286. }
  287. // success in downloading the index
  288. // rename the index
  289. if(Debug)
  290. std::clog << "Renaming: " << DestFile << " -> " << FinalFile << std::endl;
  291. Rename(DestFile,FinalFile);
  292. chmod(FinalFile.c_str(),0644);
  293. DestFile = FinalFile;
  294. if(ParseIndex(DestFile) == false)
  295. return Failed("", NULL);
  296. Complete = true;
  297. Status = StatDone;
  298. Dequeue();
  299. return;
  300. }
  301. /*}}}*/
  302. bool pkgAcqSubIndex::ParseIndex(string const &IndexFile) /*{{{*/
  303. {
  304. indexRecords SubIndexParser;
  305. if (FileExists(IndexFile) == false || SubIndexParser.Load(IndexFile) == false)
  306. return false;
  307. // so something with the downloaded index
  308. return true;
  309. }
  310. /*}}}*/
  311. // AcqDiffIndex::AcqDiffIndex - Constructor /*{{{*/
  312. // ---------------------------------------------------------------------
  313. /* Get the DiffIndex file first and see if there are patches available
  314. * If so, create a pkgAcqIndexDiffs fetcher that will get and apply the
  315. * patches. If anything goes wrong in that process, it will fall back to
  316. * the original packages file
  317. */
  318. pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire *Owner,
  319. IndexTarget const *Target,
  320. HashString ExpectedHash,
  321. indexRecords *MetaIndexParser)
  322. : Item(Owner), ExpectedHash(ExpectedHash), Target(Target),
  323. MetaIndexParser(MetaIndexParser)
  324. {
  325. Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
  326. RealURI = Target->URI;
  327. Desc.Owner = this;
  328. Desc.Description = Target->Description + "/DiffIndex";
  329. Desc.ShortDesc = Target->ShortDesc;
  330. Desc.URI = Target->URI + ".diff/Index";
  331. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  332. DestFile += URItoFileName(Target->URI) + string(".DiffIndex");
  333. if(Debug)
  334. std::clog << "pkgAcqDiffIndex: " << Desc.URI << std::endl;
  335. // look for the current package file
  336. CurrentPackagesFile = _config->FindDir("Dir::State::lists");
  337. CurrentPackagesFile += URItoFileName(RealURI);
  338. // FIXME: this file:/ check is a hack to prevent fetching
  339. // from local sources. this is really silly, and
  340. // should be fixed cleanly as soon as possible
  341. if(!FileExists(CurrentPackagesFile) ||
  342. Desc.URI.substr(0,strlen("file:/")) == "file:/")
  343. {
  344. // we don't have a pkg file or we don't want to queue
  345. if(Debug)
  346. std::clog << "No index file, local or canceld by user" << std::endl;
  347. Failed("", NULL);
  348. return;
  349. }
  350. if(Debug)
  351. std::clog << "pkgAcqDiffIndex::pkgAcqDiffIndex(): "
  352. << CurrentPackagesFile << std::endl;
  353. QueueURI(Desc);
  354. }
  355. /*}}}*/
  356. // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
  357. // ---------------------------------------------------------------------
  358. /* The only header we use is the last-modified header. */
  359. string pkgAcqDiffIndex::Custom600Headers()
  360. {
  361. string Final = _config->FindDir("Dir::State::lists");
  362. Final += URItoFileName(RealURI) + string(".IndexDiff");
  363. if(Debug)
  364. std::clog << "Custom600Header-IMS: " << Final << std::endl;
  365. struct stat Buf;
  366. if (stat(Final.c_str(),&Buf) != 0)
  367. return "\nIndex-File: true";
  368. return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  369. }
  370. /*}}}*/
  371. bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile) /*{{{*/
  372. {
  373. if(Debug)
  374. std::clog << "pkgAcqDiffIndex::ParseIndexDiff() " << IndexDiffFile
  375. << std::endl;
  376. pkgTagSection Tags;
  377. string ServerSha1;
  378. vector<DiffInfo> available_patches;
  379. FileFd Fd(IndexDiffFile,FileFd::ReadOnly);
  380. pkgTagFile TF(&Fd);
  381. if (_error->PendingError() == true)
  382. return false;
  383. if(TF.Step(Tags) == true)
  384. {
  385. bool found = false;
  386. DiffInfo d;
  387. string size;
  388. string const tmp = Tags.FindS("SHA1-Current");
  389. std::stringstream ss(tmp);
  390. ss >> ServerSha1 >> size;
  391. unsigned long const ServerSize = atol(size.c_str());
  392. FileFd fd(CurrentPackagesFile, FileFd::ReadOnly);
  393. SHA1Summation SHA1;
  394. SHA1.AddFD(fd);
  395. string const local_sha1 = SHA1.Result();
  396. if(local_sha1 == ServerSha1)
  397. {
  398. // we have the same sha1 as the server so we are done here
  399. if(Debug)
  400. std::clog << "Package file is up-to-date" << std::endl;
  401. // list cleanup needs to know that this file as well as the already
  402. // present index is ours, so we create an empty diff to save it for us
  403. new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc,
  404. ExpectedHash, ServerSha1, available_patches);
  405. return true;
  406. }
  407. else
  408. {
  409. if(Debug)
  410. std::clog << "SHA1-Current: " << ServerSha1 << " and we start at "<< fd.Name() << " " << fd.Size() << " " << local_sha1 << std::endl;
  411. // check the historie and see what patches we need
  412. string const history = Tags.FindS("SHA1-History");
  413. std::stringstream hist(history);
  414. while(hist >> d.sha1 >> size >> d.file)
  415. {
  416. // read until the first match is found
  417. // from that point on, we probably need all diffs
  418. if(d.sha1 == local_sha1)
  419. found=true;
  420. else if (found == false)
  421. continue;
  422. if(Debug)
  423. std::clog << "Need to get diff: " << d.file << std::endl;
  424. available_patches.push_back(d);
  425. }
  426. if (available_patches.empty() == false)
  427. {
  428. // patching with too many files is rather slow compared to a fast download
  429. unsigned long const fileLimit = _config->FindI("Acquire::PDiffs::FileLimit", 0);
  430. if (fileLimit != 0 && fileLimit < available_patches.size())
  431. {
  432. if (Debug)
  433. std::clog << "Need " << available_patches.size() << " diffs (Limit is " << fileLimit
  434. << ") so fallback to complete download" << std::endl;
  435. return false;
  436. }
  437. // see if the patches are too big
  438. found = false; // it was true and it will be true again at the end
  439. d = *available_patches.begin();
  440. string const firstPatch = d.file;
  441. unsigned long patchesSize = 0;
  442. std::stringstream patches(Tags.FindS("SHA1-Patches"));
  443. while(patches >> d.sha1 >> size >> d.file)
  444. {
  445. if (firstPatch == d.file)
  446. found = true;
  447. else if (found == false)
  448. continue;
  449. patchesSize += atol(size.c_str());
  450. }
  451. unsigned long const sizeLimit = ServerSize * _config->FindI("Acquire::PDiffs::SizeLimit", 100);
  452. if (sizeLimit > 0 && (sizeLimit/100) < patchesSize)
  453. {
  454. if (Debug)
  455. std::clog << "Need " << patchesSize << " bytes (Limit is " << sizeLimit/100
  456. << ") so fallback to complete download" << std::endl;
  457. return false;
  458. }
  459. }
  460. }
  461. // we have something, queue the next diff
  462. if(found)
  463. {
  464. // queue the diffs
  465. string::size_type const last_space = Description.rfind(" ");
  466. if(last_space != string::npos)
  467. Description.erase(last_space, Description.size()-last_space);
  468. /* decide if we should download patches one by one or in one go:
  469. The first is good if the server merges patches, but many don't so client
  470. based merging can be attempt in which case the second is better.
  471. "bad things" will happen if patches are merged on the server,
  472. but client side merging is attempt as well */
  473. bool pdiff_merge = _config->FindB("Acquire::PDiffs::Merge", true);
  474. if (pdiff_merge == true)
  475. {
  476. // reprepro adds this flag if it has merged patches on the server
  477. std::string const precedence = Tags.FindS("X-Patch-Precedence");
  478. pdiff_merge = (precedence != "merged");
  479. }
  480. if (pdiff_merge == false)
  481. new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc,
  482. ExpectedHash, ServerSha1, available_patches);
  483. else
  484. {
  485. std::vector<pkgAcqIndexMergeDiffs*> *diffs = new std::vector<pkgAcqIndexMergeDiffs*>(available_patches.size());
  486. for(size_t i = 0; i < available_patches.size(); ++i)
  487. (*diffs)[i] = new pkgAcqIndexMergeDiffs(Owner, RealURI, Description, Desc.ShortDesc, ExpectedHash,
  488. available_patches[i], diffs);
  489. }
  490. Complete = false;
  491. Status = StatDone;
  492. Dequeue();
  493. return true;
  494. }
  495. }
  496. // Nothing found, report and return false
  497. // Failing here is ok, if we return false later, the full
  498. // IndexFile is queued
  499. if(Debug)
  500. std::clog << "Can't find a patch in the index file" << std::endl;
  501. return false;
  502. }
  503. /*}}}*/
  504. void pkgAcqDiffIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)/*{{{*/
  505. {
  506. if(Debug)
  507. std::clog << "pkgAcqDiffIndex failed: " << Desc.URI << " with " << Message << std::endl
  508. << "Falling back to normal index file acquire" << std::endl;
  509. new pkgAcqIndex(Owner, Target, ExpectedHash, MetaIndexParser);
  510. Complete = false;
  511. Status = StatDone;
  512. Dequeue();
  513. }
  514. /*}}}*/
  515. void pkgAcqDiffIndex::Done(string Message,unsigned long long Size,string Md5Hash, /*{{{*/
  516. pkgAcquire::MethodConfig *Cnf)
  517. {
  518. if(Debug)
  519. std::clog << "pkgAcqDiffIndex::Done(): " << Desc.URI << std::endl;
  520. Item::Done(Message,Size,Md5Hash,Cnf);
  521. string FinalFile;
  522. FinalFile = _config->FindDir("Dir::State::lists")+URItoFileName(RealURI);
  523. // success in downloading the index
  524. // rename the index
  525. FinalFile += string(".IndexDiff");
  526. if(Debug)
  527. std::clog << "Renaming: " << DestFile << " -> " << FinalFile
  528. << std::endl;
  529. Rename(DestFile,FinalFile);
  530. chmod(FinalFile.c_str(),0644);
  531. DestFile = FinalFile;
  532. if(!ParseDiffIndex(DestFile))
  533. return Failed("", NULL);
  534. Complete = true;
  535. Status = StatDone;
  536. Dequeue();
  537. return;
  538. }
  539. /*}}}*/
  540. // AcqIndexDiffs::AcqIndexDiffs - Constructor /*{{{*/
  541. // ---------------------------------------------------------------------
  542. /* The package diff is added to the queue. one object is constructed
  543. * for each diff and the index
  544. */
  545. pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner,
  546. string URI,string URIDesc,string ShortDesc,
  547. HashString ExpectedHash,
  548. string ServerSha1,
  549. vector<DiffInfo> diffs)
  550. : Item(Owner), RealURI(URI), ExpectedHash(ExpectedHash),
  551. available_patches(diffs), ServerSha1(ServerSha1)
  552. {
  553. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  554. DestFile += URItoFileName(URI);
  555. Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
  556. Description = URIDesc;
  557. Desc.Owner = this;
  558. Desc.ShortDesc = ShortDesc;
  559. if(available_patches.empty() == true)
  560. {
  561. // we are done (yeah!)
  562. Finish(true);
  563. }
  564. else
  565. {
  566. // get the next diff
  567. State = StateFetchDiff;
  568. QueueNextDiff();
  569. }
  570. }
  571. /*}}}*/
  572. void pkgAcqIndexDiffs::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)/*{{{*/
  573. {
  574. if(Debug)
  575. std::clog << "pkgAcqIndexDiffs failed: " << Desc.URI << " with " << Message << std::endl
  576. << "Falling back to normal index file acquire" << std::endl;
  577. new pkgAcqIndex(Owner, RealURI, Description,Desc.ShortDesc,
  578. ExpectedHash);
  579. Finish();
  580. }
  581. /*}}}*/
  582. // Finish - helper that cleans the item out of the fetcher queue /*{{{*/
  583. void pkgAcqIndexDiffs::Finish(bool allDone)
  584. {
  585. // we restore the original name, this is required, otherwise
  586. // the file will be cleaned
  587. if(allDone)
  588. {
  589. DestFile = _config->FindDir("Dir::State::lists");
  590. DestFile += URItoFileName(RealURI);
  591. if(!ExpectedHash.empty() && !ExpectedHash.VerifyFile(DestFile))
  592. {
  593. RenameOnError(HashSumMismatch);
  594. Dequeue();
  595. return;
  596. }
  597. // this is for the "real" finish
  598. Complete = true;
  599. Status = StatDone;
  600. Dequeue();
  601. if(Debug)
  602. std::clog << "\n\nallDone: " << DestFile << "\n" << std::endl;
  603. return;
  604. }
  605. if(Debug)
  606. std::clog << "Finishing: " << Desc.URI << std::endl;
  607. Complete = false;
  608. Status = StatDone;
  609. Dequeue();
  610. return;
  611. }
  612. /*}}}*/
  613. bool pkgAcqIndexDiffs::QueueNextDiff() /*{{{*/
  614. {
  615. // calc sha1 of the just patched file
  616. string FinalFile = _config->FindDir("Dir::State::lists");
  617. FinalFile += URItoFileName(RealURI);
  618. FileFd fd(FinalFile, FileFd::ReadOnly);
  619. SHA1Summation SHA1;
  620. SHA1.AddFD(fd);
  621. string local_sha1 = string(SHA1.Result());
  622. if(Debug)
  623. std::clog << "QueueNextDiff: "
  624. << FinalFile << " (" << local_sha1 << ")"<<std::endl;
  625. // final file reached before all patches are applied
  626. if(local_sha1 == ServerSha1)
  627. {
  628. Finish(true);
  629. return true;
  630. }
  631. // remove all patches until the next matching patch is found
  632. // this requires the Index file to be ordered
  633. for(vector<DiffInfo>::iterator I=available_patches.begin();
  634. available_patches.empty() == false &&
  635. I != available_patches.end() &&
  636. I->sha1 != local_sha1;
  637. ++I)
  638. {
  639. available_patches.erase(I);
  640. }
  641. // error checking and falling back if no patch was found
  642. if(available_patches.empty() == true)
  643. {
  644. Failed("", NULL);
  645. return false;
  646. }
  647. // queue the right diff
  648. Desc.URI = RealURI + ".diff/" + available_patches[0].file + ".gz";
  649. Desc.Description = Description + " " + available_patches[0].file + string(".pdiff");
  650. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  651. DestFile += URItoFileName(RealURI + ".diff/" + available_patches[0].file);
  652. if(Debug)
  653. std::clog << "pkgAcqIndexDiffs::QueueNextDiff(): " << Desc.URI << std::endl;
  654. QueueURI(Desc);
  655. return true;
  656. }
  657. /*}}}*/
  658. void pkgAcqIndexDiffs::Done(string Message,unsigned long long Size,string Md5Hash, /*{{{*/
  659. pkgAcquire::MethodConfig *Cnf)
  660. {
  661. if(Debug)
  662. std::clog << "pkgAcqIndexDiffs::Done(): " << Desc.URI << std::endl;
  663. Item::Done(Message,Size,Md5Hash,Cnf);
  664. string FinalFile;
  665. FinalFile = _config->FindDir("Dir::State::lists")+URItoFileName(RealURI);
  666. // success in downloading a diff, enter ApplyDiff state
  667. if(State == StateFetchDiff)
  668. {
  669. // rred excepts the patch as $FinalFile.ed
  670. Rename(DestFile,FinalFile+".ed");
  671. if(Debug)
  672. std::clog << "Sending to rred method: " << FinalFile << std::endl;
  673. State = StateApplyDiff;
  674. Local = true;
  675. Desc.URI = "rred:" + FinalFile;
  676. QueueURI(Desc);
  677. Mode = "rred";
  678. return;
  679. }
  680. // success in download/apply a diff, queue next (if needed)
  681. if(State == StateApplyDiff)
  682. {
  683. // remove the just applied patch
  684. available_patches.erase(available_patches.begin());
  685. unlink((FinalFile + ".ed").c_str());
  686. // move into place
  687. if(Debug)
  688. {
  689. std::clog << "Moving patched file in place: " << std::endl
  690. << DestFile << " -> " << FinalFile << std::endl;
  691. }
  692. Rename(DestFile,FinalFile);
  693. chmod(FinalFile.c_str(),0644);
  694. // see if there is more to download
  695. if(available_patches.empty() == false) {
  696. new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc,
  697. ExpectedHash, ServerSha1, available_patches);
  698. return Finish();
  699. } else
  700. return Finish(true);
  701. }
  702. }
  703. /*}}}*/
  704. // AcqIndexMergeDiffs::AcqIndexMergeDiffs - Constructor /*{{{*/
  705. pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire *Owner,
  706. string const &URI, string const &URIDesc,
  707. string const &ShortDesc, HashString const &ExpectedHash,
  708. DiffInfo const &patch,
  709. std::vector<pkgAcqIndexMergeDiffs*> const * const allPatches)
  710. : Item(Owner), RealURI(URI), ExpectedHash(ExpectedHash),
  711. patch(patch),allPatches(allPatches), State(StateFetchDiff)
  712. {
  713. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  714. DestFile += URItoFileName(URI);
  715. Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
  716. Description = URIDesc;
  717. Desc.Owner = this;
  718. Desc.ShortDesc = ShortDesc;
  719. Desc.URI = RealURI + ".diff/" + patch.file + ".gz";
  720. Desc.Description = Description + " " + patch.file + string(".pdiff");
  721. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  722. DestFile += URItoFileName(RealURI + ".diff/" + patch.file);
  723. if(Debug)
  724. std::clog << "pkgAcqIndexMergeDiffs: " << Desc.URI << std::endl;
  725. QueueURI(Desc);
  726. }
  727. /*}}}*/
  728. void pkgAcqIndexMergeDiffs::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)/*{{{*/
  729. {
  730. if(Debug)
  731. std::clog << "pkgAcqIndexMergeDiffs failed: " << Desc.URI << " with " << Message << std::endl;
  732. Complete = false;
  733. Status = StatDone;
  734. Dequeue();
  735. // check if we are the first to fail, otherwise we are done here
  736. State = StateDoneDiff;
  737. for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
  738. I != allPatches->end(); ++I)
  739. if ((*I)->State == StateErrorDiff)
  740. return;
  741. // first failure means we should fallback
  742. State = StateErrorDiff;
  743. std::clog << "Falling back to normal index file acquire" << std::endl;
  744. new pkgAcqIndex(Owner, RealURI, Description,Desc.ShortDesc,
  745. ExpectedHash);
  746. }
  747. /*}}}*/
  748. void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,string Md5Hash, /*{{{*/
  749. pkgAcquire::MethodConfig *Cnf)
  750. {
  751. if(Debug)
  752. std::clog << "pkgAcqIndexMergeDiffs::Done(): " << Desc.URI << std::endl;
  753. Item::Done(Message,Size,Md5Hash,Cnf);
  754. string const FinalFile = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
  755. if (State == StateFetchDiff)
  756. {
  757. // rred expects the patch as $FinalFile.ed.$patchname.gz
  758. Rename(DestFile, FinalFile + ".ed." + patch.file + ".gz");
  759. // check if this is the last completed diff
  760. State = StateDoneDiff;
  761. for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
  762. I != allPatches->end(); ++I)
  763. if ((*I)->State != StateDoneDiff)
  764. {
  765. if(Debug)
  766. std::clog << "Not the last done diff in the batch: " << Desc.URI << std::endl;
  767. return;
  768. }
  769. // this is the last completed diff, so we are ready to apply now
  770. State = StateApplyDiff;
  771. if(Debug)
  772. std::clog << "Sending to rred method: " << FinalFile << std::endl;
  773. Local = true;
  774. Desc.URI = "rred:" + FinalFile;
  775. QueueURI(Desc);
  776. Mode = "rred";
  777. return;
  778. }
  779. // success in download/apply all diffs, clean up
  780. else if (State == StateApplyDiff)
  781. {
  782. // see if we really got the expected file
  783. if(!ExpectedHash.empty() && !ExpectedHash.VerifyFile(DestFile))
  784. {
  785. RenameOnError(HashSumMismatch);
  786. return;
  787. }
  788. // move the result into place
  789. if(Debug)
  790. std::clog << "Moving patched file in place: " << std::endl
  791. << DestFile << " -> " << FinalFile << std::endl;
  792. Rename(DestFile, FinalFile);
  793. chmod(FinalFile.c_str(), 0644);
  794. // otherwise lists cleanup will eat the file
  795. DestFile = FinalFile;
  796. // ensure the ed's are gone regardless of list-cleanup
  797. for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
  798. I != allPatches->end(); ++I)
  799. {
  800. std::string patch = FinalFile + ".ed." + (*I)->patch.file + ".gz";
  801. unlink(patch.c_str());
  802. }
  803. // all set and done
  804. Complete = true;
  805. if(Debug)
  806. std::clog << "allDone: " << DestFile << "\n" << std::endl;
  807. }
  808. }
  809. /*}}}*/
  810. // AcqIndex::AcqIndex - Constructor /*{{{*/
  811. // ---------------------------------------------------------------------
  812. /* The package file is added to the queue and a second class is
  813. instantiated to fetch the revision file */
  814. pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,
  815. string URI,string URIDesc,string ShortDesc,
  816. HashString ExpectedHash, string comprExt)
  817. : Item(Owner), RealURI(URI), ExpectedHash(ExpectedHash), Target(0),
  818. MetaIndexParser(0)
  819. {
  820. if(comprExt.empty() == true)
  821. {
  822. // autoselect the compression method
  823. std::vector<std::string> types = APT::Configuration::getCompressionTypes();
  824. for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
  825. comprExt.append(*t).append(" ");
  826. if (comprExt.empty() == false)
  827. comprExt.erase(comprExt.end()-1);
  828. }
  829. CompressionExtension = comprExt;
  830. Verify = true;
  831. Init(URI, URIDesc, ShortDesc);
  832. }
  833. pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, IndexTarget const *Target,
  834. HashString const &ExpectedHash, indexRecords *MetaIndexParser)
  835. : Item(Owner), RealURI(Target->URI), ExpectedHash(ExpectedHash)
  836. {
  837. // autoselect the compression method
  838. std::vector<std::string> types = APT::Configuration::getCompressionTypes();
  839. CompressionExtension = "";
  840. if (ExpectedHash.empty() == false)
  841. {
  842. for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
  843. if (*t == "uncompressed" || MetaIndexParser->Exists(string(Target->MetaKey).append(".").append(*t)) == true)
  844. CompressionExtension.append(*t).append(" ");
  845. }
  846. else
  847. {
  848. for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
  849. CompressionExtension.append(*t).append(" ");
  850. }
  851. if (CompressionExtension.empty() == false)
  852. CompressionExtension.erase(CompressionExtension.end()-1);
  853. // only verify non-optional targets, see acquire-item.h for a FIXME
  854. // to make this more flexible
  855. if (Target->IsOptional())
  856. Verify = false;
  857. else
  858. Verify = true;
  859. // we need this in Init()
  860. this->Target = Target;
  861. this->MetaIndexParser = MetaIndexParser;
  862. Init(Target->URI, Target->Description, Target->ShortDesc);
  863. }
  864. /*}}}*/
  865. // AcqIndex::Init - defered Constructor /*{{{*/
  866. void pkgAcqIndex::Init(string const &URI, string const &URIDesc, string const &ShortDesc) {
  867. Decompression = false;
  868. Erase = false;
  869. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  870. DestFile += URItoFileName(URI);
  871. std::string const comprExt = CompressionExtension.substr(0, CompressionExtension.find(' '));
  872. std::string MetaKey;
  873. if (comprExt == "uncompressed")
  874. {
  875. Desc.URI = URI;
  876. if(Target)
  877. MetaKey = string(Target->MetaKey);
  878. }
  879. else
  880. {
  881. Desc.URI = URI + '.' + comprExt;
  882. if(Target)
  883. MetaKey = string(Target->MetaKey) + '.' + comprExt;
  884. }
  885. // load the filesize
  886. if(MetaIndexParser)
  887. {
  888. indexRecords::checkSum *Record = MetaIndexParser->Lookup(MetaKey);
  889. if(Record)
  890. FileSize = Record->Size;
  891. }
  892. Desc.Description = URIDesc;
  893. Desc.Owner = this;
  894. Desc.ShortDesc = ShortDesc;
  895. QueueURI(Desc);
  896. }
  897. /*}}}*/
  898. // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
  899. // ---------------------------------------------------------------------
  900. /* The only header we use is the last-modified header. */
  901. string pkgAcqIndex::Custom600Headers()
  902. {
  903. string Final = _config->FindDir("Dir::State::lists");
  904. Final += URItoFileName(RealURI);
  905. if (_config->FindB("Acquire::GzipIndexes",false))
  906. Final += ".gz";
  907. string msg = "\nIndex-File: true";
  908. // FIXME: this really should use "IndexTarget::IsOptional()" but that
  909. // seems to be difficult without breaking ABI
  910. if (ShortDesc().find("Translation") != 0)
  911. msg += "\nFail-Ignore: true";
  912. struct stat Buf;
  913. if (stat(Final.c_str(),&Buf) == 0)
  914. msg += "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  915. return msg;
  916. }
  917. /*}}}*/
  918. void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
  919. {
  920. size_t const nextExt = CompressionExtension.find(' ');
  921. if (nextExt != std::string::npos)
  922. {
  923. CompressionExtension = CompressionExtension.substr(nextExt+1);
  924. Init(RealURI, Desc.Description, Desc.ShortDesc);
  925. return;
  926. }
  927. // on decompression failure, remove bad versions in partial/
  928. if (Decompression && Erase) {
  929. string s = _config->FindDir("Dir::State::lists") + "partial/";
  930. s.append(URItoFileName(RealURI));
  931. unlink(s.c_str());
  932. }
  933. Item::Failed(Message,Cnf);
  934. }
  935. /*}}}*/
  936. // AcqIndex::Done - Finished a fetch /*{{{*/
  937. // ---------------------------------------------------------------------
  938. /* This goes through a number of states.. On the initial fetch the
  939. method could possibly return an alternate filename which points
  940. to the uncompressed version of the file. If this is so the file
  941. is copied into the partial directory. In all other cases the file
  942. is decompressed with a gzip uri. */
  943. void pkgAcqIndex::Done(string Message,unsigned long long Size,string Hash,
  944. pkgAcquire::MethodConfig *Cfg)
  945. {
  946. Item::Done(Message,Size,Hash,Cfg);
  947. if (Decompression == true)
  948. {
  949. if (_config->FindB("Debug::pkgAcquire::Auth", false))
  950. {
  951. std::cerr << std::endl << RealURI << ": Computed Hash: " << Hash;
  952. std::cerr << " Expected Hash: " << ExpectedHash.toStr() << std::endl;
  953. }
  954. if (!ExpectedHash.empty() && ExpectedHash.toStr() != Hash)
  955. {
  956. RenameOnError(HashSumMismatch);
  957. return;
  958. }
  959. /* Verify the index file for correctness (all indexes must
  960. * have a Package field) (LP: #346386) (Closes: #627642) */
  961. if (Verify == true)
  962. {
  963. FileFd fd(DestFile, FileFd::ReadOnly);
  964. // Only test for correctness if the file is not empty (empty is ok)
  965. if (fd.FileSize() > 0)
  966. {
  967. pkgTagSection sec;
  968. pkgTagFile tag(&fd);
  969. // all our current indexes have a field 'Package' in each section
  970. if (_error->PendingError() == true || tag.Step(sec) == false || sec.Exists("Package") == false)
  971. {
  972. RenameOnError(InvalidFormat);
  973. return;
  974. }
  975. }
  976. }
  977. // Done, move it into position
  978. string FinalFile = _config->FindDir("Dir::State::lists");
  979. FinalFile += URItoFileName(RealURI);
  980. Rename(DestFile,FinalFile);
  981. chmod(FinalFile.c_str(),0644);
  982. /* We restore the original name to DestFile so that the clean operation
  983. will work OK */
  984. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  985. DestFile += URItoFileName(RealURI);
  986. // Remove the compressed version.
  987. if (Erase == true)
  988. unlink(DestFile.c_str());
  989. return;
  990. }
  991. Erase = false;
  992. Complete = true;
  993. // Handle the unzipd case
  994. string FileName = LookupTag(Message,"Alt-Filename");
  995. if (FileName.empty() == false)
  996. {
  997. // The files timestamp matches
  998. if (StringToBool(LookupTag(Message,"Alt-IMS-Hit"),false) == true)
  999. return;
  1000. Decompression = true;
  1001. Local = true;
  1002. DestFile += ".decomp";
  1003. Desc.URI = "copy:" + FileName;
  1004. QueueURI(Desc);
  1005. Mode = "copy";
  1006. return;
  1007. }
  1008. FileName = LookupTag(Message,"Filename");
  1009. if (FileName.empty() == true)
  1010. {
  1011. Status = StatError;
  1012. ErrorText = "Method gave a blank filename";
  1013. }
  1014. std::string const compExt = CompressionExtension.substr(0, CompressionExtension.find(' '));
  1015. // The files timestamp matches
  1016. if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true) {
  1017. if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz")
  1018. // Update DestFile for .gz suffix so that the clean operation keeps it
  1019. DestFile += ".gz";
  1020. return;
  1021. }
  1022. if (FileName == DestFile)
  1023. Erase = true;
  1024. else
  1025. Local = true;
  1026. string decompProg;
  1027. // If we enable compressed indexes and already have gzip, keep it
  1028. if (_config->FindB("Acquire::GzipIndexes",false) && compExt == "gz" && !Local) {
  1029. string FinalFile = _config->FindDir("Dir::State::lists");
  1030. FinalFile += URItoFileName(RealURI) + ".gz";
  1031. Rename(DestFile,FinalFile);
  1032. chmod(FinalFile.c_str(),0644);
  1033. // Update DestFile for .gz suffix so that the clean operation keeps it
  1034. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  1035. DestFile += URItoFileName(RealURI) + ".gz";
  1036. return;
  1037. }
  1038. // get the binary name for your used compression type
  1039. decompProg = _config->Find(string("Acquire::CompressionTypes::").append(compExt),"");
  1040. if(decompProg.empty() == false);
  1041. else if(compExt == "uncompressed")
  1042. decompProg = "copy";
  1043. else {
  1044. _error->Error("Unsupported extension: %s", compExt.c_str());
  1045. return;
  1046. }
  1047. Decompression = true;
  1048. DestFile += ".decomp";
  1049. Desc.URI = decompProg + ":" + FileName;
  1050. QueueURI(Desc);
  1051. // FIXME: this points to a c++ string that goes out of scope
  1052. Mode = decompProg.c_str();
  1053. }
  1054. /*}}}*/
  1055. // AcqIndexTrans::pkgAcqIndexTrans - Constructor /*{{{*/
  1056. // ---------------------------------------------------------------------
  1057. /* The Translation file is added to the queue */
  1058. pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner,
  1059. string URI,string URIDesc,string ShortDesc)
  1060. : pkgAcqIndex(Owner, URI, URIDesc, ShortDesc, HashString(), "")
  1061. {
  1062. }
  1063. pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner, IndexTarget const *Target,
  1064. HashString const &ExpectedHash, indexRecords *MetaIndexParser)
  1065. : pkgAcqIndex(Owner, Target, ExpectedHash, MetaIndexParser)
  1066. {
  1067. // load the filesize
  1068. indexRecords::checkSum *Record = MetaIndexParser->Lookup(string(Target->MetaKey));
  1069. if(Record)
  1070. FileSize = Record->Size;
  1071. }
  1072. /*}}}*/
  1073. // AcqIndexTrans::Custom600Headers - Insert custom request headers /*{{{*/
  1074. // ---------------------------------------------------------------------
  1075. string pkgAcqIndexTrans::Custom600Headers()
  1076. {
  1077. string Final = _config->FindDir("Dir::State::lists");
  1078. Final += URItoFileName(RealURI);
  1079. struct stat Buf;
  1080. if (stat(Final.c_str(),&Buf) != 0)
  1081. return "\nFail-Ignore: true\nIndex-File: true";
  1082. return "\nFail-Ignore: true\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  1083. }
  1084. /*}}}*/
  1085. // AcqIndexTrans::Failed - Silence failure messages for missing files /*{{{*/
  1086. // ---------------------------------------------------------------------
  1087. /* */
  1088. void pkgAcqIndexTrans::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
  1089. {
  1090. size_t const nextExt = CompressionExtension.find(' ');
  1091. if (nextExt != std::string::npos)
  1092. {
  1093. CompressionExtension = CompressionExtension.substr(nextExt+1);
  1094. Init(RealURI, Desc.Description, Desc.ShortDesc);
  1095. Status = StatIdle;
  1096. return;
  1097. }
  1098. if (Cnf->LocalOnly == true ||
  1099. StringToBool(LookupTag(Message,"Transient-Failure"),false) == false)
  1100. {
  1101. // Ignore this
  1102. Status = StatDone;
  1103. Complete = false;
  1104. Dequeue();
  1105. return;
  1106. }
  1107. Item::Failed(Message,Cnf);
  1108. }
  1109. /*}}}*/
  1110. pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner, /*{{{*/
  1111. string URI,string URIDesc,string ShortDesc,
  1112. string MetaIndexURI, string MetaIndexURIDesc,
  1113. string MetaIndexShortDesc,
  1114. const vector<IndexTarget*>* IndexTargets,
  1115. indexRecords* MetaIndexParser) :
  1116. Item(Owner), RealURI(URI), MetaIndexURI(MetaIndexURI),
  1117. MetaIndexURIDesc(MetaIndexURIDesc), MetaIndexShortDesc(MetaIndexShortDesc),
  1118. MetaIndexParser(MetaIndexParser), IndexTargets(IndexTargets)
  1119. {
  1120. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  1121. DestFile += URItoFileName(URI);
  1122. // remove any partial downloaded sig-file in partial/.
  1123. // it may confuse proxies and is too small to warrant a
  1124. // partial download anyway
  1125. unlink(DestFile.c_str());
  1126. // Create the item
  1127. Desc.Description = URIDesc;
  1128. Desc.Owner = this;
  1129. Desc.ShortDesc = ShortDesc;
  1130. Desc.URI = URI;
  1131. string Final = _config->FindDir("Dir::State::lists");
  1132. Final += URItoFileName(RealURI);
  1133. if (RealFileExists(Final) == true)
  1134. {
  1135. // File was already in place. It needs to be re-downloaded/verified
  1136. // because Release might have changed, we do give it a different
  1137. // name than DestFile because otherwise the http method will
  1138. // send If-Range requests and there are too many broken servers
  1139. // out there that do not understand them
  1140. LastGoodSig = DestFile+".reverify";
  1141. Rename(Final,LastGoodSig);
  1142. }
  1143. // we expect the indextargets + one additional Release file
  1144. ExpectedAdditionalItems = IndexTargets->size() + 1;
  1145. QueueURI(Desc);
  1146. }
  1147. /*}}}*/
  1148. pkgAcqMetaSig::~pkgAcqMetaSig() /*{{{*/
  1149. {
  1150. // if the file was never queued undo file-changes done in the constructor
  1151. if (QueueCounter == 1 && Status == StatIdle && FileSize == 0 && Complete == false &&
  1152. LastGoodSig.empty() == false)
  1153. {
  1154. string const Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
  1155. if (RealFileExists(Final) == false && RealFileExists(LastGoodSig) == true)
  1156. Rename(LastGoodSig, Final);
  1157. }
  1158. }
  1159. /*}}}*/
  1160. // pkgAcqMetaSig::Custom600Headers - Insert custom request headers /*{{{*/
  1161. // ---------------------------------------------------------------------
  1162. /* The only header we use is the last-modified header. */
  1163. string pkgAcqMetaSig::Custom600Headers()
  1164. {
  1165. struct stat Buf;
  1166. if (stat(LastGoodSig.c_str(),&Buf) != 0)
  1167. return "\nIndex-File: true";
  1168. return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  1169. }
  1170. void pkgAcqMetaSig::Done(string Message,unsigned long long Size,string MD5,
  1171. pkgAcquire::MethodConfig *Cfg)
  1172. {
  1173. Item::Done(Message,Size,MD5,Cfg);
  1174. string FileName = LookupTag(Message,"Filename");
  1175. if (FileName.empty() == true)
  1176. {
  1177. Status = StatError;
  1178. ErrorText = "Method gave a blank filename";
  1179. return;
  1180. }
  1181. if (FileName != DestFile)
  1182. {
  1183. // We have to copy it into place
  1184. Local = true;
  1185. Desc.URI = "copy:" + FileName;
  1186. QueueURI(Desc);
  1187. return;
  1188. }
  1189. Complete = true;
  1190. // at this point pkgAcqMetaIndex takes over
  1191. ExpectedAdditionalItems = 0;
  1192. // put the last known good file back on i-m-s hit (it will
  1193. // be re-verified again)
  1194. // Else do nothing, we have the new file in DestFile then
  1195. if(StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
  1196. Rename(LastGoodSig, DestFile);
  1197. // queue a pkgAcqMetaIndex to be verified against the sig we just retrieved
  1198. new pkgAcqMetaIndex(Owner, MetaIndexURI, MetaIndexURIDesc,
  1199. MetaIndexShortDesc, DestFile, IndexTargets,
  1200. MetaIndexParser);
  1201. }
  1202. /*}}}*/
  1203. void pkgAcqMetaSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf)/*{{{*/
  1204. {
  1205. string Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
  1206. // at this point pkgAcqMetaIndex takes over
  1207. ExpectedAdditionalItems = 0;
  1208. // if we get a network error we fail gracefully
  1209. if(Status == StatTransientNetworkError)
  1210. {
  1211. Item::Failed(Message,Cnf);
  1212. // move the sigfile back on transient network failures
  1213. if(FileExists(LastGoodSig))
  1214. Rename(LastGoodSig,Final);
  1215. // set the status back to , Item::Failed likes to reset it
  1216. Status = pkgAcquire::Item::StatTransientNetworkError;
  1217. return;
  1218. }
  1219. // Delete any existing sigfile when the acquire failed
  1220. unlink(Final.c_str());
  1221. // queue a pkgAcqMetaIndex with no sigfile
  1222. new pkgAcqMetaIndex(Owner, MetaIndexURI, MetaIndexURIDesc, MetaIndexShortDesc,
  1223. "", IndexTargets, MetaIndexParser);
  1224. if (Cnf->LocalOnly == true ||
  1225. StringToBool(LookupTag(Message,"Transient-Failure"),false) == false)
  1226. {
  1227. // Ignore this
  1228. Status = StatDone;
  1229. Complete = false;
  1230. Dequeue();
  1231. return;
  1232. }
  1233. Item::Failed(Message,Cnf);
  1234. }
  1235. /*}}}*/
  1236. pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire *Owner, /*{{{*/
  1237. string URI,string URIDesc,string ShortDesc,
  1238. string SigFile,
  1239. const vector<struct IndexTarget*>* IndexTargets,
  1240. indexRecords* MetaIndexParser) :
  1241. Item(Owner), RealURI(URI), SigFile(SigFile), IndexTargets(IndexTargets),
  1242. MetaIndexParser(MetaIndexParser), AuthPass(false), IMSHit(false)
  1243. {
  1244. DestFile = _config->FindDir("Dir::State::lists") + "partial/";
  1245. DestFile += URItoFileName(URI);
  1246. // Create the item
  1247. Desc.Description = URIDesc;
  1248. Desc.Owner = this;
  1249. Desc.ShortDesc = ShortDesc;
  1250. Desc.URI = URI;
  1251. // we expect more item
  1252. ExpectedAdditionalItems = IndexTargets->size();
  1253. QueueURI(Desc);
  1254. }
  1255. /*}}}*/
  1256. // pkgAcqMetaIndex::Custom600Headers - Insert custom request headers /*{{{*/
  1257. // ---------------------------------------------------------------------
  1258. /* The only header we use is the last-modified header. */
  1259. string pkgAcqMetaIndex::Custom600Headers()
  1260. {
  1261. string Final = _config->FindDir("Dir::State::lists");
  1262. Final += URItoFileName(RealURI);
  1263. struct stat Buf;
  1264. if (stat(Final.c_str(),&Buf) != 0)
  1265. return "\nIndex-File: true";
  1266. return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  1267. }
  1268. /*}}}*/
  1269. void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,string Hash, /*{{{*/
  1270. pkgAcquire::MethodConfig *Cfg)
  1271. {
  1272. Item::Done(Message,Size,Hash,Cfg);
  1273. // MetaIndexes are done in two passes: one to download the
  1274. // metaindex with an appropriate method, and a second to verify it
  1275. // with the gpgv method
  1276. if (AuthPass == true)
  1277. {
  1278. AuthDone(Message);
  1279. // all cool, move Release file into place
  1280. Complete = true;
  1281. }
  1282. else
  1283. {
  1284. RetrievalDone(Message);
  1285. if (!Complete)
  1286. // Still more retrieving to do
  1287. return;
  1288. if (SigFile == "")
  1289. {
  1290. // There was no signature file, so we are finished. Download
  1291. // the indexes and do only hashsum verification if possible
  1292. MetaIndexParser->Load(DestFile);
  1293. QueueIndexes(false);
  1294. }
  1295. else
  1296. {
  1297. // There was a signature file, so pass it to gpgv for
  1298. // verification
  1299. if (_config->FindB("Debug::pkgAcquire::Auth", false))
  1300. std::cerr << "Metaindex acquired, queueing gpg verification ("
  1301. << SigFile << "," << DestFile << ")\n";
  1302. AuthPass = true;
  1303. Desc.URI = "gpgv:" + SigFile;
  1304. QueueURI(Desc);
  1305. Mode = "gpgv";
  1306. return;
  1307. }
  1308. }
  1309. if (Complete == true)
  1310. {
  1311. string FinalFile = _config->FindDir("Dir::State::lists");
  1312. FinalFile += URItoFileName(RealURI);
  1313. if (SigFile == DestFile)
  1314. SigFile = FinalFile;
  1315. Rename(DestFile,FinalFile);
  1316. chmod(FinalFile.c_str(),0644);
  1317. DestFile = FinalFile;
  1318. }
  1319. }
  1320. /*}}}*/
  1321. void pkgAcqMetaIndex::RetrievalDone(string Message) /*{{{*/
  1322. {
  1323. // We have just finished downloading a Release file (it is not
  1324. // verified yet)
  1325. string FileName = LookupTag(Message,"Filename");
  1326. if (FileName.empty() == true)
  1327. {
  1328. Status = StatError;
  1329. ErrorText = "Method gave a blank filename";
  1330. return;
  1331. }
  1332. if (FileName != DestFile)
  1333. {
  1334. Local = true;
  1335. Desc.URI = "copy:" + FileName;
  1336. QueueURI(Desc);
  1337. return;
  1338. }
  1339. // make sure to verify against the right file on I-M-S hit
  1340. IMSHit = StringToBool(LookupTag(Message,"IMS-Hit"),false);
  1341. if(IMSHit)
  1342. {
  1343. string FinalFile = _config->FindDir("Dir::State::lists");
  1344. FinalFile += URItoFileName(RealURI);
  1345. if (SigFile == DestFile)
  1346. {
  1347. SigFile = FinalFile;
  1348. // constructor of pkgAcqMetaClearSig moved it out of the way,
  1349. // now move it back in on IMS hit for the 'old' file
  1350. string const OldClearSig = DestFile + ".reverify";
  1351. if (RealFileExists(OldClearSig) == true)
  1352. Rename(OldClearSig, FinalFile);
  1353. }
  1354. DestFile = FinalFile;
  1355. }
  1356. Complete = true;
  1357. }
  1358. /*}}}*/
  1359. void pkgAcqMetaIndex::AuthDone(string Message) /*{{{*/
  1360. {
  1361. // At this point, the gpgv method has succeeded, so there is a
  1362. // valid signature from a key in the trusted keyring. We
  1363. // perform additional verification of its contents, and use them
  1364. // to verify the indexes we are about to download
  1365. if (!MetaIndexParser->Load(DestFile))
  1366. {
  1367. Status = StatAuthError;
  1368. ErrorText = MetaIndexParser->ErrorText;
  1369. return;
  1370. }
  1371. if (!VerifyVendor(Message))
  1372. {
  1373. return;
  1374. }
  1375. if (_config->FindB("Debug::pkgAcquire::Auth", false))
  1376. std::cerr << "Signature verification succeeded: "
  1377. << DestFile << std::endl;
  1378. // Download further indexes with verification
  1379. QueueIndexes(true);
  1380. // is it a clearsigned MetaIndex file?
  1381. if (DestFile == SigFile)
  1382. return;
  1383. // Done, move signature file into position
  1384. string VerifiedSigFile = _config->FindDir("Dir::State::lists") +
  1385. URItoFileName(RealURI) + ".gpg";
  1386. Rename(SigFile,VerifiedSigFile);
  1387. chmod(VerifiedSigFile.c_str(),0644);
  1388. }
  1389. /*}}}*/
  1390. void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/
  1391. {
  1392. #if 0
  1393. /* Reject invalid, existing Release files (LP: #346386) (Closes: #627642)
  1394. * FIXME: Disabled; it breaks unsigned repositories without hashes */
  1395. if (!verify && FileExists(DestFile) && !MetaIndexParser->Load(DestFile))
  1396. {
  1397. Status = StatError;
  1398. ErrorText = MetaIndexParser->ErrorText;
  1399. return;
  1400. }
  1401. #endif
  1402. bool transInRelease = false;
  1403. {
  1404. std::vector<std::string> const keys = MetaIndexParser->MetaKeys();
  1405. for (std::vector<std::string>::const_iterator k = keys.begin(); k != keys.end(); ++k)
  1406. // FIXME: Feels wrong to check for hardcoded string here, but what should we do else…
  1407. if (k->find("Translation-") != std::string::npos)
  1408. {
  1409. transInRelease = true;
  1410. break;
  1411. }
  1412. }
  1413. // at this point the real Items are loaded in the fetcher
  1414. ExpectedAdditionalItems = 0;
  1415. for (vector <struct IndexTarget*>::const_iterator Target = IndexTargets->begin();
  1416. Target != IndexTargets->end();
  1417. ++Target)
  1418. {
  1419. HashString ExpectedIndexHash;
  1420. indexRecords::checkSum *Record = MetaIndexParser->Lookup((*Target)->MetaKey);
  1421. bool compressedAvailable = false;
  1422. if (Record == NULL)
  1423. {
  1424. if ((*Target)->IsOptional() == true)
  1425. {
  1426. std::vector<std::string> types = APT::Configuration::getCompressionTypes();
  1427. for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
  1428. if (MetaIndexParser->Exists((*Target)->MetaKey + "." + *t) == true)
  1429. {
  1430. compressedAvailable = true;
  1431. break;
  1432. }
  1433. }
  1434. else if (verify == true)
  1435. {
  1436. Status = StatAuthError;
  1437. strprintf(ErrorText, _("Unable to find expected entry '%s' in Release file (Wrong sources.list entry or malformed file)"), (*Target)->MetaKey.c_str());
  1438. return;
  1439. }
  1440. }
  1441. else
  1442. {
  1443. ExpectedIndexHash = Record->Hash;
  1444. if (_config->FindB("Debug::pkgAcquire::Auth", false))
  1445. {
  1446. std::cerr << "Queueing: " << (*Target)->URI << std::endl;
  1447. std::cerr << "Expected Hash: " << ExpectedIndexHash.toStr() << std::endl;
  1448. std::cerr << "For: " << Record->MetaKeyFilename << std::endl;
  1449. }
  1450. if (verify == true && ExpectedIndexHash.empty() == true && (*Target)->IsOptional() == false)
  1451. {
  1452. Status = StatAuthError;
  1453. strprintf(ErrorText, _("Unable to find hash sum for '%s' in Release file"), (*Target)->MetaKey.c_str());
  1454. return;
  1455. }
  1456. }
  1457. if ((*Target)->IsOptional() == true)
  1458. {
  1459. if ((*Target)->IsSubIndex() == true)
  1460. new pkgAcqSubIndex(Owner, (*Target)->URI, (*Target)->Description,
  1461. (*Target)->ShortDesc, ExpectedIndexHash);
  1462. else if (transInRelease == false || Record != NULL || compressedAvailable == true)
  1463. {
  1464. if (_config->FindB("Acquire::PDiffs",true) == true && transInRelease == true &&
  1465. MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true)
  1466. new pkgAcqDiffIndex(Owner, *Target, ExpectedIndexHash, MetaIndexParser);
  1467. else
  1468. new pkgAcqIndexTrans(Owner, *Target, ExpectedIndexHash, MetaIndexParser);
  1469. }
  1470. continue;
  1471. }
  1472. /* Queue Packages file (either diff or full packages files, depending
  1473. on the users option) - we also check if the PDiff Index file is listed
  1474. in the Meta-Index file. Ideal would be if pkgAcqDiffIndex would test this
  1475. instead, but passing the required info to it is to much hassle */
  1476. if(_config->FindB("Acquire::PDiffs",true) == true && (verify == false ||
  1477. MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true))
  1478. new pkgAcqDiffIndex(Owner, *Target, ExpectedIndexHash, MetaIndexParser);
  1479. else
  1480. new pkgAcqIndex(Owner, *Target, ExpectedIndexHash, MetaIndexParser);
  1481. }
  1482. }
  1483. /*}}}*/
  1484. bool pkgAcqMetaIndex::VerifyVendor(string Message) /*{{{*/
  1485. {
  1486. string::size_type pos;
  1487. // check for missing sigs (that where not fatal because otherwise we had
  1488. // bombed earlier)
  1489. string missingkeys;
  1490. string msg = _("There is no public key available for the "
  1491. "following key IDs:\n");
  1492. pos = Message.find("NO_PUBKEY ");
  1493. if (pos != std::string::npos)
  1494. {
  1495. string::size_type start = pos+strlen("NO_PUBKEY ");
  1496. string Fingerprint = Message.substr(start, Message.find("\n")-start);
  1497. missingkeys += (Fingerprint);
  1498. }
  1499. if(!missingkeys.empty())
  1500. _error->Warning("%s", (msg + missingkeys).c_str());
  1501. string Transformed = MetaIndexParser->GetExpectedDist();
  1502. if (Transformed == "../project/experimental")
  1503. {
  1504. Transformed = "experimental";
  1505. }
  1506. pos = Transformed.rfind('/');
  1507. if (pos != string::npos)
  1508. {
  1509. Transformed = Transformed.substr(0, pos);
  1510. }
  1511. if (Transformed == ".")
  1512. {
  1513. Transformed = "";
  1514. }
  1515. if (_config->FindB("Acquire::Check-Valid-Until", true) == true &&
  1516. MetaIndexParser->GetValidUntil() > 0) {
  1517. time_t const invalid_since = time(NULL) - MetaIndexParser->GetValidUntil();
  1518. if (invalid_since > 0)
  1519. // TRANSLATOR: The first %s is the URL of the bad Release file, the second is
  1520. // the time since then the file is invalid - formated in the same way as in
  1521. // the download progress display (e.g. 7d 3h 42min 1s)
  1522. return _error->Error(
  1523. _("Release file for %s is expired (invalid since %s). "
  1524. "Updates for this repository will not be applied."),
  1525. RealURI.c_str(), TimeToStr(invalid_since).c_str());
  1526. }
  1527. if (_config->FindB("Debug::pkgAcquire::Auth", false))
  1528. {
  1529. std::cerr << "Got Codename: " << MetaIndexParser->GetDist() << std::endl;
  1530. std::cerr << "Expecting Dist: " << MetaIndexParser->GetExpectedDist() << std::endl;
  1531. std::cerr << "Transformed Dist: " << Transformed << std::endl;
  1532. }
  1533. if (MetaIndexParser->CheckDist(Transformed) == false)
  1534. {
  1535. // This might become fatal one day
  1536. // Status = StatAuthError;
  1537. // ErrorText = "Conflicting distribution; expected "
  1538. // + MetaIndexParser->GetExpectedDist() + " but got "
  1539. // + MetaIndexParser->GetDist();
  1540. // return false;
  1541. if (!Transformed.empty())
  1542. {
  1543. _error->Warning(_("Conflicting distribution: %s (expected %s but got %s)"),
  1544. Desc.Description.c_str(),
  1545. Transformed.c_str(),
  1546. MetaIndexParser->GetDist().c_str());
  1547. }
  1548. }
  1549. return true;
  1550. }
  1551. /*}}}*/
  1552. // pkgAcqMetaIndex::Failed - no Release file present or no signature file present /*{{{*/
  1553. // ---------------------------------------------------------------------
  1554. /* */
  1555. void pkgAcqMetaIndex::Failed(string Message,pkgAcquire::MethodConfig * /*Cnf*/)
  1556. {
  1557. if (AuthPass == true)
  1558. {
  1559. // gpgv method failed, if we have a good signature
  1560. string LastGoodSigFile = _config->FindDir("Dir::State::lists").append("partial/").append(URItoFileName(RealURI));
  1561. if (DestFile != SigFile)
  1562. LastGoodSigFile.append(".gpg");
  1563. LastGoodSigFile.append(".reverify");
  1564. if(FileExists(LastGoodSigFile))
  1565. {
  1566. string VerifiedSigFile = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
  1567. if (DestFile != SigFile)
  1568. VerifiedSigFile.append(".gpg");
  1569. Rename(LastGoodSigFile, VerifiedSigFile);
  1570. Status = StatTransientNetworkError;
  1571. _error->Warning(_("An error occurred during the signature "
  1572. "verification. The repository is not updated "
  1573. "and the previous index files will be used. "
  1574. "GPG error: %s: %s\n"),
  1575. Desc.Description.c_str(),
  1576. LookupTag(Message,"Message").c_str());
  1577. RunScripts("APT::Update::Auth-Failure");
  1578. return;
  1579. } else if (LookupTag(Message,"Message").find("NODATA") != string::npos) {
  1580. /* Invalid signature file, reject (LP: #346386) (Closes: #627642) */
  1581. _error->Error(_("GPG error: %s: %s"),
  1582. Desc.Description.c_str(),
  1583. LookupTag(Message,"Message").c_str());
  1584. return;
  1585. } else {
  1586. _error->Warning(_("GPG error: %s: %s"),
  1587. Desc.Description.c_str(),
  1588. LookupTag(Message,"Message").c_str());
  1589. }
  1590. // gpgv method failed
  1591. ReportMirrorFailure("GPGFailure");
  1592. }
  1593. /* Always move the meta index, even if gpgv failed. This ensures
  1594. * that PackageFile objects are correctly filled in */
  1595. if (FileExists(DestFile)) {
  1596. string FinalFile = _config->FindDir("Dir::State::lists");
  1597. FinalFile += URItoFileName(RealURI);
  1598. /* InRelease files become Release files, otherwise
  1599. * they would be considered as trusted later on */
  1600. if (SigFile == DestFile) {
  1601. RealURI = RealURI.replace(RealURI.rfind("InRelease"), 9,
  1602. "Release");
  1603. FinalFile = FinalFile.replace(FinalFile.rfind("InRelease"), 9,
  1604. "Release");
  1605. SigFile = FinalFile;
  1606. }
  1607. Rename(DestFile,FinalFile);
  1608. chmod(FinalFile.c_str(),0644);
  1609. DestFile = FinalFile;
  1610. }
  1611. // No Release file was present, or verification failed, so fall
  1612. // back to queueing Packages files without verification
  1613. QueueIndexes(false);
  1614. }
  1615. /*}}}*/
  1616. pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire *Owner, /*{{{*/
  1617. string const &URI, string const &URIDesc, string const &ShortDesc,
  1618. string const &MetaIndexURI, string const &MetaIndexURIDesc, string const &MetaIndexShortDesc,
  1619. string const &MetaSigURI, string const &MetaSigURIDesc, string const &MetaSigShortDesc,
  1620. const vector<struct IndexTarget*>* IndexTargets,
  1621. indexRecords* MetaIndexParser) :
  1622. pkgAcqMetaIndex(Owner, URI, URIDesc, ShortDesc, "", IndexTargets, MetaIndexParser),
  1623. MetaIndexURI(MetaIndexURI), MetaIndexURIDesc(MetaIndexURIDesc), MetaIndexShortDesc(MetaIndexShortDesc),
  1624. MetaSigURI(MetaSigURI), MetaSigURIDesc(MetaSigURIDesc), MetaSigShortDesc(MetaSigShortDesc)
  1625. {
  1626. SigFile = DestFile;
  1627. // index targets + (worst case:) Release/Release.gpg
  1628. ExpectedAdditionalItems = IndexTargets->size() + 2;
  1629. // keep the old InRelease around in case of transistent network errors
  1630. string const Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
  1631. if (RealFileExists(Final) == true)
  1632. {
  1633. string const LastGoodSig = DestFile + ".reverify";
  1634. Rename(Final,LastGoodSig);
  1635. }
  1636. }
  1637. /*}}}*/
  1638. pkgAcqMetaClearSig::~pkgAcqMetaClearSig() /*{{{*/
  1639. {
  1640. // if the file was never queued undo file-changes done in the constructor
  1641. if (QueueCounter == 1 && Status == StatIdle && FileSize == 0 && Complete == false)
  1642. {
  1643. string const Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
  1644. string const LastGoodSig = DestFile + ".reverify";
  1645. if (RealFileExists(Final) == false && RealFileExists(LastGoodSig) == true)
  1646. Rename(LastGoodSig, Final);
  1647. }
  1648. }
  1649. /*}}}*/
  1650. // pkgAcqMetaClearSig::Custom600Headers - Insert custom request headers /*{{{*/
  1651. // ---------------------------------------------------------------------
  1652. // FIXME: this can go away once the InRelease file is used widely
  1653. string pkgAcqMetaClearSig::Custom600Headers()
  1654. {
  1655. string Final = _config->FindDir("Dir::State::lists");
  1656. Final += URItoFileName(RealURI);
  1657. struct stat Buf;
  1658. if (stat(Final.c_str(),&Buf) != 0)
  1659. {
  1660. Final = DestFile + ".reverify";
  1661. if (stat(Final.c_str(),&Buf) != 0)
  1662. return "\nIndex-File: true\nFail-Ignore: true\n";
  1663. }
  1664. return "\nIndex-File: true\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
  1665. }
  1666. /*}}}*/
  1667. void pkgAcqMetaClearSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
  1668. {
  1669. // we failed, we will not get additional items from this method
  1670. ExpectedAdditionalItems = 0;
  1671. if (AuthPass == false)
  1672. {
  1673. // Remove the 'old' InRelease file if we try Release.gpg now as otherwise
  1674. // the file will stay around and gives a false-auth impression (CVE-2012-0214)
  1675. string FinalFile = _config->FindDir("Dir::State::lists");
  1676. FinalFile.append(URItoFileName(RealURI));
  1677. if (FileExists(FinalFile))
  1678. unlink(FinalFile.c_str());
  1679. new pkgAcqMetaSig(Owner,
  1680. MetaSigURI, MetaSigURIDesc, MetaSigShortDesc,
  1681. MetaIndexURI, MetaIndexURIDesc, MetaIndexShortDesc,
  1682. IndexTargets, MetaIndexParser);
  1683. if (Cnf->LocalOnly == true ||
  1684. StringToBool(LookupTag(Message, "Transient-Failure"), false) == false)
  1685. Dequeue();
  1686. }
  1687. else
  1688. pkgAcqMetaIndex::Failed(Message, Cnf);
  1689. }
  1690. /*}}}*/
  1691. // AcqArchive::AcqArchive - Constructor /*{{{*/
  1692. // ---------------------------------------------------------------------
  1693. /* This just sets up the initial fetch environment and queues the first
  1694. possibilitiy */
  1695. pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
  1696. pkgRecords *Recs,pkgCache::VerIterator const &Version,
  1697. string &StoreFilename) :
  1698. Item(Owner), Version(Version), Sources(Sources), Recs(Recs),
  1699. StoreFilename(StoreFilename), Vf(Version.FileList()),
  1700. Trusted(false)
  1701. {
  1702. Retries = _config->FindI("Acquire::Retries",0);
  1703. if (Version.Arch() == 0)
  1704. {
  1705. _error->Error(_("I wasn't able to locate a file for the %s package. "
  1706. "This might mean you need to manually fix this package. "
  1707. "(due to missing arch)"),
  1708. Version.ParentPkg().FullName().c_str());
  1709. return;
  1710. }
  1711. /* We need to find a filename to determine the extension. We make the
  1712. assumption here that all the available sources for this version share
  1713. the same extension.. */
  1714. // Skip not source sources, they do not have file fields.
  1715. for (; Vf.end() == false; ++Vf)
  1716. {
  1717. if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0)
  1718. continue;
  1719. break;
  1720. }
  1721. // Does not really matter here.. we are going to fail out below
  1722. if (Vf.end() != true)
  1723. {
  1724. // If this fails to get a file name we will bomb out below.
  1725. pkgRecords::Parser &Parse = Recs->Lookup(Vf);
  1726. if (_error->PendingError() == true)
  1727. return;
  1728. // Generate the final file name as: package_version_arch.foo
  1729. StoreFilename = QuoteString(Version.ParentPkg().Name(),"_:") + '_' +
  1730. QuoteString(Version.VerStr(),"_:") + '_' +
  1731. QuoteString(Version.Arch(),"_:.") +
  1732. "." + flExtension(Parse.FileName());
  1733. }
  1734. // check if we have one trusted source for the package. if so, switch
  1735. // to "TrustedOnly" mode - but only if not in AllowUnauthenticated mode
  1736. bool const allowUnauth = _config->FindB("APT::Get::AllowUnauthenticated", false);
  1737. bool const debugAuth = _config->FindB("Debug::pkgAcquire::Auth", false);
  1738. bool seenUntrusted = false;
  1739. for (pkgCache::VerFileIterator i = Version.FileList(); i.end() == false; ++i)
  1740. {
  1741. pkgIndexFile *Index;
  1742. if (Sources->FindIndex(i.File(),Index) == false)
  1743. continue;
  1744. if (debugAuth == true)
  1745. std::cerr << "Checking index: " << Index->Describe()
  1746. << "(Trusted=" << Index->IsTrusted() << ")" << std::endl;
  1747. if (Index->IsTrusted() == true)
  1748. {
  1749. Trusted = true;
  1750. if (allowUnauth == false)
  1751. break;
  1752. }
  1753. else
  1754. seenUntrusted = true;
  1755. }
  1756. // "allow-unauthenticated" restores apts old fetching behaviour
  1757. // that means that e.g. unauthenticated file:// uris are higher
  1758. // priority than authenticated http:// uris
  1759. if (allowUnauth == true && seenUntrusted == true)
  1760. Trusted = false;
  1761. // Select a source
  1762. if (QueueNext() == false && _error->PendingError() == false)
  1763. _error->Error(_("Can't find a source to download version '%s' of '%s'"),
  1764. Version.VerStr(), Version.ParentPkg().FullName(false).c_str());
  1765. }
  1766. /*}}}*/
  1767. // AcqArchive::QueueNext - Queue the next file source /*{{{*/
  1768. // ---------------------------------------------------------------------
  1769. /* This queues the next available file version for download. It checks if
  1770. the archive is already available in the cache and stashs the MD5 for
  1771. checking later. */
  1772. bool pkgAcqArchive::QueueNext()
  1773. {
  1774. string const ForceHash = _config->Find("Acquire::ForceHash");
  1775. for (; Vf.end() == false; ++Vf)
  1776. {
  1777. // Ignore not source sources
  1778. if ((Vf.File()->Flags & pkgCache::Flag::NotSource) != 0)
  1779. continue;
  1780. // Try to cross match against the source list
  1781. pkgIndexFile *Index;
  1782. if (Sources->FindIndex(Vf.File(),Index) == false)
  1783. continue;
  1784. // only try to get a trusted package from another source if that source
  1785. // is also trusted
  1786. if(Trusted && !Index->IsTrusted())
  1787. continue;
  1788. // Grab the text package record
  1789. pkgRecords::Parser &Parse = Recs->Lookup(Vf);
  1790. if (_error->PendingError() == true)
  1791. return false;
  1792. string PkgFile = Parse.FileName();
  1793. if (ForceHash.empty() == false)
  1794. {
  1795. if(stringcasecmp(ForceHash, "sha512") == 0)
  1796. ExpectedHash = HashString("SHA512", Parse.SHA512Hash());
  1797. else if(stringcasecmp(ForceHash, "sha256") == 0)
  1798. ExpectedHash = HashString("SHA256", Parse.SHA256Hash());
  1799. else if (stringcasecmp(ForceHash, "sha1") == 0)
  1800. ExpectedHash = HashString("SHA1", Parse.SHA1Hash());
  1801. else
  1802. ExpectedHash = HashString("MD5Sum", Parse.MD5Hash());
  1803. }
  1804. else
  1805. {
  1806. string Hash;
  1807. if ((Hash = Parse.SHA512Hash()).empty() == false)
  1808. ExpectedHash = HashString("SHA512", Hash);
  1809. else if ((Hash = Parse.SHA256Hash()).empty() == false)
  1810. ExpectedHash = HashString("SHA256", Hash);
  1811. else if ((Hash = Parse.SHA1Hash()).empty() == false)
  1812. ExpectedHash = HashString("SHA1", Hash);
  1813. else
  1814. ExpectedHash = HashString("MD5Sum", Parse.MD5Hash());
  1815. }
  1816. if (PkgFile.empty() == true)
  1817. return _error->Error(_("The package index files are corrupted. No Filename: "
  1818. "field for package %s."),
  1819. Version.ParentPkg().Name());
  1820. Desc.URI = Index->ArchiveURI(PkgFile);
  1821. Desc.Description = Index->ArchiveInfo(Version);
  1822. Desc.Owner = this;
  1823. Desc.ShortDesc = Version.ParentPkg().FullName(true);
  1824. // See if we already have the file. (Legacy filenames)
  1825. FileSize = Version->Size;
  1826. string FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile);
  1827. struct stat Buf;
  1828. if (stat(FinalFile.c_str(),&Buf) == 0)
  1829. {
  1830. // Make sure the size matches
  1831. if ((unsigned long long)Buf.st_size == Version->Size)
  1832. {
  1833. Complete = true;
  1834. Local = true;
  1835. Status = StatDone;
  1836. StoreFilename = DestFile = FinalFile;
  1837. return true;
  1838. }
  1839. /* Hmm, we have a file and its size does not match, this means it is
  1840. an old style mismatched arch */
  1841. unlink(FinalFile.c_str());
  1842. }
  1843. // Check it again using the new style output filenames
  1844. FinalFile = _config->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename);
  1845. if (stat(FinalFile.c_str(),&Buf) == 0)
  1846. {
  1847. // Make sure the size matches
  1848. if ((unsigned long long)Buf.st_size == Version->Size)
  1849. {
  1850. Complete = true;
  1851. Local = true;
  1852. Status = StatDone;
  1853. StoreFilename = DestFile = FinalFile;
  1854. return true;
  1855. }
  1856. /* Hmm, we have a file and its size does not match, this shouldn't
  1857. happen.. */
  1858. unlink(FinalFile.c_str());
  1859. }
  1860. DestFile = _config->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(StoreFilename);
  1861. // Check the destination file
  1862. if (stat(DestFile.c_str(),&Buf) == 0)
  1863. {
  1864. // Hmm, the partial file is too big, erase it
  1865. if ((unsigned long long)Buf.st_size > Version->Size)
  1866. unlink(DestFile.c_str());
  1867. else
  1868. PartialSize = Buf.st_size;
  1869. }
  1870. // Disables download of archives - useful if no real installation follows,
  1871. // e.g. if we are just interested in proposed installation order
  1872. if (_config->FindB("Debug::pkgAcqArchive::NoQueue", false) == true)
  1873. {
  1874. Complete = true;
  1875. Local = true;
  1876. Status = StatDone;
  1877. StoreFilename = DestFile = FinalFile;
  1878. return true;
  1879. }
  1880. // Create the item
  1881. Local = false;
  1882. QueueURI(Desc);
  1883. ++Vf;
  1884. return true;
  1885. }
  1886. return false;
  1887. }
  1888. /*}}}*/
  1889. // AcqArchive::Done - Finished fetching /*{{{*/
  1890. // ---------------------------------------------------------------------
  1891. /* */
  1892. void pkgAcqArchive::Done(string Message,unsigned long long Size,string CalcHash,
  1893. pkgAcquire::MethodConfig *Cfg)
  1894. {
  1895. Item::Done(Message,Size,CalcHash,Cfg);
  1896. // Check the size
  1897. if (Size != Version->Size)
  1898. {
  1899. RenameOnError(SizeMismatch);
  1900. return;
  1901. }
  1902. // Check the hash
  1903. if(ExpectedHash.toStr() != CalcHash)
  1904. {
  1905. RenameOnError(HashSumMismatch);
  1906. return;
  1907. }
  1908. // Grab the output filename
  1909. string FileName = LookupTag(Message,"Filename");
  1910. if (FileName.empty() == true)
  1911. {
  1912. Status = StatError;
  1913. ErrorText = "Method gave a blank filename";
  1914. return;
  1915. }
  1916. Complete = true;
  1917. // Reference filename
  1918. if (FileName != DestFile)
  1919. {
  1920. StoreFilename = DestFile = FileName;
  1921. Local = true;
  1922. return;
  1923. }
  1924. // Done, move it into position
  1925. string FinalFile = _config->FindDir("Dir::Cache::Archives");
  1926. FinalFile += flNotDir(StoreFilename);
  1927. Rename(DestFile,FinalFile);
  1928. StoreFilename = DestFile = FinalFile;
  1929. Complete = true;
  1930. }
  1931. /*}}}*/
  1932. // AcqArchive::Failed - Failure handler /*{{{*/
  1933. // ---------------------------------------------------------------------
  1934. /* Here we try other sources */
  1935. void pkgAcqArchive::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
  1936. {
  1937. ErrorText = LookupTag(Message,"Message");
  1938. /* We don't really want to retry on failed media swaps, this prevents
  1939. that. An interesting observation is that permanent failures are not
  1940. recorded. */
  1941. if (Cnf->Removable == true &&
  1942. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  1943. {
  1944. // Vf = Version.FileList();
  1945. while (Vf.end() == false) ++Vf;
  1946. StoreFilename = string();
  1947. Item::Failed(Message,Cnf);
  1948. return;
  1949. }
  1950. if (QueueNext() == false)
  1951. {
  1952. // This is the retry counter
  1953. if (Retries != 0 &&
  1954. Cnf->LocalOnly == false &&
  1955. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  1956. {
  1957. Retries--;
  1958. Vf = Version.FileList();
  1959. if (QueueNext() == true)
  1960. return;
  1961. }
  1962. StoreFilename = string();
  1963. Item::Failed(Message,Cnf);
  1964. }
  1965. }
  1966. /*}}}*/
  1967. // AcqArchive::IsTrusted - Determine whether this archive comes from a trusted source /*{{{*/
  1968. // ---------------------------------------------------------------------
  1969. APT_PURE bool pkgAcqArchive::IsTrusted()
  1970. {
  1971. return Trusted;
  1972. }
  1973. /*}}}*/
  1974. // AcqArchive::Finished - Fetching has finished, tidy up /*{{{*/
  1975. // ---------------------------------------------------------------------
  1976. /* */
  1977. void pkgAcqArchive::Finished()
  1978. {
  1979. if (Status == pkgAcquire::Item::StatDone &&
  1980. Complete == true)
  1981. return;
  1982. StoreFilename = string();
  1983. }
  1984. /*}}}*/
  1985. // AcqFile::pkgAcqFile - Constructor /*{{{*/
  1986. // ---------------------------------------------------------------------
  1987. /* The file is added to the queue */
  1988. pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI,string Hash,
  1989. unsigned long long Size,string Dsc,string ShortDesc,
  1990. const string &DestDir, const string &DestFilename,
  1991. bool IsIndexFile) :
  1992. Item(Owner), ExpectedHash(Hash), IsIndexFile(IsIndexFile)
  1993. {
  1994. Retries = _config->FindI("Acquire::Retries",0);
  1995. if(!DestFilename.empty())
  1996. DestFile = DestFilename;
  1997. else if(!DestDir.empty())
  1998. DestFile = DestDir + "/" + flNotDir(URI);
  1999. else
  2000. DestFile = flNotDir(URI);
  2001. // Create the item
  2002. Desc.URI = URI;
  2003. Desc.Description = Dsc;
  2004. Desc.Owner = this;
  2005. // Set the short description to the archive component
  2006. Desc.ShortDesc = ShortDesc;
  2007. // Get the transfer sizes
  2008. FileSize = Size;
  2009. struct stat Buf;
  2010. if (stat(DestFile.c_str(),&Buf) == 0)
  2011. {
  2012. // Hmm, the partial file is too big, erase it
  2013. if ((Size > 0) && (unsigned long long)Buf.st_size > Size)
  2014. unlink(DestFile.c_str());
  2015. else
  2016. PartialSize = Buf.st_size;
  2017. }
  2018. QueueURI(Desc);
  2019. }
  2020. /*}}}*/
  2021. // AcqFile::Done - Item downloaded OK /*{{{*/
  2022. // ---------------------------------------------------------------------
  2023. /* */
  2024. void pkgAcqFile::Done(string Message,unsigned long long Size,string CalcHash,
  2025. pkgAcquire::MethodConfig *Cnf)
  2026. {
  2027. Item::Done(Message,Size,CalcHash,Cnf);
  2028. // Check the hash
  2029. if(!ExpectedHash.empty() && ExpectedHash.toStr() != CalcHash)
  2030. {
  2031. RenameOnError(HashSumMismatch);
  2032. return;
  2033. }
  2034. string FileName = LookupTag(Message,"Filename");
  2035. if (FileName.empty() == true)
  2036. {
  2037. Status = StatError;
  2038. ErrorText = "Method gave a blank filename";
  2039. return;
  2040. }
  2041. Complete = true;
  2042. // The files timestamp matches
  2043. if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
  2044. return;
  2045. // We have to copy it into place
  2046. if (FileName != DestFile)
  2047. {
  2048. Local = true;
  2049. if (_config->FindB("Acquire::Source-Symlinks",true) == false ||
  2050. Cnf->Removable == true)
  2051. {
  2052. Desc.URI = "copy:" + FileName;
  2053. QueueURI(Desc);
  2054. return;
  2055. }
  2056. // Erase the file if it is a symlink so we can overwrite it
  2057. struct stat St;
  2058. if (lstat(DestFile.c_str(),&St) == 0)
  2059. {
  2060. if (S_ISLNK(St.st_mode) != 0)
  2061. unlink(DestFile.c_str());
  2062. }
  2063. // Symlink the file
  2064. if (symlink(FileName.c_str(),DestFile.c_str()) != 0)
  2065. {
  2066. ErrorText = "Link to " + DestFile + " failure ";
  2067. Status = StatError;
  2068. Complete = false;
  2069. }
  2070. }
  2071. }
  2072. /*}}}*/
  2073. // AcqFile::Failed - Failure handler /*{{{*/
  2074. // ---------------------------------------------------------------------
  2075. /* Here we try other sources */
  2076. void pkgAcqFile::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
  2077. {
  2078. ErrorText = LookupTag(Message,"Message");
  2079. // This is the retry counter
  2080. if (Retries != 0 &&
  2081. Cnf->LocalOnly == false &&
  2082. StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
  2083. {
  2084. Retries--;
  2085. QueueURI(Desc);
  2086. return;
  2087. }
  2088. Item::Failed(Message,Cnf);
  2089. }
  2090. /*}}}*/
  2091. // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
  2092. // ---------------------------------------------------------------------
  2093. /* The only header we use is the last-modified header. */
  2094. string pkgAcqFile::Custom600Headers()
  2095. {
  2096. if (IsIndexFile)
  2097. return "\nIndex-File: true";
  2098. return "";
  2099. }
  2100. /*}}}*/