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),
59 ExpectedAdditionalItems(0)
65 // Acquire::Item::~Item - Destructor /*{{{*/
66 // ---------------------------------------------------------------------
68 pkgAcquire::Item::~Item()
73 // Acquire::Item::Failed - Item failed to download /*{{{*/
74 // ---------------------------------------------------------------------
75 /* We return to an idle state if there are still other queues that could
77 void pkgAcquire::Item::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
80 ErrorText
= LookupTag(Message
,"Message");
81 UsedMirror
= LookupTag(Message
,"UsedMirror");
82 if (QueueCounter
<= 1)
84 /* This indicates that the file is not available right now but might
85 be sometime later. If we do a retry cycle then this should be
87 if (Cnf
->LocalOnly
== true &&
88 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
99 // report mirror failure back to LP if we actually use a mirror
100 string FailReason
= LookupTag(Message
, "FailReason");
101 if(FailReason
.size() != 0)
102 ReportMirrorFailure(FailReason
);
104 ReportMirrorFailure(ErrorText
);
107 // Acquire::Item::Start - Item has begun to download /*{{{*/
108 // ---------------------------------------------------------------------
109 /* Stash status and the file size. Note that setting Complete means
110 sub-phases of the acquire process such as decompresion are operating */
111 void pkgAcquire::Item::Start(string
/*Message*/,unsigned long long Size
)
113 Status
= StatFetching
;
114 if (FileSize
== 0 && Complete
== false)
118 // Acquire::Item::Done - Item downloaded OK /*{{{*/
119 // ---------------------------------------------------------------------
121 void pkgAcquire::Item::Done(string Message
,unsigned long long Size
,string
/*Hash*/,
122 pkgAcquire::MethodConfig
* /*Cnf*/)
124 // We just downloaded something..
125 string FileName
= LookupTag(Message
,"Filename");
126 UsedMirror
= LookupTag(Message
,"UsedMirror");
127 if (Complete
== false && !Local
&& FileName
== DestFile
)
130 Owner
->Log
->Fetched(Size
,atoi(LookupTag(Message
,"Resume-Point","0").c_str()));
136 ErrorText
= string();
137 Owner
->Dequeue(this);
140 // Acquire::Item::Rename - Rename a file /*{{{*/
141 // ---------------------------------------------------------------------
142 /* This helper function is used by a lot of item methods as their final
144 void pkgAcquire::Item::Rename(string From
,string To
)
146 if (rename(From
.c_str(),To
.c_str()) != 0)
149 snprintf(S
,sizeof(S
),_("rename failed, %s (%s -> %s)."),strerror(errno
),
150 From
.c_str(),To
.c_str());
156 bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState
const error
)/*{{{*/
158 if(FileExists(DestFile
))
159 Rename(DestFile
, DestFile
+ ".FAILED");
163 case HashSumMismatch
:
164 ErrorText
= _("Hash Sum mismatch");
165 Status
= StatAuthError
;
166 ReportMirrorFailure("HashChecksumFailure");
169 ErrorText
= _("Size mismatch");
170 Status
= StatAuthError
;
171 ReportMirrorFailure("SizeFailure");
174 ErrorText
= _("Invalid file format");
176 // do not report as usually its not the mirrors fault, but Portal/Proxy
182 // Acquire::Item::ReportMirrorFailure /*{{{*/
183 // ---------------------------------------------------------------------
184 void pkgAcquire::Item::ReportMirrorFailure(string FailCode
)
186 // we only act if a mirror was used at all
187 if(UsedMirror
.empty())
190 std::cerr
<< "\nReportMirrorFailure: "
192 << " Uri: " << DescURI()
194 << FailCode
<< std::endl
;
196 const char *Args
[40];
198 string report
= _config
->Find("Methods::Mirror::ProblemReporting",
199 "/usr/lib/apt/apt-report-mirror-failure");
200 if(!FileExists(report
))
202 Args
[i
++] = report
.c_str();
203 Args
[i
++] = UsedMirror
.c_str();
204 Args
[i
++] = DescURI().c_str();
205 Args
[i
++] = FailCode
.c_str();
207 pid_t pid
= ExecFork();
210 _error
->Error("ReportMirrorFailure Fork failed");
215 execvp(Args
[0], (char**)Args
);
216 std::cerr
<< "Could not exec " << Args
[0] << std::endl
;
219 if(!ExecWait(pid
, "report-mirror-failure"))
221 _error
->Warning("Couldn't report problem to '%s'",
222 _config
->Find("Methods::Mirror::ProblemReporting").c_str());
226 // AcqSubIndex::AcqSubIndex - Constructor /*{{{*/
227 // ---------------------------------------------------------------------
228 /* Get a sub-index file based on checksums from a 'master' file and
229 possibly query additional files */
230 pkgAcqSubIndex::pkgAcqSubIndex(pkgAcquire
*Owner
, string
const &URI
,
231 string
const &URIDesc
, string
const &ShortDesc
,
232 HashString
const &ExpectedHash
)
233 : Item(Owner
), ExpectedHash(ExpectedHash
)
235 /* XXX: Beware: Currently this class does nothing (of value) anymore ! */
236 Debug
= _config
->FindB("Debug::pkgAcquire::SubIndex",false);
238 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
239 DestFile
+= URItoFileName(URI
);
242 Desc
.Description
= URIDesc
;
244 Desc
.ShortDesc
= ShortDesc
;
249 std::clog
<< "pkgAcqSubIndex: " << Desc
.URI
<< std::endl
;
252 // AcqSubIndex::Custom600Headers - Insert custom request headers /*{{{*/
253 // ---------------------------------------------------------------------
254 /* The only header we use is the last-modified header. */
255 string
pkgAcqSubIndex::Custom600Headers()
257 string Final
= _config
->FindDir("Dir::State::lists");
258 Final
+= URItoFileName(Desc
.URI
);
261 if (stat(Final
.c_str(),&Buf
) != 0)
262 return "\nIndex-File: true\nFail-Ignore: true\n";
263 return "\nIndex-File: true\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
266 void pkgAcqSubIndex::Failed(string Message
,pkgAcquire::MethodConfig
* /*Cnf*/)/*{{{*/
269 std::clog
<< "pkgAcqSubIndex failed: " << Desc
.URI
<< " with " << Message
<< std::endl
;
275 // No good Index is provided
278 void pkgAcqSubIndex::Done(string Message
,unsigned long long Size
,string Md5Hash
, /*{{{*/
279 pkgAcquire::MethodConfig
*Cnf
)
282 std::clog
<< "pkgAcqSubIndex::Done(): " << Desc
.URI
<< std::endl
;
284 string FileName
= LookupTag(Message
,"Filename");
285 if (FileName
.empty() == true)
288 ErrorText
= "Method gave a blank filename";
292 if (FileName
!= DestFile
)
295 Desc
.URI
= "copy:" + FileName
;
300 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
302 string FinalFile
= _config
->FindDir("Dir::State::lists")+URItoFileName(Desc
.URI
);
304 /* Downloaded invalid transindex => Error (LP: #346386) (Closes: #627642) */
305 indexRecords SubIndexParser
;
306 if (FileExists(DestFile
) == true && !SubIndexParser
.Load(DestFile
)) {
308 ErrorText
= SubIndexParser
.ErrorText
;
312 // success in downloading the index
315 std::clog
<< "Renaming: " << DestFile
<< " -> " << FinalFile
<< std::endl
;
316 Rename(DestFile
,FinalFile
);
317 chmod(FinalFile
.c_str(),0644);
318 DestFile
= FinalFile
;
320 if(ParseIndex(DestFile
) == false)
321 return Failed("", NULL
);
329 bool pkgAcqSubIndex::ParseIndex(string
const &IndexFile
) /*{{{*/
331 indexRecords SubIndexParser
;
332 if (FileExists(IndexFile
) == false || SubIndexParser
.Load(IndexFile
) == false)
334 // so something with the downloaded index
338 // AcqDiffIndex::AcqDiffIndex - Constructor /*{{{*/
339 // ---------------------------------------------------------------------
340 /* Get the DiffIndex file first and see if there are patches available
341 * If so, create a pkgAcqIndexDiffs fetcher that will get and apply the
342 * patches. If anything goes wrong in that process, it will fall back to
343 * the original packages file
345 pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire
*Owner
,
346 IndexTarget
const *Target
,
347 HashString ExpectedHash
,
348 indexRecords
*MetaIndexParser
)
349 : Item(Owner
), ExpectedHash(ExpectedHash
), Target(Target
),
350 MetaIndexParser(MetaIndexParser
)
354 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
356 RealURI
= Target
->URI
;
358 Desc
.Description
= Target
->Description
+ "/DiffIndex";
359 Desc
.ShortDesc
= Target
->ShortDesc
;
360 Desc
.URI
= Target
->URI
+ ".diff/Index";
362 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
363 DestFile
+= URItoFileName(Target
->URI
) + string(".DiffIndex");
366 std::clog
<< "pkgAcqDiffIndex: " << Desc
.URI
<< std::endl
;
368 // look for the current package file
369 CurrentPackagesFile
= _config
->FindDir("Dir::State::lists");
370 CurrentPackagesFile
+= URItoFileName(RealURI
);
372 // FIXME: this file:/ check is a hack to prevent fetching
373 // from local sources. this is really silly, and
374 // should be fixed cleanly as soon as possible
375 if(!FileExists(CurrentPackagesFile
) ||
376 Desc
.URI
.substr(0,strlen("file:/")) == "file:/")
378 // we don't have a pkg file or we don't want to queue
380 std::clog
<< "No index file, local or canceld by user" << std::endl
;
386 std::clog
<< "pkgAcqDiffIndex::pkgAcqDiffIndex(): "
387 << CurrentPackagesFile
<< std::endl
;
393 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
394 // ---------------------------------------------------------------------
395 /* The only header we use is the last-modified header. */
396 string
pkgAcqDiffIndex::Custom600Headers()
398 string Final
= _config
->FindDir("Dir::State::lists");
399 Final
+= URItoFileName(RealURI
) + string(".IndexDiff");
402 std::clog
<< "Custom600Header-IMS: " << Final
<< std::endl
;
405 if (stat(Final
.c_str(),&Buf
) != 0)
406 return "\nIndex-File: true";
408 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
411 bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile
) /*{{{*/
414 std::clog
<< "pkgAcqDiffIndex::ParseIndexDiff() " << IndexDiffFile
419 vector
<DiffInfo
> available_patches
;
421 FileFd
Fd(IndexDiffFile
,FileFd::ReadOnly
);
423 if (_error
->PendingError() == true)
426 if(TF
.Step(Tags
) == true)
432 string
const tmp
= Tags
.FindS("SHA1-Current");
433 std::stringstream
ss(tmp
);
434 ss
>> ServerSha1
>> size
;
435 unsigned long const ServerSize
= atol(size
.c_str());
437 FileFd
fd(CurrentPackagesFile
, FileFd::ReadOnly
);
440 string
const local_sha1
= SHA1
.Result();
442 if(local_sha1
== ServerSha1
)
444 // we have the same sha1 as the server so we are done here
446 std::clog
<< "Package file is up-to-date" << std::endl
;
447 // list cleanup needs to know that this file as well as the already
448 // present index is ours, so we create an empty diff to save it for us
449 new pkgAcqIndexDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
450 ExpectedHash
, ServerSha1
, available_patches
);
456 std::clog
<< "SHA1-Current: " << ServerSha1
<< " and we start at "<< fd
.Name() << " " << fd
.Size() << " " << local_sha1
<< std::endl
;
458 // check the historie and see what patches we need
459 string
const history
= Tags
.FindS("SHA1-History");
460 std::stringstream
hist(history
);
461 while(hist
>> d
.sha1
>> size
>> d
.file
)
463 // read until the first match is found
464 // from that point on, we probably need all diffs
465 if(d
.sha1
== local_sha1
)
467 else if (found
== false)
471 std::clog
<< "Need to get diff: " << d
.file
<< std::endl
;
472 available_patches
.push_back(d
);
475 if (available_patches
.empty() == false)
477 // patching with too many files is rather slow compared to a fast download
478 unsigned long const fileLimit
= _config
->FindI("Acquire::PDiffs::FileLimit", 0);
479 if (fileLimit
!= 0 && fileLimit
< available_patches
.size())
482 std::clog
<< "Need " << available_patches
.size() << " diffs (Limit is " << fileLimit
483 << ") so fallback to complete download" << std::endl
;
487 // see if the patches are too big
488 found
= false; // it was true and it will be true again at the end
489 d
= *available_patches
.begin();
490 string
const firstPatch
= d
.file
;
491 unsigned long patchesSize
= 0;
492 std::stringstream
patches(Tags
.FindS("SHA1-Patches"));
493 while(patches
>> d
.sha1
>> size
>> d
.file
)
495 if (firstPatch
== d
.file
)
497 else if (found
== false)
500 patchesSize
+= atol(size
.c_str());
502 unsigned long const sizeLimit
= ServerSize
* _config
->FindI("Acquire::PDiffs::SizeLimit", 100);
503 if (sizeLimit
> 0 && (sizeLimit
/100) < patchesSize
)
506 std::clog
<< "Need " << patchesSize
<< " bytes (Limit is " << sizeLimit
/100
507 << ") so fallback to complete download" << std::endl
;
513 // we have something, queue the next diff
517 string::size_type
const last_space
= Description
.rfind(" ");
518 if(last_space
!= string::npos
)
519 Description
.erase(last_space
, Description
.size()-last_space
);
521 /* decide if we should download patches one by one or in one go:
522 The first is good if the server merges patches, but many don't so client
523 based merging can be attempt in which case the second is better.
524 "bad things" will happen if patches are merged on the server,
525 but client side merging is attempt as well */
526 bool pdiff_merge
= _config
->FindB("Acquire::PDiffs::Merge", true);
527 if (pdiff_merge
== true)
529 // reprepro adds this flag if it has merged patches on the server
530 std::string
const precedence
= Tags
.FindS("X-Patch-Precedence");
531 pdiff_merge
= (precedence
!= "merged");
534 if (pdiff_merge
== false)
535 new pkgAcqIndexDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
536 ExpectedHash
, ServerSha1
, available_patches
);
539 std::vector
<pkgAcqIndexMergeDiffs
*> *diffs
= new std::vector
<pkgAcqIndexMergeDiffs
*>(available_patches
.size());
540 for(size_t i
= 0; i
< available_patches
.size(); ++i
)
541 (*diffs
)[i
] = new pkgAcqIndexMergeDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
, ExpectedHash
,
542 available_patches
[i
], diffs
);
552 // Nothing found, report and return false
553 // Failing here is ok, if we return false later, the full
554 // IndexFile is queued
556 std::clog
<< "Can't find a patch in the index file" << std::endl
;
560 void pkgAcqDiffIndex::Failed(string Message
,pkgAcquire::MethodConfig
* /*Cnf*/)/*{{{*/
563 std::clog
<< "pkgAcqDiffIndex failed: " << Desc
.URI
<< " with " << Message
<< std::endl
564 << "Falling back to normal index file acquire" << std::endl
;
566 new pkgAcqIndex(Owner
, Target
, ExpectedHash
, MetaIndexParser
);
573 void pkgAcqDiffIndex::Done(string Message
,unsigned long long Size
,string Md5Hash
, /*{{{*/
574 pkgAcquire::MethodConfig
*Cnf
)
577 std::clog
<< "pkgAcqDiffIndex::Done(): " << Desc
.URI
<< std::endl
;
579 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
582 FinalFile
= _config
->FindDir("Dir::State::lists")+URItoFileName(RealURI
);
584 // success in downloading the index
586 FinalFile
+= string(".IndexDiff");
588 std::clog
<< "Renaming: " << DestFile
<< " -> " << FinalFile
590 Rename(DestFile
,FinalFile
);
591 chmod(FinalFile
.c_str(),0644);
592 DestFile
= FinalFile
;
594 if(!ParseDiffIndex(DestFile
))
595 return Failed("", NULL
);
603 // AcqIndexDiffs::AcqIndexDiffs - Constructor /*{{{*/
604 // ---------------------------------------------------------------------
605 /* The package diff is added to the queue. one object is constructed
606 * for each diff and the index
608 pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire
*Owner
,
609 string URI
,string URIDesc
,string ShortDesc
,
610 HashString ExpectedHash
,
612 vector
<DiffInfo
> diffs
)
613 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
),
614 available_patches(diffs
), ServerSha1(ServerSha1
)
617 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
618 DestFile
+= URItoFileName(URI
);
620 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
622 Description
= URIDesc
;
624 Desc
.ShortDesc
= ShortDesc
;
626 if(available_patches
.empty() == true)
628 // we are done (yeah!)
634 State
= StateFetchDiff
;
639 void pkgAcqIndexDiffs::Failed(string Message
,pkgAcquire::MethodConfig
* /*Cnf*/)/*{{{*/
642 std::clog
<< "pkgAcqIndexDiffs failed: " << Desc
.URI
<< " with " << Message
<< std::endl
643 << "Falling back to normal index file acquire" << std::endl
;
644 new pkgAcqIndex(Owner
, RealURI
, Description
,Desc
.ShortDesc
,
649 // Finish - helper that cleans the item out of the fetcher queue /*{{{*/
650 void pkgAcqIndexDiffs::Finish(bool allDone
)
652 // we restore the original name, this is required, otherwise
653 // the file will be cleaned
656 DestFile
= _config
->FindDir("Dir::State::lists");
657 DestFile
+= URItoFileName(RealURI
);
659 if(!ExpectedHash
.empty() && !ExpectedHash
.VerifyFile(DestFile
))
661 RenameOnError(HashSumMismatch
);
666 // this is for the "real" finish
671 std::clog
<< "\n\nallDone: " << DestFile
<< "\n" << std::endl
;
676 std::clog
<< "Finishing: " << Desc
.URI
<< std::endl
;
683 bool pkgAcqIndexDiffs::QueueNextDiff() /*{{{*/
686 // calc sha1 of the just patched file
687 string FinalFile
= _config
->FindDir("Dir::State::lists");
688 FinalFile
+= URItoFileName(RealURI
);
690 FileFd
fd(FinalFile
, FileFd::ReadOnly
);
693 string local_sha1
= string(SHA1
.Result());
695 std::clog
<< "QueueNextDiff: "
696 << FinalFile
<< " (" << local_sha1
<< ")"<<std::endl
;
698 // final file reached before all patches are applied
699 if(local_sha1
== ServerSha1
)
705 // remove all patches until the next matching patch is found
706 // this requires the Index file to be ordered
707 for(vector
<DiffInfo
>::iterator I
=available_patches
.begin();
708 available_patches
.empty() == false &&
709 I
!= available_patches
.end() &&
710 I
->sha1
!= local_sha1
;
713 available_patches
.erase(I
);
716 // error checking and falling back if no patch was found
717 if(available_patches
.empty() == true)
723 // queue the right diff
724 Desc
.URI
= RealURI
+ ".diff/" + available_patches
[0].file
+ ".gz";
725 Desc
.Description
= Description
+ " " + available_patches
[0].file
+ string(".pdiff");
726 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
727 DestFile
+= URItoFileName(RealURI
+ ".diff/" + available_patches
[0].file
);
730 std::clog
<< "pkgAcqIndexDiffs::QueueNextDiff(): " << Desc
.URI
<< std::endl
;
737 void pkgAcqIndexDiffs::Done(string Message
,unsigned long long Size
,string Md5Hash
, /*{{{*/
738 pkgAcquire::MethodConfig
*Cnf
)
741 std::clog
<< "pkgAcqIndexDiffs::Done(): " << Desc
.URI
<< std::endl
;
743 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
746 FinalFile
= _config
->FindDir("Dir::State::lists")+URItoFileName(RealURI
);
748 // success in downloading a diff, enter ApplyDiff state
749 if(State
== StateFetchDiff
)
752 // rred excepts the patch as $FinalFile.ed
753 Rename(DestFile
,FinalFile
+".ed");
756 std::clog
<< "Sending to rred method: " << FinalFile
<< std::endl
;
758 State
= StateApplyDiff
;
760 Desc
.URI
= "rred:" + FinalFile
;
767 // success in download/apply a diff, queue next (if needed)
768 if(State
== StateApplyDiff
)
770 // remove the just applied patch
771 available_patches
.erase(available_patches
.begin());
772 unlink((FinalFile
+ ".ed").c_str());
777 std::clog
<< "Moving patched file in place: " << std::endl
778 << DestFile
<< " -> " << FinalFile
<< std::endl
;
780 Rename(DestFile
,FinalFile
);
781 chmod(FinalFile
.c_str(),0644);
783 // see if there is more to download
784 if(available_patches
.empty() == false) {
785 new pkgAcqIndexDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
786 ExpectedHash
, ServerSha1
, available_patches
);
793 // AcqIndexMergeDiffs::AcqIndexMergeDiffs - Constructor /*{{{*/
794 pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire
*Owner
,
795 string
const &URI
, string
const &URIDesc
,
796 string
const &ShortDesc
, HashString
const &ExpectedHash
,
797 DiffInfo
const &patch
,
798 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
)
799 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
),
800 patch(patch
),allPatches(allPatches
), State(StateFetchDiff
)
803 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
804 DestFile
+= URItoFileName(URI
);
806 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
808 Description
= URIDesc
;
810 Desc
.ShortDesc
= ShortDesc
;
812 Desc
.URI
= RealURI
+ ".diff/" + patch
.file
+ ".gz";
813 Desc
.Description
= Description
+ " " + patch
.file
+ string(".pdiff");
814 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
815 DestFile
+= URItoFileName(RealURI
+ ".diff/" + patch
.file
);
818 std::clog
<< "pkgAcqIndexMergeDiffs: " << Desc
.URI
<< std::endl
;
823 void pkgAcqIndexMergeDiffs::Failed(string Message
,pkgAcquire::MethodConfig
* /*Cnf*/)/*{{{*/
826 std::clog
<< "pkgAcqIndexMergeDiffs failed: " << Desc
.URI
<< " with " << Message
<< std::endl
;
831 // check if we are the first to fail, otherwise we are done here
832 State
= StateDoneDiff
;
833 for (std::vector
<pkgAcqIndexMergeDiffs
*>::const_iterator I
= allPatches
->begin();
834 I
!= allPatches
->end(); ++I
)
835 if ((*I
)->State
== StateErrorDiff
)
838 // first failure means we should fallback
839 State
= StateErrorDiff
;
840 std::clog
<< "Falling back to normal index file acquire" << std::endl
;
841 new pkgAcqIndex(Owner
, RealURI
, Description
,Desc
.ShortDesc
,
845 void pkgAcqIndexMergeDiffs::Done(string Message
,unsigned long long Size
,string Md5Hash
, /*{{{*/
846 pkgAcquire::MethodConfig
*Cnf
)
849 std::clog
<< "pkgAcqIndexMergeDiffs::Done(): " << Desc
.URI
<< std::endl
;
851 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
853 string
const FinalFile
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
855 if (State
== StateFetchDiff
)
857 // rred expects the patch as $FinalFile.ed.$patchname.gz
858 Rename(DestFile
, FinalFile
+ ".ed." + patch
.file
+ ".gz");
860 // check if this is the last completed diff
861 State
= StateDoneDiff
;
862 for (std::vector
<pkgAcqIndexMergeDiffs
*>::const_iterator I
= allPatches
->begin();
863 I
!= allPatches
->end(); ++I
)
864 if ((*I
)->State
!= StateDoneDiff
)
867 std::clog
<< "Not the last done diff in the batch: " << Desc
.URI
<< std::endl
;
871 // this is the last completed diff, so we are ready to apply now
872 State
= StateApplyDiff
;
875 std::clog
<< "Sending to rred method: " << FinalFile
<< std::endl
;
878 Desc
.URI
= "rred:" + FinalFile
;
883 // success in download/apply all diffs, clean up
884 else if (State
== StateApplyDiff
)
886 // see if we really got the expected file
887 if(!ExpectedHash
.empty() && !ExpectedHash
.VerifyFile(DestFile
))
889 RenameOnError(HashSumMismatch
);
893 // move the result into place
895 std::clog
<< "Moving patched file in place: " << std::endl
896 << DestFile
<< " -> " << FinalFile
<< std::endl
;
897 Rename(DestFile
, FinalFile
);
898 chmod(FinalFile
.c_str(), 0644);
900 // otherwise lists cleanup will eat the file
901 DestFile
= FinalFile
;
903 // ensure the ed's are gone regardless of list-cleanup
904 for (std::vector
<pkgAcqIndexMergeDiffs
*>::const_iterator I
= allPatches
->begin();
905 I
!= allPatches
->end(); ++I
)
907 std::string patch
= FinalFile
+ ".ed." + (*I
)->patch
.file
+ ".gz";
908 unlink(patch
.c_str());
914 std::clog
<< "allDone: " << DestFile
<< "\n" << std::endl
;
918 // AcqIndex::AcqIndex - Constructor /*{{{*/
919 // ---------------------------------------------------------------------
920 /* The package file is added to the queue and a second class is
921 instantiated to fetch the revision file */
922 pkgAcqIndex::pkgAcqIndex(pkgAcquire
*Owner
,
923 string URI
,string URIDesc
,string ShortDesc
,
924 HashString ExpectedHash
, string comprExt
)
925 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
), Target(0),
928 if(comprExt
.empty() == true)
930 // autoselect the compression method
931 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
932 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
933 comprExt
.append(*t
).append(" ");
934 if (comprExt
.empty() == false)
935 comprExt
.erase(comprExt
.end()-1);
937 CompressionExtension
= comprExt
;
941 Init(URI
, URIDesc
, ShortDesc
);
943 pkgAcqIndex::pkgAcqIndex(pkgAcquire
*Owner
, IndexTarget
const *Target
,
944 HashString
const &ExpectedHash
, indexRecords
*MetaIndexParser
)
945 : Item(Owner
), RealURI(Target
->URI
), ExpectedHash(ExpectedHash
)
947 // autoselect the compression method
948 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
949 CompressionExtension
= "";
950 if (ExpectedHash
.empty() == false)
952 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
953 if (*t
== "uncompressed" || MetaIndexParser
->Exists(string(Target
->MetaKey
).append(".").append(*t
)) == true)
954 CompressionExtension
.append(*t
).append(" ");
958 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
959 CompressionExtension
.append(*t
).append(" ");
961 if (CompressionExtension
.empty() == false)
962 CompressionExtension
.erase(CompressionExtension
.end()-1);
964 // only verify non-optional targets, see acquire-item.h for a FIXME
965 // to make this more flexible
966 if (Target
->IsOptional())
971 // we need this in Init()
972 this->Target
= Target
;
973 this->MetaIndexParser
= MetaIndexParser
;
975 Init(Target
->URI
, Target
->Description
, Target
->ShortDesc
);
978 // AcqIndex::Init - defered Constructor /*{{{*/
979 void pkgAcqIndex::Init(string
const &URI
, string
const &URIDesc
, string
const &ShortDesc
) {
980 Decompression
= false;
983 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
984 DestFile
+= URItoFileName(URI
);
986 std::string
const comprExt
= CompressionExtension
.substr(0, CompressionExtension
.find(' '));
988 if (comprExt
== "uncompressed")
992 MetaKey
= string(Target
->MetaKey
);
996 Desc
.URI
= URI
+ '.' + comprExt
;
998 MetaKey
= string(Target
->MetaKey
) + '.' + comprExt
;
1001 // load the filesize
1004 indexRecords::checkSum
*Record
= MetaIndexParser
->Lookup(MetaKey
);
1006 FileSize
= Record
->Size
;
1009 Desc
.Description
= URIDesc
;
1011 Desc
.ShortDesc
= ShortDesc
;
1016 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
1017 // ---------------------------------------------------------------------
1018 /* The only header we use is the last-modified header. */
1019 string
pkgAcqIndex::Custom600Headers()
1021 string Final
= _config
->FindDir("Dir::State::lists");
1022 Final
+= URItoFileName(RealURI
);
1023 if (_config
->FindB("Acquire::GzipIndexes",false))
1026 string msg
= "\nIndex-File: true";
1027 // FIXME: this really should use "IndexTarget::IsOptional()" but that
1028 // seems to be difficult without breaking ABI
1029 if (ShortDesc().find("Translation") != 0)
1030 msg
+= "\nFail-Ignore: true";
1032 if (stat(Final
.c_str(),&Buf
) == 0)
1033 msg
+= "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1038 void pkgAcqIndex::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
) /*{{{*/
1040 size_t const nextExt
= CompressionExtension
.find(' ');
1041 if (nextExt
!= std::string::npos
)
1043 CompressionExtension
= CompressionExtension
.substr(nextExt
+1);
1044 Init(RealURI
, Desc
.Description
, Desc
.ShortDesc
);
1048 // on decompression failure, remove bad versions in partial/
1049 if (Decompression
&& Erase
) {
1050 string s
= _config
->FindDir("Dir::State::lists") + "partial/";
1051 s
.append(URItoFileName(RealURI
));
1055 Item::Failed(Message
,Cnf
);
1058 // AcqIndex::Done - Finished a fetch /*{{{*/
1059 // ---------------------------------------------------------------------
1060 /* This goes through a number of states.. On the initial fetch the
1061 method could possibly return an alternate filename which points
1062 to the uncompressed version of the file. If this is so the file
1063 is copied into the partial directory. In all other cases the file
1064 is decompressed with a gzip uri. */
1065 void pkgAcqIndex::Done(string Message
,unsigned long long Size
,string Hash
,
1066 pkgAcquire::MethodConfig
*Cfg
)
1068 Item::Done(Message
,Size
,Hash
,Cfg
);
1070 if (Decompression
== true)
1072 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1074 std::cerr
<< std::endl
<< RealURI
<< ": Computed Hash: " << Hash
;
1075 std::cerr
<< " Expected Hash: " << ExpectedHash
.toStr() << std::endl
;
1078 if (!ExpectedHash
.empty() && ExpectedHash
.toStr() != Hash
)
1080 RenameOnError(HashSumMismatch
);
1084 /* Verify the index file for correctness (all indexes must
1085 * have a Package field) (LP: #346386) (Closes: #627642) */
1088 FileFd
fd(DestFile
, FileFd::ReadOnly
);
1089 // Only test for correctness if the file is not empty (empty is ok)
1090 if (fd
.FileSize() > 0)
1093 pkgTagFile
tag(&fd
);
1095 // all our current indexes have a field 'Package' in each section
1096 if (_error
->PendingError() == true || tag
.Step(sec
) == false || sec
.Exists("Package") == false)
1098 RenameOnError(InvalidFormat
);
1104 // Done, move it into position
1105 string FinalFile
= _config
->FindDir("Dir::State::lists");
1106 FinalFile
+= URItoFileName(RealURI
);
1107 Rename(DestFile
,FinalFile
);
1108 chmod(FinalFile
.c_str(),0644);
1110 /* We restore the original name to DestFile so that the clean operation
1112 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
1113 DestFile
+= URItoFileName(RealURI
);
1115 // Remove the compressed version.
1117 unlink(DestFile
.c_str());
1125 // Handle the unzipd case
1126 string FileName
= LookupTag(Message
,"Alt-Filename");
1127 if (FileName
.empty() == false)
1129 // The files timestamp matches
1130 if (StringToBool(LookupTag(Message
,"Alt-IMS-Hit"),false) == true)
1132 Decompression
= true;
1134 DestFile
+= ".decomp";
1135 Desc
.URI
= "copy:" + FileName
;
1141 FileName
= LookupTag(Message
,"Filename");
1142 if (FileName
.empty() == true)
1145 ErrorText
= "Method gave a blank filename";
1148 std::string
const compExt
= CompressionExtension
.substr(0, CompressionExtension
.find(' '));
1150 // The files timestamp matches
1151 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true) {
1152 if (_config
->FindB("Acquire::GzipIndexes",false) && compExt
== "gz")
1153 // Update DestFile for .gz suffix so that the clean operation keeps it
1158 if (FileName
== DestFile
)
1165 // If we enable compressed indexes and already have gzip, keep it
1166 if (_config
->FindB("Acquire::GzipIndexes",false) && compExt
== "gz" && !Local
) {
1167 string FinalFile
= _config
->FindDir("Dir::State::lists");
1168 FinalFile
+= URItoFileName(RealURI
) + ".gz";
1169 Rename(DestFile
,FinalFile
);
1170 chmod(FinalFile
.c_str(),0644);
1172 // Update DestFile for .gz suffix so that the clean operation keeps it
1173 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
1174 DestFile
+= URItoFileName(RealURI
) + ".gz";
1178 // get the binary name for your used compression type
1179 decompProg
= _config
->Find(string("Acquire::CompressionTypes::").append(compExt
),"");
1180 if(decompProg
.empty() == false);
1181 else if(compExt
== "uncompressed")
1182 decompProg
= "copy";
1184 _error
->Error("Unsupported extension: %s", compExt
.c_str());
1188 Decompression
= true;
1189 DestFile
+= ".decomp";
1190 Desc
.URI
= decompProg
+ ":" + FileName
;
1193 // FIXME: this points to a c++ string that goes out of scope
1194 Mode
= decompProg
.c_str();
1197 // AcqIndexTrans::pkgAcqIndexTrans - Constructor /*{{{*/
1198 // ---------------------------------------------------------------------
1199 /* The Translation file is added to the queue */
1200 pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire
*Owner
,
1201 string URI
,string URIDesc
,string ShortDesc
)
1202 : pkgAcqIndex(Owner
, URI
, URIDesc
, ShortDesc
, HashString(), "")
1205 pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire
*Owner
, IndexTarget
const *Target
,
1206 HashString
const &ExpectedHash
, indexRecords
*MetaIndexParser
)
1207 : pkgAcqIndex(Owner
, Target
, ExpectedHash
, MetaIndexParser
)
1209 // load the filesize
1210 indexRecords::checkSum
*Record
= MetaIndexParser
->Lookup(string(Target
->MetaKey
));
1212 FileSize
= Record
->Size
;
1215 // AcqIndexTrans::Custom600Headers - Insert custom request headers /*{{{*/
1216 // ---------------------------------------------------------------------
1217 string
pkgAcqIndexTrans::Custom600Headers()
1219 string Final
= _config
->FindDir("Dir::State::lists");
1220 Final
+= URItoFileName(RealURI
);
1223 if (stat(Final
.c_str(),&Buf
) != 0)
1224 return "\nFail-Ignore: true\nIndex-File: true";
1225 return "\nFail-Ignore: true\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1228 // AcqIndexTrans::Failed - Silence failure messages for missing files /*{{{*/
1229 // ---------------------------------------------------------------------
1231 void pkgAcqIndexTrans::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
1233 size_t const nextExt
= CompressionExtension
.find(' ');
1234 if (nextExt
!= std::string::npos
)
1236 CompressionExtension
= CompressionExtension
.substr(nextExt
+1);
1237 Init(RealURI
, Desc
.Description
, Desc
.ShortDesc
);
1242 if (Cnf
->LocalOnly
== true ||
1243 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == false)
1252 Item::Failed(Message
,Cnf
);
1255 pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire
*Owner
, /*{{{*/
1256 string URI
,string URIDesc
,string ShortDesc
,
1257 string MetaIndexURI
, string MetaIndexURIDesc
,
1258 string MetaIndexShortDesc
,
1259 const vector
<IndexTarget
*>* IndexTargets
,
1260 indexRecords
* MetaIndexParser
) :
1261 Item(Owner
), RealURI(URI
), MetaIndexURI(MetaIndexURI
),
1262 MetaIndexURIDesc(MetaIndexURIDesc
), MetaIndexShortDesc(MetaIndexShortDesc
),
1263 MetaIndexParser(MetaIndexParser
), IndexTargets(IndexTargets
)
1265 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
1266 DestFile
+= URItoFileName(URI
);
1268 // remove any partial downloaded sig-file in partial/.
1269 // it may confuse proxies and is too small to warrant a
1270 // partial download anyway
1271 unlink(DestFile
.c_str());
1274 Desc
.Description
= URIDesc
;
1276 Desc
.ShortDesc
= ShortDesc
;
1279 string Final
= _config
->FindDir("Dir::State::lists");
1280 Final
+= URItoFileName(RealURI
);
1281 if (RealFileExists(Final
) == true)
1283 // File was already in place. It needs to be re-downloaded/verified
1284 // because Release might have changed, we do give it a different
1285 // name than DestFile because otherwise the http method will
1286 // send If-Range requests and there are too many broken servers
1287 // out there that do not understand them
1288 LastGoodSig
= DestFile
+".reverify";
1289 Rename(Final
,LastGoodSig
);
1292 // we expect the indextargets + one additional Release file
1293 ExpectedAdditionalItems
= IndexTargets
->size() + 1;
1298 pkgAcqMetaSig::~pkgAcqMetaSig() /*{{{*/
1300 // if the file was never queued undo file-changes done in the constructor
1301 if (QueueCounter
== 1 && Status
== StatIdle
&& FileSize
== 0 && Complete
== false &&
1302 LastGoodSig
.empty() == false)
1304 string
const Final
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
1305 if (RealFileExists(Final
) == false && RealFileExists(LastGoodSig
) == true)
1306 Rename(LastGoodSig
, Final
);
1311 // pkgAcqMetaSig::Custom600Headers - Insert custom request headers /*{{{*/
1312 // ---------------------------------------------------------------------
1313 /* The only header we use is the last-modified header. */
1314 string
pkgAcqMetaSig::Custom600Headers()
1317 if (stat(LastGoodSig
.c_str(),&Buf
) != 0)
1318 return "\nIndex-File: true";
1320 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1323 void pkgAcqMetaSig::Done(string Message
,unsigned long long Size
,string MD5
,
1324 pkgAcquire::MethodConfig
*Cfg
)
1326 Item::Done(Message
,Size
,MD5
,Cfg
);
1328 string FileName
= LookupTag(Message
,"Filename");
1329 if (FileName
.empty() == true)
1332 ErrorText
= "Method gave a blank filename";
1336 if (FileName
!= DestFile
)
1338 // We have to copy it into place
1340 Desc
.URI
= "copy:" + FileName
;
1347 // at this point pkgAcqMetaIndex takes over
1348 ExpectedAdditionalItems
= 0;
1350 // put the last known good file back on i-m-s hit (it will
1351 // be re-verified again)
1352 // Else do nothing, we have the new file in DestFile then
1353 if(StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
1354 Rename(LastGoodSig
, DestFile
);
1356 // queue a pkgAcqMetaIndex to be verified against the sig we just retrieved
1357 new pkgAcqMetaIndex(Owner
, MetaIndexURI
, MetaIndexURIDesc
,
1358 MetaIndexShortDesc
, DestFile
, IndexTargets
,
1363 void pkgAcqMetaSig::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)/*{{{*/
1365 string Final
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
1367 // at this point pkgAcqMetaIndex takes over
1368 ExpectedAdditionalItems
= 0;
1370 // if we get a network error we fail gracefully
1371 if(Status
== StatTransientNetworkError
)
1373 Item::Failed(Message
,Cnf
);
1374 // move the sigfile back on transient network failures
1375 if(FileExists(LastGoodSig
))
1376 Rename(LastGoodSig
,Final
);
1378 // set the status back to , Item::Failed likes to reset it
1379 Status
= pkgAcquire::Item::StatTransientNetworkError
;
1383 // Delete any existing sigfile when the acquire failed
1384 unlink(Final
.c_str());
1386 // queue a pkgAcqMetaIndex with no sigfile
1387 new pkgAcqMetaIndex(Owner
, MetaIndexURI
, MetaIndexURIDesc
, MetaIndexShortDesc
,
1388 "", IndexTargets
, MetaIndexParser
);
1390 if (Cnf
->LocalOnly
== true ||
1391 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == false)
1400 Item::Failed(Message
,Cnf
);
1403 pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire
*Owner
, /*{{{*/
1404 string URI
,string URIDesc
,string ShortDesc
,
1406 const vector
<struct IndexTarget
*>* IndexTargets
,
1407 indexRecords
* MetaIndexParser
) :
1408 Item(Owner
), RealURI(URI
), SigFile(SigFile
), IndexTargets(IndexTargets
),
1409 MetaIndexParser(MetaIndexParser
), AuthPass(false), IMSHit(false)
1411 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
1412 DestFile
+= URItoFileName(URI
);
1415 Desc
.Description
= URIDesc
;
1417 Desc
.ShortDesc
= ShortDesc
;
1420 // we expect more item
1421 ExpectedAdditionalItems
= IndexTargets
->size();
1426 // pkgAcqMetaIndex::Custom600Headers - Insert custom request headers /*{{{*/
1427 // ---------------------------------------------------------------------
1428 /* The only header we use is the last-modified header. */
1429 string
pkgAcqMetaIndex::Custom600Headers()
1431 string Final
= _config
->FindDir("Dir::State::lists");
1432 Final
+= URItoFileName(RealURI
);
1435 if (stat(Final
.c_str(),&Buf
) != 0)
1436 return "\nIndex-File: true";
1438 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1441 void pkgAcqMetaIndex::Done(string Message
,unsigned long long Size
,string Hash
, /*{{{*/
1442 pkgAcquire::MethodConfig
*Cfg
)
1444 Item::Done(Message
,Size
,Hash
,Cfg
);
1446 // MetaIndexes are done in two passes: one to download the
1447 // metaindex with an appropriate method, and a second to verify it
1448 // with the gpgv method
1450 if (AuthPass
== true)
1454 // all cool, move Release file into place
1459 RetrievalDone(Message
);
1461 // Still more retrieving to do
1466 // There was no signature file, so we are finished. Download
1467 // the indexes and do only hashsum verification if possible
1468 MetaIndexParser
->Load(DestFile
);
1469 QueueIndexes(false);
1473 // FIXME: move this into pkgAcqMetaClearSig::Done on the next
1476 // if we expect a ClearTextSignature (InRelase), ensure that
1477 // this is what we get and if not fail to queue a
1478 // Release/Release.gpg, see #346386
1479 if (SigFile
== DestFile
&& !StartsWithGPGClearTextSignature(DestFile
))
1481 Failed(Message
, Cfg
);
1485 // There was a signature file, so pass it to gpgv for
1487 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1488 std::cerr
<< "Metaindex acquired, queueing gpg verification ("
1489 << SigFile
<< "," << DestFile
<< ")\n";
1491 Desc
.URI
= "gpgv:" + SigFile
;
1498 if (Complete
== true)
1500 string FinalFile
= _config
->FindDir("Dir::State::lists");
1501 FinalFile
+= URItoFileName(RealURI
);
1502 if (SigFile
== DestFile
)
1503 SigFile
= FinalFile
;
1504 Rename(DestFile
,FinalFile
);
1505 chmod(FinalFile
.c_str(),0644);
1506 DestFile
= FinalFile
;
1510 void pkgAcqMetaIndex::RetrievalDone(string Message
) /*{{{*/
1512 // We have just finished downloading a Release file (it is not
1515 string FileName
= LookupTag(Message
,"Filename");
1516 if (FileName
.empty() == true)
1519 ErrorText
= "Method gave a blank filename";
1523 if (FileName
!= DestFile
)
1526 Desc
.URI
= "copy:" + FileName
;
1531 // make sure to verify against the right file on I-M-S hit
1532 IMSHit
= StringToBool(LookupTag(Message
,"IMS-Hit"),false);
1535 string FinalFile
= _config
->FindDir("Dir::State::lists");
1536 FinalFile
+= URItoFileName(RealURI
);
1537 if (SigFile
== DestFile
)
1539 SigFile
= FinalFile
;
1540 // constructor of pkgAcqMetaClearSig moved it out of the way,
1541 // now move it back in on IMS hit for the 'old' file
1542 string
const OldClearSig
= DestFile
+ ".reverify";
1543 if (RealFileExists(OldClearSig
) == true)
1544 Rename(OldClearSig
, FinalFile
);
1546 DestFile
= FinalFile
;
1551 void pkgAcqMetaIndex::AuthDone(string Message
) /*{{{*/
1553 // At this point, the gpgv method has succeeded, so there is a
1554 // valid signature from a key in the trusted keyring. We
1555 // perform additional verification of its contents, and use them
1556 // to verify the indexes we are about to download
1558 if (!MetaIndexParser
->Load(DestFile
))
1560 Status
= StatAuthError
;
1561 ErrorText
= MetaIndexParser
->ErrorText
;
1565 if (!VerifyVendor(Message
))
1570 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1571 std::cerr
<< "Signature verification succeeded: "
1572 << DestFile
<< std::endl
;
1574 // Download further indexes with verification
1577 // is it a clearsigned MetaIndex file?
1578 if (DestFile
== SigFile
)
1581 // Done, move signature file into position
1582 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
1583 URItoFileName(RealURI
) + ".gpg";
1584 Rename(SigFile
,VerifiedSigFile
);
1585 chmod(VerifiedSigFile
.c_str(),0644);
1588 void pkgAcqMetaIndex::QueueIndexes(bool verify
) /*{{{*/
1591 /* Reject invalid, existing Release files (LP: #346386) (Closes: #627642)
1592 * FIXME: Disabled; it breaks unsigned repositories without hashes */
1593 if (!verify
&& FileExists(DestFile
) && !MetaIndexParser
->Load(DestFile
))
1596 ErrorText
= MetaIndexParser
->ErrorText
;
1600 bool transInRelease
= false;
1602 std::vector
<std::string
> const keys
= MetaIndexParser
->MetaKeys();
1603 for (std::vector
<std::string
>::const_iterator k
= keys
.begin(); k
!= keys
.end(); ++k
)
1604 // FIXME: Feels wrong to check for hardcoded string here, but what should we do else…
1605 if (k
->find("Translation-") != std::string::npos
)
1607 transInRelease
= true;
1612 // at this point the real Items are loaded in the fetcher
1613 ExpectedAdditionalItems
= 0;
1615 for (vector
<struct IndexTarget
*>::const_iterator Target
= IndexTargets
->begin();
1616 Target
!= IndexTargets
->end();
1619 HashString ExpectedIndexHash
;
1620 indexRecords::checkSum
*Record
= MetaIndexParser
->Lookup((*Target
)->MetaKey
);
1621 bool compressedAvailable
= false;
1624 if ((*Target
)->IsOptional() == true)
1626 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
1627 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
1628 if (MetaIndexParser
->Exists((*Target
)->MetaKey
+ "." + *t
) == true)
1630 compressedAvailable
= true;
1634 else if (verify
== true)
1636 Status
= StatAuthError
;
1637 strprintf(ErrorText
, _("Unable to find expected entry '%s' in Release file (Wrong sources.list entry or malformed file)"), (*Target
)->MetaKey
.c_str());
1643 ExpectedIndexHash
= Record
->Hash
;
1644 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1646 std::cerr
<< "Queueing: " << (*Target
)->URI
<< std::endl
;
1647 std::cerr
<< "Expected Hash: " << ExpectedIndexHash
.toStr() << std::endl
;
1648 std::cerr
<< "For: " << Record
->MetaKeyFilename
<< std::endl
;
1650 if (verify
== true && ExpectedIndexHash
.empty() == true && (*Target
)->IsOptional() == false)
1652 Status
= StatAuthError
;
1653 strprintf(ErrorText
, _("Unable to find hash sum for '%s' in Release file"), (*Target
)->MetaKey
.c_str());
1658 if ((*Target
)->IsOptional() == true)
1660 if ((*Target
)->IsSubIndex() == true)
1661 new pkgAcqSubIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
1662 (*Target
)->ShortDesc
, ExpectedIndexHash
);
1663 else if (transInRelease
== false || Record
!= NULL
|| compressedAvailable
== true)
1665 if (_config
->FindB("Acquire::PDiffs",true) == true && transInRelease
== true &&
1666 MetaIndexParser
->Exists((*Target
)->MetaKey
+ ".diff/Index") == true)
1667 new pkgAcqDiffIndex(Owner
, *Target
, ExpectedIndexHash
, MetaIndexParser
);
1669 new pkgAcqIndexTrans(Owner
, *Target
, ExpectedIndexHash
, MetaIndexParser
);
1674 /* Queue Packages file (either diff or full packages files, depending
1675 on the users option) - we also check if the PDiff Index file is listed
1676 in the Meta-Index file. Ideal would be if pkgAcqDiffIndex would test this
1677 instead, but passing the required info to it is to much hassle */
1678 if(_config
->FindB("Acquire::PDiffs",true) == true && (verify
== false ||
1679 MetaIndexParser
->Exists((*Target
)->MetaKey
+ ".diff/Index") == true))
1680 new pkgAcqDiffIndex(Owner
, *Target
, ExpectedIndexHash
, MetaIndexParser
);
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 // index targets + (worst case:) Release/Release.gpg
1844 ExpectedAdditionalItems
= IndexTargets
->size() + 2;
1847 // keep the old InRelease around in case of transistent network errors
1848 string
const Final
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
1849 if (RealFileExists(Final
) == true)
1851 string
const LastGoodSig
= DestFile
+ ".reverify";
1852 Rename(Final
,LastGoodSig
);
1856 pkgAcqMetaClearSig::~pkgAcqMetaClearSig() /*{{{*/
1858 // if the file was never queued undo file-changes done in the constructor
1859 if (QueueCounter
== 1 && Status
== StatIdle
&& FileSize
== 0 && Complete
== false)
1861 string
const Final
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
1862 string
const LastGoodSig
= DestFile
+ ".reverify";
1863 if (RealFileExists(Final
) == false && RealFileExists(LastGoodSig
) == true)
1864 Rename(LastGoodSig
, Final
);
1868 // pkgAcqMetaClearSig::Custom600Headers - Insert custom request headers /*{{{*/
1869 // ---------------------------------------------------------------------
1870 // FIXME: this can go away once the InRelease file is used widely
1871 string
pkgAcqMetaClearSig::Custom600Headers()
1873 string Final
= _config
->FindDir("Dir::State::lists");
1874 Final
+= URItoFileName(RealURI
);
1877 if (stat(Final
.c_str(),&Buf
) != 0)
1879 Final
= DestFile
+ ".reverify";
1880 if (stat(Final
.c_str(),&Buf
) != 0)
1881 return "\nIndex-File: true\nFail-Ignore: true\n";
1884 return "\nIndex-File: true\nFail-Ignore: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1887 void pkgAcqMetaClearSig::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
) /*{{{*/
1889 // we failed, we will not get additional items from this method
1890 ExpectedAdditionalItems
= 0;
1892 if (AuthPass
== false)
1894 // Remove the 'old' InRelease file if we try Release.gpg now as otherwise
1895 // the file will stay around and gives a false-auth impression (CVE-2012-0214)
1896 string FinalFile
= _config
->FindDir("Dir::State::lists");
1897 FinalFile
.append(URItoFileName(RealURI
));
1898 if (FileExists(FinalFile
))
1899 unlink(FinalFile
.c_str());
1901 new pkgAcqMetaSig(Owner
,
1902 MetaSigURI
, MetaSigURIDesc
, MetaSigShortDesc
,
1903 MetaIndexURI
, MetaIndexURIDesc
, MetaIndexShortDesc
,
1904 IndexTargets
, MetaIndexParser
);
1905 if (Cnf
->LocalOnly
== true ||
1906 StringToBool(LookupTag(Message
, "Transient-Failure"), false) == false)
1910 pkgAcqMetaIndex::Failed(Message
, Cnf
);
1913 // AcqArchive::AcqArchive - Constructor /*{{{*/
1914 // ---------------------------------------------------------------------
1915 /* This just sets up the initial fetch environment and queues the first
1917 pkgAcqArchive::pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
1918 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
1919 string
&StoreFilename
) :
1920 Item(Owner
), Version(Version
), Sources(Sources
), Recs(Recs
),
1921 StoreFilename(StoreFilename
), Vf(Version
.FileList()),
1924 Retries
= _config
->FindI("Acquire::Retries",0);
1926 if (Version
.Arch() == 0)
1928 _error
->Error(_("I wasn't able to locate a file for the %s package. "
1929 "This might mean you need to manually fix this package. "
1930 "(due to missing arch)"),
1931 Version
.ParentPkg().FullName().c_str());
1935 /* We need to find a filename to determine the extension. We make the
1936 assumption here that all the available sources for this version share
1937 the same extension.. */
1938 // Skip not source sources, they do not have file fields.
1939 for (; Vf
.end() == false; ++Vf
)
1941 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
1946 // Does not really matter here.. we are going to fail out below
1947 if (Vf
.end() != true)
1949 // If this fails to get a file name we will bomb out below.
1950 pkgRecords::Parser
&Parse
= Recs
->Lookup(Vf
);
1951 if (_error
->PendingError() == true)
1954 // Generate the final file name as: package_version_arch.foo
1955 StoreFilename
= QuoteString(Version
.ParentPkg().Name(),"_:") + '_' +
1956 QuoteString(Version
.VerStr(),"_:") + '_' +
1957 QuoteString(Version
.Arch(),"_:.") +
1958 "." + flExtension(Parse
.FileName());
1961 // check if we have one trusted source for the package. if so, switch
1962 // to "TrustedOnly" mode - but only if not in AllowUnauthenticated mode
1963 bool const allowUnauth
= _config
->FindB("APT::Get::AllowUnauthenticated", false);
1964 bool const debugAuth
= _config
->FindB("Debug::pkgAcquire::Auth", false);
1965 bool seenUntrusted
= false;
1966 for (pkgCache::VerFileIterator i
= Version
.FileList(); i
.end() == false; ++i
)
1968 pkgIndexFile
*Index
;
1969 if (Sources
->FindIndex(i
.File(),Index
) == false)
1972 if (debugAuth
== true)
1973 std::cerr
<< "Checking index: " << Index
->Describe()
1974 << "(Trusted=" << Index
->IsTrusted() << ")" << std::endl
;
1976 if (Index
->IsTrusted() == true)
1979 if (allowUnauth
== false)
1983 seenUntrusted
= true;
1986 // "allow-unauthenticated" restores apts old fetching behaviour
1987 // that means that e.g. unauthenticated file:// uris are higher
1988 // priority than authenticated http:// uris
1989 if (allowUnauth
== true && seenUntrusted
== true)
1993 if (QueueNext() == false && _error
->PendingError() == false)
1994 _error
->Error(_("Can't find a source to download version '%s' of '%s'"),
1995 Version
.VerStr(), Version
.ParentPkg().FullName(false).c_str());
1998 // AcqArchive::QueueNext - Queue the next file source /*{{{*/
1999 // ---------------------------------------------------------------------
2000 /* This queues the next available file version for download. It checks if
2001 the archive is already available in the cache and stashs the MD5 for
2003 bool pkgAcqArchive::QueueNext()
2005 string
const ForceHash
= _config
->Find("Acquire::ForceHash");
2006 for (; Vf
.end() == false; ++Vf
)
2008 // Ignore not source sources
2009 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
2012 // Try to cross match against the source list
2013 pkgIndexFile
*Index
;
2014 if (Sources
->FindIndex(Vf
.File(),Index
) == false)
2017 // only try to get a trusted package from another source if that source
2019 if(Trusted
&& !Index
->IsTrusted())
2022 // Grab the text package record
2023 pkgRecords::Parser
&Parse
= Recs
->Lookup(Vf
);
2024 if (_error
->PendingError() == true)
2027 string PkgFile
= Parse
.FileName();
2028 if (ForceHash
.empty() == false)
2030 if(stringcasecmp(ForceHash
, "sha512") == 0)
2031 ExpectedHash
= HashString("SHA512", Parse
.SHA512Hash());
2032 else if(stringcasecmp(ForceHash
, "sha256") == 0)
2033 ExpectedHash
= HashString("SHA256", Parse
.SHA256Hash());
2034 else if (stringcasecmp(ForceHash
, "sha1") == 0)
2035 ExpectedHash
= HashString("SHA1", Parse
.SHA1Hash());
2037 ExpectedHash
= HashString("MD5Sum", Parse
.MD5Hash());
2042 if ((Hash
= Parse
.SHA512Hash()).empty() == false)
2043 ExpectedHash
= HashString("SHA512", Hash
);
2044 else if ((Hash
= Parse
.SHA256Hash()).empty() == false)
2045 ExpectedHash
= HashString("SHA256", Hash
);
2046 else if ((Hash
= Parse
.SHA1Hash()).empty() == false)
2047 ExpectedHash
= HashString("SHA1", Hash
);
2049 ExpectedHash
= HashString("MD5Sum", Parse
.MD5Hash());
2051 if (PkgFile
.empty() == true)
2052 return _error
->Error(_("The package index files are corrupted. No Filename: "
2053 "field for package %s."),
2054 Version
.ParentPkg().Name());
2056 Desc
.URI
= Index
->ArchiveURI(PkgFile
);
2057 Desc
.Description
= Index
->ArchiveInfo(Version
);
2059 Desc
.ShortDesc
= Version
.ParentPkg().FullName(true);
2061 // See if we already have the file. (Legacy filenames)
2062 FileSize
= Version
->Size
;
2063 string FinalFile
= _config
->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile
);
2065 if (stat(FinalFile
.c_str(),&Buf
) == 0)
2067 // Make sure the size matches
2068 if ((unsigned long long)Buf
.st_size
== Version
->Size
)
2073 StoreFilename
= DestFile
= FinalFile
;
2077 /* Hmm, we have a file and its size does not match, this means it is
2078 an old style mismatched arch */
2079 unlink(FinalFile
.c_str());
2082 // Check it again using the new style output filenames
2083 FinalFile
= _config
->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename
);
2084 if (stat(FinalFile
.c_str(),&Buf
) == 0)
2086 // Make sure the size matches
2087 if ((unsigned long long)Buf
.st_size
== Version
->Size
)
2092 StoreFilename
= DestFile
= FinalFile
;
2096 /* Hmm, we have a file and its size does not match, this shouldn't
2098 unlink(FinalFile
.c_str());
2101 DestFile
= _config
->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(StoreFilename
);
2103 // Check the destination file
2104 if (stat(DestFile
.c_str(),&Buf
) == 0)
2106 // Hmm, the partial file is too big, erase it
2107 if ((unsigned long long)Buf
.st_size
> Version
->Size
)
2108 unlink(DestFile
.c_str());
2110 PartialSize
= Buf
.st_size
;
2113 // Disables download of archives - useful if no real installation follows,
2114 // e.g. if we are just interested in proposed installation order
2115 if (_config
->FindB("Debug::pkgAcqArchive::NoQueue", false) == true)
2120 StoreFilename
= DestFile
= FinalFile
;
2134 // AcqArchive::Done - Finished fetching /*{{{*/
2135 // ---------------------------------------------------------------------
2137 void pkgAcqArchive::Done(string Message
,unsigned long long Size
,string CalcHash
,
2138 pkgAcquire::MethodConfig
*Cfg
)
2140 Item::Done(Message
,Size
,CalcHash
,Cfg
);
2143 if (Size
!= Version
->Size
)
2145 RenameOnError(SizeMismatch
);
2150 // FIXME: could this empty() check impose *any* sort of security issue?
2151 if(ExpectedHash
.empty() == false && ExpectedHash
.toStr() != CalcHash
)
2153 RenameOnError(HashSumMismatch
);
2157 // Grab the output filename
2158 string FileName
= LookupTag(Message
,"Filename");
2159 if (FileName
.empty() == true)
2162 ErrorText
= "Method gave a blank filename";
2168 // Reference filename
2169 if (FileName
!= DestFile
)
2171 StoreFilename
= DestFile
= FileName
;
2176 // Done, move it into position
2177 string FinalFile
= _config
->FindDir("Dir::Cache::Archives");
2178 FinalFile
+= flNotDir(StoreFilename
);
2179 Rename(DestFile
,FinalFile
);
2181 StoreFilename
= DestFile
= FinalFile
;
2185 // AcqArchive::Failed - Failure handler /*{{{*/
2186 // ---------------------------------------------------------------------
2187 /* Here we try other sources */
2188 void pkgAcqArchive::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
2190 ErrorText
= LookupTag(Message
,"Message");
2192 /* We don't really want to retry on failed media swaps, this prevents
2193 that. An interesting observation is that permanent failures are not
2195 if (Cnf
->Removable
== true &&
2196 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
2198 // Vf = Version.FileList();
2199 while (Vf
.end() == false) ++Vf
;
2200 StoreFilename
= string();
2201 Item::Failed(Message
,Cnf
);
2205 if (QueueNext() == false)
2207 // This is the retry counter
2209 Cnf
->LocalOnly
== false &&
2210 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
2213 Vf
= Version
.FileList();
2214 if (QueueNext() == true)
2218 StoreFilename
= string();
2219 Item::Failed(Message
,Cnf
);
2223 // AcqArchive::IsTrusted - Determine whether this archive comes from a trusted source /*{{{*/
2224 // ---------------------------------------------------------------------
2225 APT_PURE
bool pkgAcqArchive::IsTrusted()
2230 // AcqArchive::Finished - Fetching has finished, tidy up /*{{{*/
2231 // ---------------------------------------------------------------------
2233 void pkgAcqArchive::Finished()
2235 if (Status
== pkgAcquire::Item::StatDone
&&
2238 StoreFilename
= string();
2241 // AcqFile::pkgAcqFile - Constructor /*{{{*/
2242 // ---------------------------------------------------------------------
2243 /* The file is added to the queue */
2244 pkgAcqFile::pkgAcqFile(pkgAcquire
*Owner
,string URI
,string Hash
,
2245 unsigned long long Size
,string Dsc
,string ShortDesc
,
2246 const string
&DestDir
, const string
&DestFilename
,
2248 Item(Owner
), ExpectedHash(Hash
), IsIndexFile(IsIndexFile
)
2250 Retries
= _config
->FindI("Acquire::Retries",0);
2252 if(!DestFilename
.empty())
2253 DestFile
= DestFilename
;
2254 else if(!DestDir
.empty())
2255 DestFile
= DestDir
+ "/" + flNotDir(URI
);
2257 DestFile
= flNotDir(URI
);
2261 Desc
.Description
= Dsc
;
2264 // Set the short description to the archive component
2265 Desc
.ShortDesc
= ShortDesc
;
2267 // Get the transfer sizes
2270 if (stat(DestFile
.c_str(),&Buf
) == 0)
2272 // Hmm, the partial file is too big, erase it
2273 if ((Size
> 0) && (unsigned long long)Buf
.st_size
> Size
)
2274 unlink(DestFile
.c_str());
2276 PartialSize
= Buf
.st_size
;
2282 // AcqFile::Done - Item downloaded OK /*{{{*/
2283 // ---------------------------------------------------------------------
2285 void pkgAcqFile::Done(string Message
,unsigned long long Size
,string CalcHash
,
2286 pkgAcquire::MethodConfig
*Cnf
)
2288 Item::Done(Message
,Size
,CalcHash
,Cnf
);
2291 if(!ExpectedHash
.empty() && ExpectedHash
.toStr() != CalcHash
)
2293 RenameOnError(HashSumMismatch
);
2297 string FileName
= LookupTag(Message
,"Filename");
2298 if (FileName
.empty() == true)
2301 ErrorText
= "Method gave a blank filename";
2307 // The files timestamp matches
2308 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
2311 // We have to copy it into place
2312 if (FileName
!= DestFile
)
2315 if (_config
->FindB("Acquire::Source-Symlinks",true) == false ||
2316 Cnf
->Removable
== true)
2318 Desc
.URI
= "copy:" + FileName
;
2323 // Erase the file if it is a symlink so we can overwrite it
2325 if (lstat(DestFile
.c_str(),&St
) == 0)
2327 if (S_ISLNK(St
.st_mode
) != 0)
2328 unlink(DestFile
.c_str());
2332 if (symlink(FileName
.c_str(),DestFile
.c_str()) != 0)
2334 ErrorText
= "Link to " + DestFile
+ " failure ";
2341 // AcqFile::Failed - Failure handler /*{{{*/
2342 // ---------------------------------------------------------------------
2343 /* Here we try other sources */
2344 void pkgAcqFile::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
2346 ErrorText
= LookupTag(Message
,"Message");
2348 // This is the retry counter
2350 Cnf
->LocalOnly
== false &&
2351 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
2358 Item::Failed(Message
,Cnf
);
2361 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
2362 // ---------------------------------------------------------------------
2363 /* The only header we use is the last-modified header. */
2364 string
pkgAcqFile::Custom600Headers()
2367 return "\nIndex-File: true";