1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acquire-item.cc,v 1.46.2.9 2004/01/16 18:51:11 mdz Exp $
4 /* ######################################################################
6 Acquire Item - Item to acquire
8 Each item can download to exactly one file at a time. This means you
9 cannot create an item that fetches two uri's to two files at the same
10 time. The pkgAcqIndex class creates a second class upon instantiation
11 to fetch the other index files because of this.
13 ##################################################################### */
15 // Include Files /*{{{*/
18 #include <apt-pkg/acquire-item.h>
19 #include <apt-pkg/configuration.h>
20 #include <apt-pkg/aptconfiguration.h>
21 #include <apt-pkg/sourcelist.h>
22 #include <apt-pkg/error.h>
23 #include <apt-pkg/strutl.h>
24 #include <apt-pkg/fileutl.h>
25 #include <apt-pkg/sha1.h>
26 #include <apt-pkg/tagfile.h>
27 #include <apt-pkg/indexrecords.h>
28 #include <apt-pkg/acquire.h>
29 #include <apt-pkg/hashes.h>
30 #include <apt-pkg/indexfile.h>
31 #include <apt-pkg/pkgcache.h>
32 #include <apt-pkg/cacheiterators.h>
33 #include <apt-pkg/pkgrecords.h>
53 // Acquire::Item::Item - Constructor /*{{{*/
54 // ---------------------------------------------------------------------
56 pkgAcquire::Item::Item(pkgAcquire
*Owner
) : Owner(Owner
), FileSize(0),
57 PartialSize(0), Mode(0), ID(0), Complete(false),
58 Local(false), QueueCounter(0)
64 // Acquire::Item::~Item - Destructor /*{{{*/
65 // ---------------------------------------------------------------------
67 pkgAcquire::Item::~Item()
72 // Acquire::Item::Failed - Item failed to download /*{{{*/
73 // ---------------------------------------------------------------------
74 /* We return to an idle state if there are still other queues that could
76 void pkgAcquire::Item::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
79 ErrorText
= LookupTag(Message
,"Message");
80 UsedMirror
= LookupTag(Message
,"UsedMirror");
81 if (QueueCounter
<= 1)
83 /* This indicates that the file is not available right now but might
84 be sometime later. If we do a retry cycle then this should be
86 if (Cnf
->LocalOnly
== true &&
87 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
98 // report mirror failure back to LP if we actually use a mirror
99 string FailReason
= LookupTag(Message
, "FailReason");
100 if(FailReason
.size() != 0)
101 ReportMirrorFailure(FailReason
);
103 ReportMirrorFailure(ErrorText
);
106 // Acquire::Item::Start - Item has begun to download /*{{{*/
107 // ---------------------------------------------------------------------
108 /* Stash status and the file size. Note that setting Complete means
109 sub-phases of the acquire process such as decompresion are operating */
110 void pkgAcquire::Item::Start(string
/*Message*/,unsigned long long Size
)
112 Status
= StatFetching
;
113 if (FileSize
== 0 && Complete
== false)
117 // Acquire::Item::Done - Item downloaded OK /*{{{*/
118 // ---------------------------------------------------------------------
120 void pkgAcquire::Item::Done(string Message
,unsigned long long Size
,string
/*Hash*/,
121 pkgAcquire::MethodConfig
* /*Cnf*/)
123 // We just downloaded something..
124 string FileName
= LookupTag(Message
,"Filename");
125 UsedMirror
= LookupTag(Message
,"UsedMirror");
126 if (Complete
== false && !Local
&& FileName
== DestFile
)
129 Owner
->Log
->Fetched(Size
,atoi(LookupTag(Message
,"Resume-Point","0").c_str()));
135 ErrorText
= string();
136 Owner
->Dequeue(this);
139 // Acquire::Item::Rename - Rename a file /*{{{*/
140 // ---------------------------------------------------------------------
141 /* This helper function is used by a lot of item methods as their final
143 void pkgAcquire::Item::Rename(string From
,string To
)
145 if (rename(From
.c_str(),To
.c_str()) != 0)
148 snprintf(S
,sizeof(S
),_("rename failed, %s (%s -> %s)."),strerror(errno
),
149 From
.c_str(),To
.c_str());
155 bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState
const error
)/*{{{*/
157 if(FileExists(DestFile
))
158 Rename(DestFile
, DestFile
+ ".FAILED");
162 case HashSumMismatch
:
163 ErrorText
= _("Hash Sum mismatch");
164 Status
= StatAuthError
;
165 ReportMirrorFailure("HashChecksumFailure");
168 ErrorText
= _("Size mismatch");
169 Status
= StatAuthError
;
170 ReportMirrorFailure("SizeFailure");
173 ErrorText
= _("Invalid file format");
175 // do not report as usually its not the mirrors fault, but Portal/Proxy
181 // Acquire::Item::ReportMirrorFailure /*{{{*/
182 // ---------------------------------------------------------------------
183 void pkgAcquire::Item::ReportMirrorFailure(string FailCode
)
185 // we only act if a mirror was used at all
186 if(UsedMirror
.empty())
189 std::cerr
<< "\nReportMirrorFailure: "
191 << " Uri: " << DescURI()
193 << FailCode
<< std::endl
;
195 const char *Args
[40];
197 string report
= _config
->Find("Methods::Mirror::ProblemReporting",
198 "/usr/lib/apt/apt-report-mirror-failure");
199 if(!FileExists(report
))
201 Args
[i
++] = report
.c_str();
202 Args
[i
++] = UsedMirror
.c_str();
203 Args
[i
++] = DescURI().c_str();
204 Args
[i
++] = FailCode
.c_str();
206 pid_t pid
= ExecFork();
209 _error
->Error("ReportMirrorFailure Fork failed");
214 execvp(Args
[0], (char**)Args
);
215 std::cerr
<< "Could not exec " << Args
[0] << std::endl
;
218 if(!ExecWait(pid
, "report-mirror-failure"))
220 _error
->Warning("Couldn't report problem to '%s'",
221 _config
->Find("Methods::Mirror::ProblemReporting").c_str());
225 // AcqSubIndex::AcqSubIndex - Constructor /*{{{*/
226 // ---------------------------------------------------------------------
227 /* Get a sub-index file based on checksums from a 'master' file and
228 possibly query additional files */
229 pkgAcqSubIndex::pkgAcqSubIndex(pkgAcquire
*Owner
, string
const &URI
,
230 string
const &URIDesc
, string
const &ShortDesc
,
231 HashString
const &ExpectedHash
)
232 : Item(Owner
), ExpectedHash(ExpectedHash
)
234 /* XXX: Beware: Currently this class does nothing (of value) anymore ! */
235 Debug
= _config
->FindB("Debug::pkgAcquire::SubIndex",false);
237 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
238 DestFile
+= URItoFileName(URI
);
241 Desc
.Description
= URIDesc
;
243 Desc
.ShortDesc
= ShortDesc
;
248 std::clog
<< "pkgAcqSubIndex: " << Desc
.URI
<< std::endl
;
251 // AcqSubIndex::Custom600Headers - Insert custom request headers /*{{{*/
252 // ---------------------------------------------------------------------
253 /* The only header we use is the last-modified header. */
254 string
pkgAcqSubIndex::Custom600Headers()
256 string Final
= _config
->FindDir("Dir::State::lists");
257 Final
+= URItoFileName(Desc
.URI
);
260 if (stat(Final
.c_str(),&Buf
) != 0)
261 return "\nIndex-File: true\nFail-Ignore: true\n";
262 return "\nIndex-File: true\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
265 void pkgAcqSubIndex::Failed(string Message
,pkgAcquire::MethodConfig
* /*Cnf*/)/*{{{*/
268 std::clog
<< "pkgAcqSubIndex failed: " << Desc
.URI
<< " with " << Message
<< std::endl
;
274 // No good Index is provided
277 void pkgAcqSubIndex::Done(string Message
,unsigned long long Size
,string Md5Hash
, /*{{{*/
278 pkgAcquire::MethodConfig
*Cnf
)
281 std::clog
<< "pkgAcqSubIndex::Done(): " << Desc
.URI
<< std::endl
;
283 string FileName
= LookupTag(Message
,"Filename");
284 if (FileName
.empty() == true)
287 ErrorText
= "Method gave a blank filename";
291 if (FileName
!= DestFile
)
294 Desc
.URI
= "copy:" + FileName
;
299 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
301 string FinalFile
= _config
->FindDir("Dir::State::lists")+URItoFileName(Desc
.URI
);
303 /* Downloaded invalid transindex => Error (LP: #346386) (Closes: #627642) */
304 indexRecords SubIndexParser
;
305 if (FileExists(DestFile
) == true && !SubIndexParser
.Load(DestFile
)) {
307 ErrorText
= SubIndexParser
.ErrorText
;
311 // success in downloading the index
314 std::clog
<< "Renaming: " << DestFile
<< " -> " << FinalFile
<< std::endl
;
315 Rename(DestFile
,FinalFile
);
316 chmod(FinalFile
.c_str(),0644);
317 DestFile
= FinalFile
;
319 if(ParseIndex(DestFile
) == false)
320 return Failed("", NULL
);
328 bool pkgAcqSubIndex::ParseIndex(string
const &IndexFile
) /*{{{*/
330 indexRecords SubIndexParser
;
331 if (FileExists(IndexFile
) == false || SubIndexParser
.Load(IndexFile
) == false)
333 // so something with the downloaded index
337 // AcqDiffIndex::AcqDiffIndex - Constructor /*{{{*/
338 // ---------------------------------------------------------------------
339 /* Get the DiffIndex file first and see if there are patches available
340 * If so, create a pkgAcqIndexDiffs fetcher that will get and apply the
341 * patches. If anything goes wrong in that process, it will fall back to
342 * the original packages file
344 pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire
*Owner
,
345 string URI
,string URIDesc
,string ShortDesc
,
346 HashString ExpectedHash
)
347 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
),
351 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
353 Desc
.Description
= URIDesc
+ "/DiffIndex";
355 Desc
.ShortDesc
= ShortDesc
;
356 Desc
.URI
= URI
+ ".diff/Index";
358 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
359 DestFile
+= URItoFileName(Desc
.URI
);
362 std::clog
<< "pkgAcqDiffIndex: " << Desc
.URI
<< std::endl
;
364 // look for the current package file
365 CurrentPackagesFile
= _config
->FindDir("Dir::State::lists");
366 CurrentPackagesFile
+= URItoFileName(RealURI
);
368 // FIXME: this file:/ check is a hack to prevent fetching
369 // from local sources. this is really silly, and
370 // should be fixed cleanly as soon as possible
371 if(!FileExists(CurrentPackagesFile
) ||
372 Desc
.URI
.substr(0,strlen("file:/")) == "file:/")
374 // we don't have a pkg file or we don't want to queue
376 std::clog
<< "No index file, local or canceld by user" << std::endl
;
382 std::clog
<< "pkgAcqDiffIndex::pkgAcqDiffIndex(): "
383 << CurrentPackagesFile
<< std::endl
;
389 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
390 // ---------------------------------------------------------------------
391 /* The only header we use is the last-modified header. */
392 string
pkgAcqDiffIndex::Custom600Headers()
394 string Final
= _config
->FindDir("Dir::State::lists");
395 Final
+= URItoFileName(Desc
.URI
);
398 std::clog
<< "Custom600Header-IMS: " << Final
<< std::endl
;
401 if (stat(Final
.c_str(),&Buf
) != 0)
402 return "\nIndex-File: true";
404 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
407 bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile
) /*{{{*/
410 std::clog
<< "pkgAcqDiffIndex::ParseIndexDiff() " << IndexDiffFile
415 vector
<DiffInfo
> available_patches
;
417 FileFd
Fd(IndexDiffFile
,FileFd::ReadOnly
);
419 if (_error
->PendingError() == true)
422 if(TF
.Step(Tags
) == true)
428 string
const tmp
= Tags
.FindS("SHA1-Current");
429 std::stringstream
ss(tmp
);
430 ss
>> ServerSha1
>> size
;
431 unsigned long const ServerSize
= atol(size
.c_str());
433 FileFd
fd(CurrentPackagesFile
, FileFd::ReadOnly
);
436 string
const local_sha1
= SHA1
.Result();
438 if(local_sha1
== ServerSha1
)
440 // we have the same sha1 as the server so we are done here
442 std::clog
<< "Package file is up-to-date" << std::endl
;
443 // list cleanup needs to know that this file as well as the already
444 // present index is ours, so we create an empty diff to save it for us
445 new pkgAcqIndexDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
446 ExpectedHash
, ServerSha1
, available_patches
);
452 std::clog
<< "SHA1-Current: " << ServerSha1
<< " and we start at "<< fd
.Name() << " " << fd
.Size() << " " << local_sha1
<< std::endl
;
454 // check the historie and see what patches we need
455 string
const history
= Tags
.FindS("SHA1-History");
456 std::stringstream
hist(history
);
457 while(hist
>> d
.sha1
>> size
>> d
.file
)
459 // read until the first match is found
460 // from that point on, we probably need all diffs
461 if(d
.sha1
== local_sha1
)
463 else if (found
== false)
467 std::clog
<< "Need to get diff: " << d
.file
<< std::endl
;
468 available_patches
.push_back(d
);
471 if (available_patches
.empty() == false)
473 // patching with too many files is rather slow compared to a fast download
474 unsigned long const fileLimit
= _config
->FindI("Acquire::PDiffs::FileLimit", 0);
475 if (fileLimit
!= 0 && fileLimit
< available_patches
.size())
478 std::clog
<< "Need " << available_patches
.size() << " diffs (Limit is " << fileLimit
479 << ") so fallback to complete download" << std::endl
;
483 // see if the patches are too big
484 found
= false; // it was true and it will be true again at the end
485 d
= *available_patches
.begin();
486 string
const firstPatch
= d
.file
;
487 unsigned long patchesSize
= 0;
488 std::stringstream
patches(Tags
.FindS("SHA1-Patches"));
489 while(patches
>> d
.sha1
>> size
>> d
.file
)
491 if (firstPatch
== d
.file
)
493 else if (found
== false)
496 patchesSize
+= atol(size
.c_str());
498 unsigned long const sizeLimit
= ServerSize
* _config
->FindI("Acquire::PDiffs::SizeLimit", 100);
499 if (sizeLimit
> 0 && (sizeLimit
/100) < patchesSize
)
502 std::clog
<< "Need " << patchesSize
<< " bytes (Limit is " << sizeLimit
/100
503 << ") so fallback to complete download" << std::endl
;
509 // we have something, queue the next diff
513 string::size_type
const last_space
= Description
.rfind(" ");
514 if(last_space
!= string::npos
)
515 Description
.erase(last_space
, Description
.size()-last_space
);
517 /* decide if we should download patches one by one or in one go:
518 The first is good if the server merges patches, but many don't so client
519 based merging can be attempt in which case the second is better.
520 "bad things" will happen if patches are merged on the server,
521 but client side merging is attempt as well */
522 bool pdiff_merge
= _config
->FindB("Acquire::PDiffs::Merge", true);
523 if (pdiff_merge
== true)
525 // reprepro adds this flag if it has merged patches on the server
526 std::string
const precedence
= Tags
.FindS("X-Patch-Precedence");
527 pdiff_merge
= (precedence
!= "merged");
530 if (pdiff_merge
== false)
531 new pkgAcqIndexDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
532 ExpectedHash
, ServerSha1
, available_patches
);
535 std::vector
<pkgAcqIndexMergeDiffs
*> *diffs
= new std::vector
<pkgAcqIndexMergeDiffs
*>(available_patches
.size());
536 for(size_t i
= 0; i
< available_patches
.size(); ++i
)
537 (*diffs
)[i
] = new pkgAcqIndexMergeDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
, ExpectedHash
,
538 available_patches
[i
], diffs
);
548 // Nothing found, report and return false
549 // Failing here is ok, if we return false later, the full
550 // IndexFile is queued
552 std::clog
<< "Can't find a patch in the index file" << std::endl
;
556 void pkgAcqDiffIndex::Failed(string Message
,pkgAcquire::MethodConfig
* /*Cnf*/)/*{{{*/
559 std::clog
<< "pkgAcqDiffIndex failed: " << Desc
.URI
<< " with " << Message
<< std::endl
560 << "Falling back to normal index file acquire" << std::endl
;
562 new pkgAcqIndex(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
570 void pkgAcqDiffIndex::Done(string Message
,unsigned long long Size
,string Md5Hash
, /*{{{*/
571 pkgAcquire::MethodConfig
*Cnf
)
574 std::clog
<< "pkgAcqDiffIndex::Done(): " << Desc
.URI
<< std::endl
;
576 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
579 FinalFile
= _config
->FindDir("Dir::State::lists")+URItoFileName(RealURI
);
581 // success in downloading the index
583 FinalFile
+= string(".IndexDiff");
585 std::clog
<< "Renaming: " << DestFile
<< " -> " << FinalFile
587 Rename(DestFile
,FinalFile
);
588 chmod(FinalFile
.c_str(),0644);
589 DestFile
= FinalFile
;
591 if(!ParseDiffIndex(DestFile
))
592 return Failed("", NULL
);
600 // AcqIndexDiffs::AcqIndexDiffs - Constructor /*{{{*/
601 // ---------------------------------------------------------------------
602 /* The package diff is added to the queue. one object is constructed
603 * for each diff and the index
605 pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire
*Owner
,
606 string URI
,string URIDesc
,string ShortDesc
,
607 HashString ExpectedHash
,
609 vector
<DiffInfo
> diffs
)
610 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
),
611 available_patches(diffs
), ServerSha1(ServerSha1
)
614 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
615 DestFile
+= URItoFileName(URI
);
617 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
619 Description
= URIDesc
;
621 Desc
.ShortDesc
= ShortDesc
;
623 if(available_patches
.empty() == true)
625 // we are done (yeah!)
631 State
= StateFetchDiff
;
636 void pkgAcqIndexDiffs::Failed(string Message
,pkgAcquire::MethodConfig
* /*Cnf*/)/*{{{*/
639 std::clog
<< "pkgAcqIndexDiffs failed: " << Desc
.URI
<< " with " << Message
<< std::endl
640 << "Falling back to normal index file acquire" << std::endl
;
641 new pkgAcqIndex(Owner
, RealURI
, Description
,Desc
.ShortDesc
,
646 // Finish - helper that cleans the item out of the fetcher queue /*{{{*/
647 void pkgAcqIndexDiffs::Finish(bool allDone
)
649 // we restore the original name, this is required, otherwise
650 // the file will be cleaned
653 DestFile
= _config
->FindDir("Dir::State::lists");
654 DestFile
+= URItoFileName(RealURI
);
656 if(!ExpectedHash
.empty() && !ExpectedHash
.VerifyFile(DestFile
))
658 RenameOnError(HashSumMismatch
);
663 // this is for the "real" finish
668 std::clog
<< "\n\nallDone: " << DestFile
<< "\n" << std::endl
;
673 std::clog
<< "Finishing: " << Desc
.URI
<< std::endl
;
680 bool pkgAcqIndexDiffs::QueueNextDiff() /*{{{*/
683 // calc sha1 of the just patched file
684 string FinalFile
= _config
->FindDir("Dir::State::lists");
685 FinalFile
+= URItoFileName(RealURI
);
687 FileFd
fd(FinalFile
, FileFd::ReadOnly
);
690 string local_sha1
= string(SHA1
.Result());
692 std::clog
<< "QueueNextDiff: "
693 << FinalFile
<< " (" << local_sha1
<< ")"<<std::endl
;
695 // final file reached before all patches are applied
696 if(local_sha1
== ServerSha1
)
702 // remove all patches until the next matching patch is found
703 // this requires the Index file to be ordered
704 for(vector
<DiffInfo
>::iterator I
=available_patches
.begin();
705 available_patches
.empty() == false &&
706 I
!= available_patches
.end() &&
707 I
->sha1
!= local_sha1
;
710 available_patches
.erase(I
);
713 // error checking and falling back if no patch was found
714 if(available_patches
.empty() == true)
720 // queue the right diff
721 Desc
.URI
= RealURI
+ ".diff/" + available_patches
[0].file
+ ".gz";
722 Desc
.Description
= Description
+ " " + available_patches
[0].file
+ string(".pdiff");
723 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
724 DestFile
+= URItoFileName(RealURI
+ ".diff/" + available_patches
[0].file
);
727 std::clog
<< "pkgAcqIndexDiffs::QueueNextDiff(): " << Desc
.URI
<< std::endl
;
734 void pkgAcqIndexDiffs::Done(string Message
,unsigned long long Size
,string Md5Hash
, /*{{{*/
735 pkgAcquire::MethodConfig
*Cnf
)
738 std::clog
<< "pkgAcqIndexDiffs::Done(): " << Desc
.URI
<< std::endl
;
740 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
743 FinalFile
= _config
->FindDir("Dir::State::lists")+URItoFileName(RealURI
);
745 // success in downloading a diff, enter ApplyDiff state
746 if(State
== StateFetchDiff
)
749 // rred excepts the patch as $FinalFile.ed
750 Rename(DestFile
,FinalFile
+".ed");
753 std::clog
<< "Sending to rred method: " << FinalFile
<< std::endl
;
755 State
= StateApplyDiff
;
757 Desc
.URI
= "rred:" + FinalFile
;
764 // success in download/apply a diff, queue next (if needed)
765 if(State
== StateApplyDiff
)
767 // remove the just applied patch
768 available_patches
.erase(available_patches
.begin());
769 unlink((FinalFile
+ ".ed").c_str());
774 std::clog
<< "Moving patched file in place: " << std::endl
775 << DestFile
<< " -> " << FinalFile
<< std::endl
;
777 Rename(DestFile
,FinalFile
);
778 chmod(FinalFile
.c_str(),0644);
780 // see if there is more to download
781 if(available_patches
.empty() == false) {
782 new pkgAcqIndexDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
783 ExpectedHash
, ServerSha1
, available_patches
);
790 // AcqIndexMergeDiffs::AcqIndexMergeDiffs - Constructor /*{{{*/
791 pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire
*Owner
,
792 string
const &URI
, string
const &URIDesc
,
793 string
const &ShortDesc
, HashString
const &ExpectedHash
,
794 DiffInfo
const &patch
,
795 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
)
796 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
),
797 patch(patch
),allPatches(allPatches
), State(StateFetchDiff
)
800 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
801 DestFile
+= URItoFileName(URI
);
803 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
805 Description
= URIDesc
;
807 Desc
.ShortDesc
= ShortDesc
;
809 Desc
.URI
= RealURI
+ ".diff/" + patch
.file
+ ".gz";
810 Desc
.Description
= Description
+ " " + patch
.file
+ string(".pdiff");
811 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
812 DestFile
+= URItoFileName(RealURI
+ ".diff/" + patch
.file
);
815 std::clog
<< "pkgAcqIndexMergeDiffs: " << Desc
.URI
<< std::endl
;
820 void pkgAcqIndexMergeDiffs::Failed(string Message
,pkgAcquire::MethodConfig
* /*Cnf*/)/*{{{*/
823 std::clog
<< "pkgAcqIndexMergeDiffs failed: " << Desc
.URI
<< " with " << Message
<< std::endl
;
828 // check if we are the first to fail, otherwise we are done here
829 State
= StateDoneDiff
;
830 for (std::vector
<pkgAcqIndexMergeDiffs
*>::const_iterator I
= allPatches
->begin();
831 I
!= allPatches
->end(); ++I
)
832 if ((*I
)->State
== StateErrorDiff
)
835 // first failure means we should fallback
836 State
= StateErrorDiff
;
837 std::clog
<< "Falling back to normal index file acquire" << std::endl
;
838 new pkgAcqIndex(Owner
, RealURI
, Description
,Desc
.ShortDesc
,
842 void pkgAcqIndexMergeDiffs::Done(string Message
,unsigned long long Size
,string Md5Hash
, /*{{{*/
843 pkgAcquire::MethodConfig
*Cnf
)
846 std::clog
<< "pkgAcqIndexMergeDiffs::Done(): " << Desc
.URI
<< std::endl
;
848 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
850 string
const FinalFile
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
852 if (State
== StateFetchDiff
)
854 // rred expects the patch as $FinalFile.ed.$patchname.gz
855 Rename(DestFile
, FinalFile
+ ".ed." + patch
.file
+ ".gz");
857 // check if this is the last completed diff
858 State
= StateDoneDiff
;
859 for (std::vector
<pkgAcqIndexMergeDiffs
*>::const_iterator I
= allPatches
->begin();
860 I
!= allPatches
->end(); ++I
)
861 if ((*I
)->State
!= StateDoneDiff
)
864 std::clog
<< "Not the last done diff in the batch: " << Desc
.URI
<< std::endl
;
868 // this is the last completed diff, so we are ready to apply now
869 State
= StateApplyDiff
;
872 std::clog
<< "Sending to rred method: " << FinalFile
<< std::endl
;
875 Desc
.URI
= "rred:" + FinalFile
;
880 // success in download/apply all diffs, clean up
881 else if (State
== StateApplyDiff
)
883 // see if we really got the expected file
884 if(!ExpectedHash
.empty() && !ExpectedHash
.VerifyFile(DestFile
))
886 RenameOnError(HashSumMismatch
);
890 // move the result into place
892 std::clog
<< "Moving patched file in place: " << std::endl
893 << DestFile
<< " -> " << FinalFile
<< std::endl
;
894 Rename(DestFile
, FinalFile
);
895 chmod(FinalFile
.c_str(), 0644);
897 // otherwise lists cleanup will eat the file
898 DestFile
= FinalFile
;
900 // ensure the ed's are gone regardless of list-cleanup
901 for (std::vector
<pkgAcqIndexMergeDiffs
*>::const_iterator I
= allPatches
->begin();
902 I
!= allPatches
->end(); ++I
)
904 std::string patch
= FinalFile
+ ".ed." + (*I
)->patch
.file
+ ".gz";
905 unlink(patch
.c_str());
911 std::clog
<< "allDone: " << DestFile
<< "\n" << std::endl
;
915 // AcqIndex::AcqIndex - Constructor /*{{{*/
916 // ---------------------------------------------------------------------
917 /* The package file is added to the queue and a second class is
918 instantiated to fetch the revision file */
919 pkgAcqIndex::pkgAcqIndex(pkgAcquire
*Owner
,
920 string URI
,string URIDesc
,string ShortDesc
,
921 HashString ExpectedHash
, string comprExt
)
922 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
)
924 if(comprExt
.empty() == true)
926 // autoselect the compression method
927 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
928 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
929 comprExt
.append(*t
).append(" ");
930 if (comprExt
.empty() == false)
931 comprExt
.erase(comprExt
.end()-1);
933 CompressionExtension
= comprExt
;
935 Init(URI
, URIDesc
, ShortDesc
);
937 pkgAcqIndex::pkgAcqIndex(pkgAcquire
*Owner
, IndexTarget
const *Target
,
938 HashString
const &ExpectedHash
, indexRecords
const *MetaIndexParser
)
939 : Item(Owner
), RealURI(Target
->URI
), ExpectedHash(ExpectedHash
)
941 // autoselect the compression method
942 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
943 CompressionExtension
= "";
944 if (ExpectedHash
.empty() == false)
946 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
947 if (*t
== "uncompressed" || MetaIndexParser
->Exists(string(Target
->MetaKey
).append(".").append(*t
)) == true)
948 CompressionExtension
.append(*t
).append(" ");
952 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
953 CompressionExtension
.append(*t
).append(" ");
955 if (CompressionExtension
.empty() == false)
956 CompressionExtension
.erase(CompressionExtension
.end()-1);
958 Init(Target
->URI
, Target
->Description
, Target
->ShortDesc
);
961 // AcqIndex::Init - defered Constructor /*{{{*/
962 void pkgAcqIndex::Init(string
const &URI
, string
const &URIDesc
, string
const &ShortDesc
) {
963 Decompression
= false;
966 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
967 DestFile
+= URItoFileName(URI
);
969 std::string
const comprExt
= CompressionExtension
.substr(0, CompressionExtension
.find(' '));
970 if (comprExt
== "uncompressed")
973 Desc
.URI
= URI
+ '.' + comprExt
;
974 DestFile
= DestFile
+ '.' + comprExt
;
977 Desc
.Description
= URIDesc
;
979 Desc
.ShortDesc
= ShortDesc
;
984 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
985 // ---------------------------------------------------------------------
986 /* The only header we use is the last-modified header. */
987 string
pkgAcqIndex::Custom600Headers()
989 std::string
const compExt
= CompressionExtension
.substr(0, CompressionExtension
.find(' '));
990 string Final
= _config
->FindDir("Dir::State::lists");
991 Final
+= URItoFileName(RealURI
);
992 if (_config
->FindB("Acquire::GzipIndexes",false))
995 string msg
= "\nIndex-File: true";
996 // FIXME: this really should use "IndexTarget::IsOptional()" but that
997 // seems to be difficult without breaking ABI
998 if (ShortDesc().find("Translation") != 0)
999 msg
+= "\nFail-Ignore: true";
1001 if (stat(Final
.c_str(),&Buf
) == 0)
1002 msg
+= "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1007 void pkgAcqIndex::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
) /*{{{*/
1009 size_t const nextExt
= CompressionExtension
.find(' ');
1010 if (nextExt
!= std::string::npos
)
1012 CompressionExtension
= CompressionExtension
.substr(nextExt
+1);
1013 Init(RealURI
, Desc
.Description
, Desc
.ShortDesc
);
1017 // on decompression failure, remove bad versions in partial/
1018 if (Decompression
&& Erase
) {
1019 string s
= _config
->FindDir("Dir::State::lists") + "partial/";
1020 s
.append(URItoFileName(RealURI
));
1024 Item::Failed(Message
,Cnf
);
1027 // pkgAcqIndex::GetFinalFilename - Return the full final file path /*{{{*/
1028 std::string
pkgAcqIndex::GetFinalFilename(std::string
const &URI
,
1029 std::string
const &compExt
)
1031 std::string FinalFile
= _config
->FindDir("Dir::State::lists");
1032 FinalFile
+= URItoFileName(URI
);
1033 if (_config
->FindB("Acquire::GzipIndexes",false) == true)
1034 FinalFile
+= '.' + compExt
;
1038 // AcqIndex::ReverifyAfterIMS - Reverify index after an ims-hit /*{{{*/
1039 void pkgAcqIndex::ReverifyAfterIMS(std::string
const &FileName
)
1041 std::string
const compExt
= CompressionExtension
.substr(0, CompressionExtension
.find(' '));
1042 if (_config
->FindB("Acquire::GzipIndexes",false) == true)
1043 DestFile
+= compExt
;
1045 string FinalFile
= GetFinalFilename(RealURI
, compExt
);
1046 Rename(FinalFile
, FileName
);
1047 Decompression
= true;
1048 Desc
.URI
= "copy:" + FileName
;
1052 // AcqIndex::Done - Finished a fetch /*{{{*/
1053 // ---------------------------------------------------------------------
1054 /* This goes through a number of states.. On the initial fetch the
1055 method could possibly return an alternate filename which points
1056 to the uncompressed version of the file. If this is so the file
1057 is copied into the partial directory. In all other cases the file
1058 is decompressed with a gzip uri. */
1059 void pkgAcqIndex::Done(string Message
,unsigned long long Size
,string Hash
,
1060 pkgAcquire::MethodConfig
*Cfg
)
1062 Item::Done(Message
,Size
,Hash
,Cfg
);
1063 std::string
const compExt
= CompressionExtension
.substr(0, CompressionExtension
.find(' '));
1065 if (Decompression
== true)
1067 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1069 std::cerr
<< std::endl
<< RealURI
<< ": Computed Hash: " << Hash
;
1070 std::cerr
<< " Expected Hash: " << ExpectedHash
.toStr() << std::endl
;
1073 if (!ExpectedHash
.empty() && ExpectedHash
.toStr() != Hash
)
1076 RenameOnError(HashSumMismatch
);
1080 // FIXME: this can go away once we only ever download stuff that
1081 // has a valid hash and we never do GET based probing
1083 /* Always verify the index file for correctness (all indexes must
1084 * have a Package field) (LP: #346386) (Closes: #627642)
1086 FileFd
fd(DestFile
, FileFd::ReadOnly
, FileFd::Extension
);
1087 // Only test for correctness if the file is not empty (empty is ok)
1091 pkgTagFile
tag(&fd
);
1093 // all our current indexes have a field 'Package' in each section
1094 if (_error
->PendingError() == true || tag
.Step(sec
) == false || sec
.Exists("Package") == false)
1096 RenameOnError(InvalidFormat
);
1101 // Done, move it into position
1102 string FinalFile
= GetFinalFilename(RealURI
, compExt
);
1103 Rename(DestFile
,FinalFile
);
1104 chmod(FinalFile
.c_str(),0644);
1106 /* We restore the original name to DestFile so that the clean operation
1108 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
1109 DestFile
+= URItoFileName(RealURI
);
1110 if (_config
->FindB("Acquire::GzipIndexes",false))
1111 DestFile
+= '.' + compExt
;
1113 // Remove the compressed version.
1115 unlink(DestFile
.c_str());
1122 // Handle the unzipd case
1123 string FileName
= LookupTag(Message
,"Alt-Filename");
1124 if (FileName
.empty() == false)
1126 Decompression
= true;
1128 DestFile
+= ".decomp";
1129 Desc
.URI
= "copy:" + FileName
;
1135 FileName
= LookupTag(Message
,"Filename");
1136 if (FileName
.empty() == true)
1139 ErrorText
= "Method gave a blank filename";
1142 if (FileName
== DestFile
)
1147 // The files timestamp matches, for non-local URLs reverify the local
1148 // file, for local file, uncompress again to ensure the hashsum is still
1149 // matching the Release file
1150 if (!Local
&& StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
1152 // set destfile to the final destfile
1153 if(_config
->FindB("Acquire::GzipIndexes",false) == false)
1155 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
1156 DestFile
+= URItoFileName(RealURI
);
1159 ReverifyAfterIMS(FileName
);
1164 // If we enable compressed indexes, queue for hash verification
1165 if (_config
->FindB("Acquire::GzipIndexes",false))
1167 DestFile
= _config
->FindDir("Dir::State::lists");
1168 DestFile
+= URItoFileName(RealURI
) + '.' + compExt
;
1170 Decompression
= true;
1171 Desc
.URI
= "copy:" + FileName
;
1177 // get the binary name for your used compression type
1178 decompProg
= _config
->Find(string("Acquire::CompressionTypes::").append(compExt
),"");
1179 if(decompProg
.empty() == false);
1180 else if(compExt
== "uncompressed")
1181 decompProg
= "copy";
1183 _error
->Error("Unsupported extension: %s", compExt
.c_str());
1187 Decompression
= true;
1188 DestFile
+= ".decomp";
1189 Desc
.URI
= decompProg
+ ":" + FileName
;
1192 // FIXME: this points to a c++ string that goes out of scope
1193 Mode
= decompProg
.c_str();
1196 // AcqIndexTrans::pkgAcqIndexTrans - Constructor /*{{{*/
1197 // ---------------------------------------------------------------------
1198 /* The Translation file is added to the queue */
1199 pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire
*Owner
,
1200 string URI
,string URIDesc
,string ShortDesc
)
1201 : pkgAcqIndex(Owner
, URI
, URIDesc
, ShortDesc
, HashString(), "")
1204 pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire
*Owner
, IndexTarget
const *Target
,
1205 HashString
const &ExpectedHash
, indexRecords
const *MetaIndexParser
)
1206 : pkgAcqIndex(Owner
, Target
, ExpectedHash
, MetaIndexParser
)
1210 // AcqIndexTrans::Custom600Headers - Insert custom request headers /*{{{*/
1211 // ---------------------------------------------------------------------
1212 string
pkgAcqIndexTrans::Custom600Headers()
1214 std::string
const compExt
= CompressionExtension
.substr(0, CompressionExtension
.find(' '));
1215 string Final
= _config
->FindDir("Dir::State::lists");
1216 Final
+= URItoFileName(RealURI
);
1217 if (_config
->FindB("Acquire::GzipIndexes",false))
1221 if (stat(Final
.c_str(),&Buf
) != 0)
1222 return "\nFail-Ignore: true\nIndex-File: true";
1223 return "\nFail-Ignore: true\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1226 // AcqIndexTrans::Failed - Silence failure messages for missing files /*{{{*/
1227 // ---------------------------------------------------------------------
1229 void pkgAcqIndexTrans::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
1231 size_t const nextExt
= CompressionExtension
.find(' ');
1232 if (nextExt
!= std::string::npos
)
1234 CompressionExtension
= CompressionExtension
.substr(nextExt
+1);
1235 Init(RealURI
, Desc
.Description
, Desc
.ShortDesc
);
1240 if (Cnf
->LocalOnly
== true ||
1241 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == false)
1250 Item::Failed(Message
,Cnf
);
1253 pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire
*Owner
, /*{{{*/
1254 string URI
,string URIDesc
,string ShortDesc
,
1255 string MetaIndexURI
, string MetaIndexURIDesc
,
1256 string MetaIndexShortDesc
,
1257 const vector
<IndexTarget
*>* IndexTargets
,
1258 indexRecords
* MetaIndexParser
) :
1259 Item(Owner
), RealURI(URI
), MetaIndexURI(MetaIndexURI
),
1260 MetaIndexURIDesc(MetaIndexURIDesc
), MetaIndexShortDesc(MetaIndexShortDesc
),
1261 MetaIndexParser(MetaIndexParser
), IndexTargets(IndexTargets
)
1263 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
1264 DestFile
+= URItoFileName(URI
);
1266 // remove any partial downloaded sig-file in partial/.
1267 // it may confuse proxies and is too small to warrant a
1268 // partial download anyway
1269 unlink(DestFile
.c_str());
1272 Desc
.Description
= URIDesc
;
1274 Desc
.ShortDesc
= ShortDesc
;
1277 string Final
= _config
->FindDir("Dir::State::lists");
1278 Final
+= URItoFileName(RealURI
);
1279 if (RealFileExists(Final
) == true)
1281 // File was already in place. It needs to be re-downloaded/verified
1282 // because Release might have changed, we do give it a different
1283 // name than DestFile because otherwise the http method will
1284 // send If-Range requests and there are too many broken servers
1285 // out there that do not understand them
1286 LastGoodSig
= DestFile
+".reverify";
1287 Rename(Final
,LastGoodSig
);
1293 pkgAcqMetaSig::~pkgAcqMetaSig() /*{{{*/
1295 // if the file was never queued undo file-changes done in the constructor
1296 if (QueueCounter
== 1 && Status
== StatIdle
&& FileSize
== 0 && Complete
== false &&
1297 LastGoodSig
.empty() == false)
1299 string
const Final
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
1300 if (RealFileExists(Final
) == false && RealFileExists(LastGoodSig
) == true)
1301 Rename(LastGoodSig
, Final
);
1306 // pkgAcqMetaSig::Custom600Headers - Insert custom request headers /*{{{*/
1307 // ---------------------------------------------------------------------
1308 /* The only header we use is the last-modified header. */
1309 string
pkgAcqMetaSig::Custom600Headers()
1312 if (stat(LastGoodSig
.c_str(),&Buf
) != 0)
1313 return "\nIndex-File: true";
1315 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1318 void pkgAcqMetaSig::Done(string Message
,unsigned long long Size
,string MD5
,
1319 pkgAcquire::MethodConfig
*Cfg
)
1321 Item::Done(Message
,Size
,MD5
,Cfg
);
1323 string FileName
= LookupTag(Message
,"Filename");
1324 if (FileName
.empty() == true)
1327 ErrorText
= "Method gave a blank filename";
1331 if (FileName
!= DestFile
)
1333 // We have to copy it into place
1335 Desc
.URI
= "copy:" + FileName
;
1342 // put the last known good file back on i-m-s hit (it will
1343 // be re-verified again)
1344 // Else do nothing, we have the new file in DestFile then
1345 if(StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
1346 Rename(LastGoodSig
, DestFile
);
1348 // queue a pkgAcqMetaIndex to be verified against the sig we just retrieved
1349 new pkgAcqMetaIndex(Owner
, MetaIndexURI
, MetaIndexURIDesc
,
1350 MetaIndexShortDesc
, DestFile
, IndexTargets
,
1355 void pkgAcqMetaSig::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)/*{{{*/
1357 string Final
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
1359 // if we get a network error we fail gracefully
1360 if(Status
== StatTransientNetworkError
)
1362 Item::Failed(Message
,Cnf
);
1363 // move the sigfile back on transient network failures
1364 if(FileExists(LastGoodSig
))
1365 Rename(LastGoodSig
,Final
);
1367 // set the status back to , Item::Failed likes to reset it
1368 Status
= pkgAcquire::Item::StatTransientNetworkError
;
1372 // Delete any existing sigfile when the acquire failed
1373 unlink(Final
.c_str());
1375 // queue a pkgAcqMetaIndex with no sigfile
1376 new pkgAcqMetaIndex(Owner
, MetaIndexURI
, MetaIndexURIDesc
, MetaIndexShortDesc
,
1377 "", IndexTargets
, MetaIndexParser
);
1379 if (Cnf
->LocalOnly
== true ||
1380 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == false)
1389 Item::Failed(Message
,Cnf
);
1392 pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire
*Owner
, /*{{{*/
1393 string URI
,string URIDesc
,string ShortDesc
,
1395 const vector
<struct IndexTarget
*>* IndexTargets
,
1396 indexRecords
* MetaIndexParser
) :
1397 Item(Owner
), RealURI(URI
), SigFile(SigFile
), IndexTargets(IndexTargets
),
1398 MetaIndexParser(MetaIndexParser
), AuthPass(false), IMSHit(false)
1400 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
1401 DestFile
+= URItoFileName(URI
);
1404 Desc
.Description
= URIDesc
;
1406 Desc
.ShortDesc
= ShortDesc
;
1412 // pkgAcqMetaIndex::Custom600Headers - Insert custom request headers /*{{{*/
1413 // ---------------------------------------------------------------------
1414 /* The only header we use is the last-modified header. */
1415 string
pkgAcqMetaIndex::Custom600Headers()
1417 string Final
= _config
->FindDir("Dir::State::lists");
1418 Final
+= URItoFileName(RealURI
);
1421 if (stat(Final
.c_str(),&Buf
) != 0)
1422 return "\nIndex-File: true";
1424 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1427 void pkgAcqMetaIndex::Done(string Message
,unsigned long long Size
,string Hash
, /*{{{*/
1428 pkgAcquire::MethodConfig
*Cfg
)
1430 Item::Done(Message
,Size
,Hash
,Cfg
);
1432 // MetaIndexes are done in two passes: one to download the
1433 // metaindex with an appropriate method, and a second to verify it
1434 // with the gpgv method
1436 if (AuthPass
== true)
1440 // all cool, move Release file into place
1445 RetrievalDone(Message
);
1447 // Still more retrieving to do
1452 // There was no signature file, so we are finished. Download
1453 // the indexes and do only hashsum verification if possible
1454 MetaIndexParser
->Load(DestFile
);
1455 QueueIndexes(false);
1459 // There was a signature file, so pass it to gpgv for
1462 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1463 std::cerr
<< "Metaindex acquired, queueing gpg verification ("
1464 << SigFile
<< "," << DestFile
<< ")\n";
1466 Desc
.URI
= "gpgv:" + SigFile
;
1473 if (Complete
== true)
1475 string FinalFile
= _config
->FindDir("Dir::State::lists");
1476 FinalFile
+= URItoFileName(RealURI
);
1477 if (SigFile
== DestFile
)
1478 SigFile
= FinalFile
;
1479 Rename(DestFile
,FinalFile
);
1480 chmod(FinalFile
.c_str(),0644);
1481 DestFile
= FinalFile
;
1485 void pkgAcqMetaIndex::RetrievalDone(string Message
) /*{{{*/
1487 // We have just finished downloading a Release file (it is not
1490 string FileName
= LookupTag(Message
,"Filename");
1491 if (FileName
.empty() == true)
1494 ErrorText
= "Method gave a blank filename";
1498 if (FileName
!= DestFile
)
1501 Desc
.URI
= "copy:" + FileName
;
1506 // make sure to verify against the right file on I-M-S hit
1507 IMSHit
= StringToBool(LookupTag(Message
,"IMS-Hit"),false);
1510 string FinalFile
= _config
->FindDir("Dir::State::lists");
1511 FinalFile
+= URItoFileName(RealURI
);
1512 if (SigFile
== DestFile
)
1514 SigFile
= FinalFile
;
1515 // constructor of pkgAcqMetaClearSig moved it out of the way,
1516 // now move it back in on IMS hit for the 'old' file
1517 string
const OldClearSig
= DestFile
+ ".reverify";
1518 if (RealFileExists(OldClearSig
) == true)
1519 Rename(OldClearSig
, FinalFile
);
1521 DestFile
= FinalFile
;
1526 void pkgAcqMetaIndex::AuthDone(string Message
) /*{{{*/
1528 // At this point, the gpgv method has succeeded, so there is a
1529 // valid signature from a key in the trusted keyring. We
1530 // perform additional verification of its contents, and use them
1531 // to verify the indexes we are about to download
1533 if (!MetaIndexParser
->Load(DestFile
))
1535 Status
= StatAuthError
;
1536 ErrorText
= MetaIndexParser
->ErrorText
;
1540 if (!VerifyVendor(Message
))
1545 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1546 std::cerr
<< "Signature verification succeeded: "
1547 << DestFile
<< std::endl
;
1549 // do not trust any previously unverified content that we may have
1550 string LastGoodSigFile
= _config
->FindDir("Dir::State::lists").append("partial/").append(URItoFileName(RealURI
));
1551 if (DestFile
!= SigFile
)
1552 LastGoodSigFile
.append(".gpg");
1553 LastGoodSigFile
.append(".reverify");
1554 if(IMSHit
== false && RealFileExists(LastGoodSigFile
) == false)
1556 for (vector
<struct IndexTarget
*>::const_iterator Target
= IndexTargets
->begin();
1557 Target
!= IndexTargets
->end();
1560 // remove old indexes
1561 std::string index
= _config
->FindDir("Dir::State::lists") +
1562 URItoFileName((*Target
)->URI
);
1563 unlink(index
.c_str());
1564 // and also old gzipindexes
1565 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
1566 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
1568 index
+= '.' + (*t
);
1569 unlink(index
.c_str());
1575 // Download further indexes with verification
1578 // is it a clearsigned MetaIndex file?
1579 if (DestFile
== SigFile
)
1582 // Done, move signature file into position
1583 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
1584 URItoFileName(RealURI
) + ".gpg";
1585 Rename(SigFile
,VerifiedSigFile
);
1586 chmod(VerifiedSigFile
.c_str(),0644);
1589 void pkgAcqMetaIndex::QueueIndexes(bool verify
) /*{{{*/
1592 /* Reject invalid, existing Release files (LP: #346386) (Closes: #627642)
1593 * FIXME: Disabled; it breaks unsigned repositories without hashes */
1594 if (!verify
&& FileExists(DestFile
) && !MetaIndexParser
->Load(DestFile
))
1597 ErrorText
= MetaIndexParser
->ErrorText
;
1601 bool transInRelease
= false;
1603 std::vector
<std::string
> const keys
= MetaIndexParser
->MetaKeys();
1604 for (std::vector
<std::string
>::const_iterator k
= keys
.begin(); k
!= keys
.end(); ++k
)
1605 // FIXME: Feels wrong to check for hardcoded string here, but what should we do else…
1606 if (k
->find("Translation-") != std::string::npos
)
1608 transInRelease
= true;
1613 for (vector
<struct IndexTarget
*>::const_iterator Target
= IndexTargets
->begin();
1614 Target
!= IndexTargets
->end();
1617 HashString ExpectedIndexHash
;
1618 const indexRecords::checkSum
*Record
= MetaIndexParser
->Lookup((*Target
)->MetaKey
);
1619 bool compressedAvailable
= false;
1622 if ((*Target
)->IsOptional() == true)
1624 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
1625 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
1626 if (MetaIndexParser
->Exists((*Target
)->MetaKey
+ "." + *t
) == true)
1628 compressedAvailable
= true;
1632 else if (verify
== true)
1634 Status
= StatAuthError
;
1635 strprintf(ErrorText
, _("Unable to find expected entry '%s' in Release file (Wrong sources.list entry or malformed file)"), (*Target
)->MetaKey
.c_str());
1641 ExpectedIndexHash
= Record
->Hash
;
1642 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1644 std::cerr
<< "Queueing: " << (*Target
)->URI
<< std::endl
;
1645 std::cerr
<< "Expected Hash: " << ExpectedIndexHash
.toStr() << std::endl
;
1646 std::cerr
<< "For: " << Record
->MetaKeyFilename
<< std::endl
;
1648 if (verify
== true && ExpectedIndexHash
.empty() == true && (*Target
)->IsOptional() == false)
1650 Status
= StatAuthError
;
1651 strprintf(ErrorText
, _("Unable to find hash sum for '%s' in Release file"), (*Target
)->MetaKey
.c_str());
1656 if ((*Target
)->IsOptional() == true)
1658 if ((*Target
)->IsSubIndex() == true)
1659 new pkgAcqSubIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
1660 (*Target
)->ShortDesc
, ExpectedIndexHash
);
1661 else if (transInRelease
== false || Record
!= NULL
|| compressedAvailable
== true)
1663 if (_config
->FindB("Acquire::PDiffs",true) == true && transInRelease
== true &&
1664 MetaIndexParser
->Exists((*Target
)->MetaKey
+ ".diff/Index") == true)
1665 new pkgAcqDiffIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
1666 (*Target
)->ShortDesc
, ExpectedIndexHash
);
1668 new pkgAcqIndexTrans(Owner
, *Target
, ExpectedIndexHash
, MetaIndexParser
);
1673 /* Queue Packages file (either diff or full packages files, depending
1674 on the users option) - we also check if the PDiff Index file is listed
1675 in the Meta-Index file. Ideal would be if pkgAcqDiffIndex would test this
1676 instead, but passing the required info to it is to much hassle */
1677 if(_config
->FindB("Acquire::PDiffs",true) == true && (verify
== false ||
1678 MetaIndexParser
->Exists((*Target
)->MetaKey
+ ".diff/Index") == true))
1679 new pkgAcqDiffIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
1680 (*Target
)->ShortDesc
, ExpectedIndexHash
);
1682 new pkgAcqIndex(Owner
, *Target
, ExpectedIndexHash
, MetaIndexParser
);
1686 bool pkgAcqMetaIndex::VerifyVendor(string Message
) /*{{{*/
1688 string::size_type pos
;
1690 // check for missing sigs (that where not fatal because otherwise we had
1693 string msg
= _("There is no public key available for the "
1694 "following key IDs:\n");
1695 pos
= Message
.find("NO_PUBKEY ");
1696 if (pos
!= std::string::npos
)
1698 string::size_type start
= pos
+strlen("NO_PUBKEY ");
1699 string Fingerprint
= Message
.substr(start
, Message
.find("\n")-start
);
1700 missingkeys
+= (Fingerprint
);
1702 if(!missingkeys
.empty())
1703 _error
->Warning("%s", (msg
+ missingkeys
).c_str());
1705 string Transformed
= MetaIndexParser
->GetExpectedDist();
1707 if (Transformed
== "../project/experimental")
1709 Transformed
= "experimental";
1712 pos
= Transformed
.rfind('/');
1713 if (pos
!= string::npos
)
1715 Transformed
= Transformed
.substr(0, pos
);
1718 if (Transformed
== ".")
1723 if (_config
->FindB("Acquire::Check-Valid-Until", true) == true &&
1724 MetaIndexParser
->GetValidUntil() > 0) {
1725 time_t const invalid_since
= time(NULL
) - MetaIndexParser
->GetValidUntil();
1726 if (invalid_since
> 0)
1727 // TRANSLATOR: The first %s is the URL of the bad Release file, the second is
1728 // the time since then the file is invalid - formated in the same way as in
1729 // the download progress display (e.g. 7d 3h 42min 1s)
1730 return _error
->Error(
1731 _("Release file for %s is expired (invalid since %s). "
1732 "Updates for this repository will not be applied."),
1733 RealURI
.c_str(), TimeToStr(invalid_since
).c_str());
1736 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1738 std::cerr
<< "Got Codename: " << MetaIndexParser
->GetDist() << std::endl
;
1739 std::cerr
<< "Expecting Dist: " << MetaIndexParser
->GetExpectedDist() << std::endl
;
1740 std::cerr
<< "Transformed Dist: " << Transformed
<< std::endl
;
1743 if (MetaIndexParser
->CheckDist(Transformed
) == false)
1745 // This might become fatal one day
1746 // Status = StatAuthError;
1747 // ErrorText = "Conflicting distribution; expected "
1748 // + MetaIndexParser->GetExpectedDist() + " but got "
1749 // + MetaIndexParser->GetDist();
1751 if (!Transformed
.empty())
1753 _error
->Warning(_("Conflicting distribution: %s (expected %s but got %s)"),
1754 Desc
.Description
.c_str(),
1755 Transformed
.c_str(),
1756 MetaIndexParser
->GetDist().c_str());
1763 // pkgAcqMetaIndex::Failed - no Release file present or no signature file present /*{{{*/
1764 // ---------------------------------------------------------------------
1766 void pkgAcqMetaIndex::Failed(string Message
,pkgAcquire::MethodConfig
* /*Cnf*/)
1768 if (AuthPass
== true)
1770 // gpgv method failed, if we have a good signature
1771 string LastGoodSigFile
= _config
->FindDir("Dir::State::lists").append("partial/").append(URItoFileName(RealURI
));
1772 if (DestFile
!= SigFile
)
1773 LastGoodSigFile
.append(".gpg");
1774 LastGoodSigFile
.append(".reverify");
1776 if(FileExists(LastGoodSigFile
))
1778 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
1779 if (DestFile
!= SigFile
)
1780 VerifiedSigFile
.append(".gpg");
1781 Rename(LastGoodSigFile
, VerifiedSigFile
);
1782 Status
= StatTransientNetworkError
;
1783 _error
->Warning(_("An error occurred during the signature "
1784 "verification. The repository is not updated "
1785 "and the previous index files will be used. "
1786 "GPG error: %s: %s\n"),
1787 Desc
.Description
.c_str(),
1788 LookupTag(Message
,"Message").c_str());
1789 RunScripts("APT::Update::Auth-Failure");
1791 } else if (LookupTag(Message
,"Message").find("NODATA") != string::npos
) {
1792 /* Invalid signature file, reject (LP: #346386) (Closes: #627642) */
1793 _error
->Error(_("GPG error: %s: %s"),
1794 Desc
.Description
.c_str(),
1795 LookupTag(Message
,"Message").c_str());
1798 _error
->Warning(_("GPG error: %s: %s"),
1799 Desc
.Description
.c_str(),
1800 LookupTag(Message
,"Message").c_str());
1802 // gpgv method failed
1803 ReportMirrorFailure("GPGFailure");
1806 /* Always move the meta index, even if gpgv failed. This ensures
1807 * that PackageFile objects are correctly filled in */
1808 if (FileExists(DestFile
)) {
1809 string FinalFile
= _config
->FindDir("Dir::State::lists");
1810 FinalFile
+= URItoFileName(RealURI
);
1811 /* InRelease files become Release files, otherwise
1812 * they would be considered as trusted later on */
1813 if (SigFile
== DestFile
) {
1814 RealURI
= RealURI
.replace(RealURI
.rfind("InRelease"), 9,
1816 FinalFile
= FinalFile
.replace(FinalFile
.rfind("InRelease"), 9,
1818 SigFile
= FinalFile
;
1820 Rename(DestFile
,FinalFile
);
1821 chmod(FinalFile
.c_str(),0644);
1823 DestFile
= FinalFile
;
1826 // No Release file was present, or verification failed, so fall
1827 // back to queueing Packages files without verification
1828 QueueIndexes(false);
1831 pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire
*Owner
, /*{{{*/
1832 string
const &URI
, string
const &URIDesc
, string
const &ShortDesc
,
1833 string
const &MetaIndexURI
, string
const &MetaIndexURIDesc
, string
const &MetaIndexShortDesc
,
1834 string
const &MetaSigURI
, string
const &MetaSigURIDesc
, string
const &MetaSigShortDesc
,
1835 const vector
<struct IndexTarget
*>* IndexTargets
,
1836 indexRecords
* MetaIndexParser
) :
1837 pkgAcqMetaIndex(Owner
, URI
, URIDesc
, ShortDesc
, "", IndexTargets
, MetaIndexParser
),
1838 MetaIndexURI(MetaIndexURI
), MetaIndexURIDesc(MetaIndexURIDesc
), MetaIndexShortDesc(MetaIndexShortDesc
),
1839 MetaSigURI(MetaSigURI
), MetaSigURIDesc(MetaSigURIDesc
), MetaSigShortDesc(MetaSigShortDesc
)
1843 // keep the old InRelease around in case of transistent network errors
1844 string
const Final
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
1845 if (RealFileExists(Final
) == true)
1847 string
const LastGoodSig
= DestFile
+ ".reverify";
1848 Rename(Final
,LastGoodSig
);
1852 pkgAcqMetaClearSig::~pkgAcqMetaClearSig() /*{{{*/
1854 // if the file was never queued undo file-changes done in the constructor
1855 if (QueueCounter
== 1 && Status
== StatIdle
&& FileSize
== 0 && Complete
== false)
1857 string
const Final
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
1858 string
const LastGoodSig
= DestFile
+ ".reverify";
1859 if (RealFileExists(Final
) == false && RealFileExists(LastGoodSig
) == true)
1860 Rename(LastGoodSig
, Final
);
1864 // pkgAcqMetaClearSig::Custom600Headers - Insert custom request headers /*{{{*/
1865 // ---------------------------------------------------------------------
1866 // FIXME: this can go away once the InRelease file is used widely
1867 string
pkgAcqMetaClearSig::Custom600Headers()
1869 string Final
= _config
->FindDir("Dir::State::lists");
1870 Final
+= URItoFileName(RealURI
);
1873 if (stat(Final
.c_str(),&Buf
) != 0)
1875 Final
= DestFile
+ ".reverify";
1876 if (stat(Final
.c_str(),&Buf
) != 0)
1877 return "\nIndex-File: true\nFail-Ignore: true\n";
1880 return "\nIndex-File: true\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1883 void pkgAcqMetaClearSig::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
) /*{{{*/
1885 if (AuthPass
== false)
1887 // Remove the 'old' InRelease file if we try Release.gpg now as otherwise
1888 // the file will stay around and gives a false-auth impression (CVE-2012-0214)
1889 string FinalFile
= _config
->FindDir("Dir::State::lists");
1890 FinalFile
.append(URItoFileName(RealURI
));
1891 if (FileExists(FinalFile
))
1892 unlink(FinalFile
.c_str());
1894 new pkgAcqMetaSig(Owner
,
1895 MetaSigURI
, MetaSigURIDesc
, MetaSigShortDesc
,
1896 MetaIndexURI
, MetaIndexURIDesc
, MetaIndexShortDesc
,
1897 IndexTargets
, MetaIndexParser
);
1898 if (Cnf
->LocalOnly
== true ||
1899 StringToBool(LookupTag(Message
, "Transient-Failure"), false) == false)
1903 pkgAcqMetaIndex::Failed(Message
, Cnf
);
1906 // AcqArchive::AcqArchive - Constructor /*{{{*/
1907 // ---------------------------------------------------------------------
1908 /* This just sets up the initial fetch environment and queues the first
1910 pkgAcqArchive::pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
1911 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
1912 string
&StoreFilename
) :
1913 Item(Owner
), Version(Version
), Sources(Sources
), Recs(Recs
),
1914 StoreFilename(StoreFilename
), Vf(Version
.FileList()),
1917 Retries
= _config
->FindI("Acquire::Retries",0);
1919 if (Version
.Arch() == 0)
1921 _error
->Error(_("I wasn't able to locate a file for the %s package. "
1922 "This might mean you need to manually fix this package. "
1923 "(due to missing arch)"),
1924 Version
.ParentPkg().FullName().c_str());
1928 /* We need to find a filename to determine the extension. We make the
1929 assumption here that all the available sources for this version share
1930 the same extension.. */
1931 // Skip not source sources, they do not have file fields.
1932 for (; Vf
.end() == false; ++Vf
)
1934 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
1939 // Does not really matter here.. we are going to fail out below
1940 if (Vf
.end() != true)
1942 // If this fails to get a file name we will bomb out below.
1943 pkgRecords::Parser
&Parse
= Recs
->Lookup(Vf
);
1944 if (_error
->PendingError() == true)
1947 // Generate the final file name as: package_version_arch.foo
1948 StoreFilename
= QuoteString(Version
.ParentPkg().Name(),"_:") + '_' +
1949 QuoteString(Version
.VerStr(),"_:") + '_' +
1950 QuoteString(Version
.Arch(),"_:.") +
1951 "." + flExtension(Parse
.FileName());
1954 // check if we have one trusted source for the package. if so, switch
1955 // to "TrustedOnly" mode - but only if not in AllowUnauthenticated mode
1956 bool const allowUnauth
= _config
->FindB("APT::Get::AllowUnauthenticated", false);
1957 bool const debugAuth
= _config
->FindB("Debug::pkgAcquire::Auth", false);
1958 bool seenUntrusted
= false;
1959 for (pkgCache::VerFileIterator i
= Version
.FileList(); i
.end() == false; ++i
)
1961 pkgIndexFile
*Index
;
1962 if (Sources
->FindIndex(i
.File(),Index
) == false)
1965 if (debugAuth
== true)
1966 std::cerr
<< "Checking index: " << Index
->Describe()
1967 << "(Trusted=" << Index
->IsTrusted() << ")" << std::endl
;
1969 if (Index
->IsTrusted() == true)
1972 if (allowUnauth
== false)
1976 seenUntrusted
= true;
1979 // "allow-unauthenticated" restores apts old fetching behaviour
1980 // that means that e.g. unauthenticated file:// uris are higher
1981 // priority than authenticated http:// uris
1982 if (allowUnauth
== true && seenUntrusted
== true)
1986 if (QueueNext() == false && _error
->PendingError() == false)
1987 _error
->Error(_("Can't find a source to download version '%s' of '%s'"),
1988 Version
.VerStr(), Version
.ParentPkg().FullName(false).c_str());
1991 // AcqArchive::QueueNext - Queue the next file source /*{{{*/
1992 // ---------------------------------------------------------------------
1993 /* This queues the next available file version for download. It checks if
1994 the archive is already available in the cache and stashs the MD5 for
1996 bool pkgAcqArchive::QueueNext()
1998 string
const ForceHash
= _config
->Find("Acquire::ForceHash");
1999 for (; Vf
.end() == false; ++Vf
)
2001 // Ignore not source sources
2002 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
2005 // Try to cross match against the source list
2006 pkgIndexFile
*Index
;
2007 if (Sources
->FindIndex(Vf
.File(),Index
) == false)
2010 // only try to get a trusted package from another source if that source
2012 if(Trusted
&& !Index
->IsTrusted())
2015 // Grab the text package record
2016 pkgRecords::Parser
&Parse
= Recs
->Lookup(Vf
);
2017 if (_error
->PendingError() == true)
2020 string PkgFile
= Parse
.FileName();
2021 if (ForceHash
.empty() == false)
2023 if(stringcasecmp(ForceHash
, "sha512") == 0)
2024 ExpectedHash
= HashString("SHA512", Parse
.SHA512Hash());
2025 else if(stringcasecmp(ForceHash
, "sha256") == 0)
2026 ExpectedHash
= HashString("SHA256", Parse
.SHA256Hash());
2027 else if (stringcasecmp(ForceHash
, "sha1") == 0)
2028 ExpectedHash
= HashString("SHA1", Parse
.SHA1Hash());
2030 ExpectedHash
= HashString("MD5Sum", Parse
.MD5Hash());
2035 if ((Hash
= Parse
.SHA512Hash()).empty() == false)
2036 ExpectedHash
= HashString("SHA512", Hash
);
2037 else if ((Hash
= Parse
.SHA256Hash()).empty() == false)
2038 ExpectedHash
= HashString("SHA256", Hash
);
2039 else if ((Hash
= Parse
.SHA1Hash()).empty() == false)
2040 ExpectedHash
= HashString("SHA1", Hash
);
2042 ExpectedHash
= HashString("MD5Sum", Parse
.MD5Hash());
2044 if (PkgFile
.empty() == true)
2045 return _error
->Error(_("The package index files are corrupted. No Filename: "
2046 "field for package %s."),
2047 Version
.ParentPkg().Name());
2049 Desc
.URI
= Index
->ArchiveURI(PkgFile
);
2050 Desc
.Description
= Index
->ArchiveInfo(Version
);
2052 Desc
.ShortDesc
= Version
.ParentPkg().FullName(true);
2054 // See if we already have the file. (Legacy filenames)
2055 FileSize
= Version
->Size
;
2056 string FinalFile
= _config
->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile
);
2058 if (stat(FinalFile
.c_str(),&Buf
) == 0)
2060 // Make sure the size matches
2061 if ((unsigned long long)Buf
.st_size
== Version
->Size
)
2066 StoreFilename
= DestFile
= FinalFile
;
2070 /* Hmm, we have a file and its size does not match, this means it is
2071 an old style mismatched arch */
2072 unlink(FinalFile
.c_str());
2075 // Check it again using the new style output filenames
2076 FinalFile
= _config
->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename
);
2077 if (stat(FinalFile
.c_str(),&Buf
) == 0)
2079 // Make sure the size matches
2080 if ((unsigned long long)Buf
.st_size
== Version
->Size
)
2085 StoreFilename
= DestFile
= FinalFile
;
2089 /* Hmm, we have a file and its size does not match, this shouldn't
2091 unlink(FinalFile
.c_str());
2094 DestFile
= _config
->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(StoreFilename
);
2096 // Check the destination file
2097 if (stat(DestFile
.c_str(),&Buf
) == 0)
2099 // Hmm, the partial file is too big, erase it
2100 if ((unsigned long long)Buf
.st_size
> Version
->Size
)
2101 unlink(DestFile
.c_str());
2103 PartialSize
= Buf
.st_size
;
2106 // Disables download of archives - useful if no real installation follows,
2107 // e.g. if we are just interested in proposed installation order
2108 if (_config
->FindB("Debug::pkgAcqArchive::NoQueue", false) == true)
2113 StoreFilename
= DestFile
= FinalFile
;
2127 // AcqArchive::Done - Finished fetching /*{{{*/
2128 // ---------------------------------------------------------------------
2130 void pkgAcqArchive::Done(string Message
,unsigned long long Size
,string CalcHash
,
2131 pkgAcquire::MethodConfig
*Cfg
)
2133 Item::Done(Message
,Size
,CalcHash
,Cfg
);
2136 if (Size
!= Version
->Size
)
2138 RenameOnError(SizeMismatch
);
2143 if(ExpectedHash
.toStr() != CalcHash
)
2145 RenameOnError(HashSumMismatch
);
2149 // Grab the output filename
2150 string FileName
= LookupTag(Message
,"Filename");
2151 if (FileName
.empty() == true)
2154 ErrorText
= "Method gave a blank filename";
2160 // Reference filename
2161 if (FileName
!= DestFile
)
2163 StoreFilename
= DestFile
= FileName
;
2168 // Done, move it into position
2169 string FinalFile
= _config
->FindDir("Dir::Cache::Archives");
2170 FinalFile
+= flNotDir(StoreFilename
);
2171 Rename(DestFile
,FinalFile
);
2173 StoreFilename
= DestFile
= FinalFile
;
2177 // AcqArchive::Failed - Failure handler /*{{{*/
2178 // ---------------------------------------------------------------------
2179 /* Here we try other sources */
2180 void pkgAcqArchive::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
2182 ErrorText
= LookupTag(Message
,"Message");
2184 /* We don't really want to retry on failed media swaps, this prevents
2185 that. An interesting observation is that permanent failures are not
2187 if (Cnf
->Removable
== true &&
2188 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
2190 // Vf = Version.FileList();
2191 while (Vf
.end() == false) ++Vf
;
2192 StoreFilename
= string();
2193 Item::Failed(Message
,Cnf
);
2197 if (QueueNext() == false)
2199 // This is the retry counter
2201 Cnf
->LocalOnly
== false &&
2202 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
2205 Vf
= Version
.FileList();
2206 if (QueueNext() == true)
2210 StoreFilename
= string();
2211 Item::Failed(Message
,Cnf
);
2215 // AcqArchive::IsTrusted - Determine whether this archive comes from a trusted source /*{{{*/
2216 // ---------------------------------------------------------------------
2217 APT_PURE
bool pkgAcqArchive::IsTrusted()
2222 // AcqArchive::Finished - Fetching has finished, tidy up /*{{{*/
2223 // ---------------------------------------------------------------------
2225 void pkgAcqArchive::Finished()
2227 if (Status
== pkgAcquire::Item::StatDone
&&
2230 StoreFilename
= string();
2233 // AcqFile::pkgAcqFile - Constructor /*{{{*/
2234 // ---------------------------------------------------------------------
2235 /* The file is added to the queue */
2236 pkgAcqFile::pkgAcqFile(pkgAcquire
*Owner
,string URI
,string Hash
,
2237 unsigned long long Size
,string Dsc
,string ShortDesc
,
2238 const string
&DestDir
, const string
&DestFilename
,
2240 Item(Owner
), ExpectedHash(Hash
), IsIndexFile(IsIndexFile
)
2242 Retries
= _config
->FindI("Acquire::Retries",0);
2244 if(!DestFilename
.empty())
2245 DestFile
= DestFilename
;
2246 else if(!DestDir
.empty())
2247 DestFile
= DestDir
+ "/" + flNotDir(URI
);
2249 DestFile
= flNotDir(URI
);
2253 Desc
.Description
= Dsc
;
2256 // Set the short description to the archive component
2257 Desc
.ShortDesc
= ShortDesc
;
2259 // Get the transfer sizes
2262 if (stat(DestFile
.c_str(),&Buf
) == 0)
2264 // Hmm, the partial file is too big, erase it
2265 if ((Size
> 0) && (unsigned long long)Buf
.st_size
> Size
)
2266 unlink(DestFile
.c_str());
2268 PartialSize
= Buf
.st_size
;
2274 // AcqFile::Done - Item downloaded OK /*{{{*/
2275 // ---------------------------------------------------------------------
2277 void pkgAcqFile::Done(string Message
,unsigned long long Size
,string CalcHash
,
2278 pkgAcquire::MethodConfig
*Cnf
)
2280 Item::Done(Message
,Size
,CalcHash
,Cnf
);
2283 if(!ExpectedHash
.empty() && ExpectedHash
.toStr() != CalcHash
)
2285 RenameOnError(HashSumMismatch
);
2289 string FileName
= LookupTag(Message
,"Filename");
2290 if (FileName
.empty() == true)
2293 ErrorText
= "Method gave a blank filename";
2299 // The files timestamp matches
2300 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
2303 // We have to copy it into place
2304 if (FileName
!= DestFile
)
2307 if (_config
->FindB("Acquire::Source-Symlinks",true) == false ||
2308 Cnf
->Removable
== true)
2310 Desc
.URI
= "copy:" + FileName
;
2315 // Erase the file if it is a symlink so we can overwrite it
2317 if (lstat(DestFile
.c_str(),&St
) == 0)
2319 if (S_ISLNK(St
.st_mode
) != 0)
2320 unlink(DestFile
.c_str());
2324 if (symlink(FileName
.c_str(),DestFile
.c_str()) != 0)
2326 ErrorText
= "Link to " + DestFile
+ " failure ";
2333 // AcqFile::Failed - Failure handler /*{{{*/
2334 // ---------------------------------------------------------------------
2335 /* Here we try other sources */
2336 void pkgAcqFile::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
2338 ErrorText
= LookupTag(Message
,"Message");
2340 // This is the retry counter
2342 Cnf
->LocalOnly
== false &&
2343 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
2350 Item::Failed(Message
,Cnf
);
2353 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
2354 // ---------------------------------------------------------------------
2355 /* The only header we use is the last-modified header. */
2356 string
pkgAcqFile::Custom600Headers()
2359 return "\nIndex-File: true";