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 /*{{{*/
16 #include <apt-pkg/acquire-item.h>
17 #include <apt-pkg/configuration.h>
18 #include <apt-pkg/aptconfiguration.h>
19 #include <apt-pkg/sourcelist.h>
20 #include <apt-pkg/vendorlist.h>
21 #include <apt-pkg/error.h>
22 #include <apt-pkg/strutl.h>
23 #include <apt-pkg/fileutl.h>
24 #include <apt-pkg/md5.h>
25 #include <apt-pkg/sha1.h>
26 #include <apt-pkg/tagfile.h>
40 // Acquire::Item::Item - Constructor /*{{{*/
41 // ---------------------------------------------------------------------
43 pkgAcquire::Item::Item(pkgAcquire
*Owner
) : Owner(Owner
), FileSize(0),
44 PartialSize(0), Mode(0), ID(0), Complete(false),
45 Local(false), QueueCounter(0)
51 // Acquire::Item::~Item - Destructor /*{{{*/
52 // ---------------------------------------------------------------------
54 pkgAcquire::Item::~Item()
59 // Acquire::Item::Failed - Item failed to download /*{{{*/
60 // ---------------------------------------------------------------------
61 /* We return to an idle state if there are still other queues that could
63 void pkgAcquire::Item::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
66 ErrorText
= LookupTag(Message
,"Message");
67 if (QueueCounter
<= 1)
69 /* This indicates that the file is not available right now but might
70 be sometime later. If we do a retry cycle then this should be
72 if (Cnf
->LocalOnly
== true &&
73 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
85 // Acquire::Item::Start - Item has begun to download /*{{{*/
86 // ---------------------------------------------------------------------
87 /* Stash status and the file size. Note that setting Complete means
88 sub-phases of the acquire process such as decompresion are operating */
89 void pkgAcquire::Item::Start(string
/*Message*/,unsigned long Size
)
91 Status
= StatFetching
;
92 if (FileSize
== 0 && Complete
== false)
96 // Acquire::Item::Done - Item downloaded OK /*{{{*/
97 // ---------------------------------------------------------------------
99 void pkgAcquire::Item::Done(string Message
,unsigned long Size
,string Hash
,
100 pkgAcquire::MethodConfig
*Cnf
)
102 // We just downloaded something..
103 string FileName
= LookupTag(Message
,"Filename");
104 // we only inform the Log class if it was actually not a local thing
105 if (Complete
== false && !Local
&& FileName
== DestFile
)
108 Owner
->Log
->Fetched(Size
,atoi(LookupTag(Message
,"Resume-Point","0").c_str()));
115 ErrorText
= string();
116 Owner
->Dequeue(this);
119 // Acquire::Item::Rename - Rename a file /*{{{*/
120 // ---------------------------------------------------------------------
121 /* This helper function is used by alot of item methods as thier final
123 void pkgAcquire::Item::Rename(string From
,string To
)
125 if (rename(From
.c_str(),To
.c_str()) != 0)
128 snprintf(S
,sizeof(S
),_("rename failed, %s (%s -> %s)."),strerror(errno
),
129 From
.c_str(),To
.c_str());
135 // AcqDiffIndex::AcqDiffIndex - Constructor /*{{{*/
136 // ---------------------------------------------------------------------
137 /* Get the DiffIndex file first and see if there are patches availabe
138 * If so, create a pkgAcqIndexDiffs fetcher that will get and apply the
139 * patches. If anything goes wrong in that process, it will fall back to
140 * the original packages file
142 pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire
*Owner
,
143 string URI
,string URIDesc
,string ShortDesc
,
144 HashString ExpectedHash
)
145 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
),
149 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
151 Desc
.Description
= URIDesc
+ "/DiffIndex";
153 Desc
.ShortDesc
= ShortDesc
;
154 Desc
.URI
= URI
+ ".diff/Index";
156 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
157 DestFile
+= URItoFileName(URI
) + string(".DiffIndex");
160 std::clog
<< "pkgAcqDiffIndex: " << Desc
.URI
<< std::endl
;
162 // look for the current package file
163 CurrentPackagesFile
= _config
->FindDir("Dir::State::lists");
164 CurrentPackagesFile
+= URItoFileName(RealURI
);
166 // FIXME: this file:/ check is a hack to prevent fetching
167 // from local sources. this is really silly, and
168 // should be fixed cleanly as soon as possible
169 if(!FileExists(CurrentPackagesFile
) ||
170 Desc
.URI
.substr(0,strlen("file:/")) == "file:/")
172 // we don't have a pkg file or we don't want to queue
174 std::clog
<< "No index file, local or canceld by user" << std::endl
;
180 std::clog
<< "pkgAcqIndexDiffs::pkgAcqIndexDiffs(): "
181 << CurrentPackagesFile
<< std::endl
;
187 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
188 // ---------------------------------------------------------------------
189 /* The only header we use is the last-modified header. */
190 string
pkgAcqDiffIndex::Custom600Headers()
192 string Final
= _config
->FindDir("Dir::State::lists");
193 Final
+= URItoFileName(RealURI
) + string(".IndexDiff");
196 std::clog
<< "Custom600Header-IMS: " << Final
<< std::endl
;
199 if (stat(Final
.c_str(),&Buf
) != 0)
200 return "\nIndex-File: true";
202 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
205 bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile
) /*{{{*/
208 std::clog
<< "pkgAcqIndexDiffs::ParseIndexDiff() " << IndexDiffFile
213 vector
<DiffInfo
> available_patches
;
215 FileFd
Fd(IndexDiffFile
,FileFd::ReadOnly
);
217 if (_error
->PendingError() == true)
220 if(TF
.Step(Tags
) == true)
226 string
const tmp
= Tags
.FindS("SHA1-Current");
227 std::stringstream
ss(tmp
);
228 ss
>> ServerSha1
>> size
;
229 unsigned long const ServerSize
= atol(size
.c_str());
231 FileFd
fd(CurrentPackagesFile
, FileFd::ReadOnly
);
233 SHA1
.AddFD(fd
.Fd(), fd
.Size());
234 string
const local_sha1
= SHA1
.Result();
236 if(local_sha1
== ServerSha1
)
238 // we have the same sha1 as the server
240 std::clog
<< "Package file is up-to-date" << std::endl
;
241 // set found to true, this will queue a pkgAcqIndexDiffs with
242 // a empty availabe_patches
248 std::clog
<< "SHA1-Current: " << ServerSha1
<< std::endl
;
250 // check the historie and see what patches we need
251 string
const history
= Tags
.FindS("SHA1-History");
252 std::stringstream
hist(history
);
253 while(hist
>> d
.sha1
>> size
>> d
.file
)
255 // read until the first match is found
256 // from that point on, we probably need all diffs
257 if(d
.sha1
== local_sha1
)
259 else if (found
== false)
263 std::clog
<< "Need to get diff: " << d
.file
<< std::endl
;
264 available_patches
.push_back(d
);
267 if (available_patches
.empty() == false)
269 // patching with too many files is rather slow compared to a fast download
270 unsigned long const fileLimit
= _config
->FindI("Acquire::PDiffs::FileLimit", 0);
271 if (fileLimit
!= 0 && fileLimit
< available_patches
.size())
274 std::clog
<< "Need " << available_patches
.size() << " diffs (Limit is " << fileLimit
275 << ") so fallback to complete download" << std::endl
;
279 // see if the patches are too big
280 found
= false; // it was true and it will be true again at the end
281 d
= *available_patches
.begin();
282 string
const firstPatch
= d
.file
;
283 unsigned long patchesSize
= 0;
284 std::stringstream
patches(Tags
.FindS("SHA1-Patches"));
285 while(patches
>> d
.sha1
>> size
>> d
.file
)
287 if (firstPatch
== d
.file
)
289 else if (found
== false)
292 patchesSize
+= atol(size
.c_str());
294 unsigned long const sizeLimit
= ServerSize
* _config
->FindI("Acquire::PDiffs::SizeLimit", 100);
295 if (sizeLimit
> 0 && (sizeLimit
/100) < patchesSize
)
298 std::clog
<< "Need " << patchesSize
<< " bytes (Limit is " << sizeLimit
/100
299 << ") so fallback to complete download" << std::endl
;
305 // we have something, queue the next diff
309 string::size_type
const last_space
= Description
.rfind(" ");
310 if(last_space
!= string::npos
)
311 Description
.erase(last_space
, Description
.size()-last_space
);
312 new pkgAcqIndexDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
313 ExpectedHash
, ServerSha1
, available_patches
);
321 // Nothing found, report and return false
322 // Failing here is ok, if we return false later, the full
323 // IndexFile is queued
325 std::clog
<< "Can't find a patch in the index file" << std::endl
;
329 void pkgAcqDiffIndex::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
) /*{{{*/
332 std::clog
<< "pkgAcqDiffIndex failed: " << Desc
.URI
<< std::endl
333 << "Falling back to normal index file aquire" << std::endl
;
335 new pkgAcqIndex(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
343 void pkgAcqDiffIndex::Done(string Message
,unsigned long Size
,string Md5Hash
, /*{{{*/
344 pkgAcquire::MethodConfig
*Cnf
)
347 std::clog
<< "pkgAcqDiffIndex::Done(): " << Desc
.URI
<< std::endl
;
349 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
352 FinalFile
= _config
->FindDir("Dir::State::lists")+URItoFileName(RealURI
);
354 // sucess in downloading the index
356 FinalFile
+= string(".IndexDiff");
358 std::clog
<< "Renaming: " << DestFile
<< " -> " << FinalFile
360 Rename(DestFile
,FinalFile
);
361 chmod(FinalFile
.c_str(),0644);
362 DestFile
= FinalFile
;
364 if(!ParseDiffIndex(DestFile
))
365 return Failed("", NULL
);
373 // AcqIndexDiffs::AcqIndexDiffs - Constructor /*{{{*/
374 // ---------------------------------------------------------------------
375 /* The package diff is added to the queue. one object is constructed
376 * for each diff and the index
378 pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire
*Owner
,
379 string URI
,string URIDesc
,string ShortDesc
,
380 HashString ExpectedHash
,
382 vector
<DiffInfo
> diffs
)
383 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
),
384 available_patches(diffs
), ServerSha1(ServerSha1
)
387 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
388 DestFile
+= URItoFileName(URI
);
390 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
392 Description
= URIDesc
;
394 Desc
.ShortDesc
= ShortDesc
;
396 if(available_patches
.size() == 0)
398 // we are done (yeah!)
404 State
= StateFetchDiff
;
409 void pkgAcqIndexDiffs::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
) /*{{{*/
412 std::clog
<< "pkgAcqIndexDiffs failed: " << Desc
.URI
<< std::endl
413 << "Falling back to normal index file aquire" << std::endl
;
414 new pkgAcqIndex(Owner
, RealURI
, Description
,Desc
.ShortDesc
,
419 // Finish - helper that cleans the item out of the fetcher queue /*{{{*/
420 void pkgAcqIndexDiffs::Finish(bool allDone
)
422 // we restore the original name, this is required, otherwise
423 // the file will be cleaned
426 DestFile
= _config
->FindDir("Dir::State::lists");
427 DestFile
+= URItoFileName(RealURI
);
429 if(!ExpectedHash
.empty() && !ExpectedHash
.VerifyFile(DestFile
))
431 Status
= StatAuthError
;
432 ErrorText
= _("MD5Sum mismatch");
433 Rename(DestFile
,DestFile
+ ".FAILED");
438 // this is for the "real" finish
443 std::clog
<< "\n\nallDone: " << DestFile
<< "\n" << std::endl
;
448 std::clog
<< "Finishing: " << Desc
.URI
<< std::endl
;
455 bool pkgAcqIndexDiffs::QueueNextDiff() /*{{{*/
458 // calc sha1 of the just patched file
459 string FinalFile
= _config
->FindDir("Dir::State::lists");
460 FinalFile
+= URItoFileName(RealURI
);
462 FileFd
fd(FinalFile
, FileFd::ReadOnly
);
464 SHA1
.AddFD(fd
.Fd(), fd
.Size());
465 string local_sha1
= string(SHA1
.Result());
467 std::clog
<< "QueueNextDiff: "
468 << FinalFile
<< " (" << local_sha1
<< ")"<<std::endl
;
470 // final file reached before all patches are applied
471 if(local_sha1
== ServerSha1
)
477 // remove all patches until the next matching patch is found
478 // this requires the Index file to be ordered
479 for(vector
<DiffInfo
>::iterator I
=available_patches
.begin();
480 available_patches
.size() > 0 &&
481 I
!= available_patches
.end() &&
482 (*I
).sha1
!= local_sha1
;
485 available_patches
.erase(I
);
488 // error checking and falling back if no patch was found
489 if(available_patches
.size() == 0)
495 // queue the right diff
496 Desc
.URI
= string(RealURI
) + ".diff/" + available_patches
[0].file
+ ".gz";
497 Desc
.Description
= Description
+ " " + available_patches
[0].file
+ string(".pdiff");
498 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
499 DestFile
+= URItoFileName(RealURI
+ ".diff/" + available_patches
[0].file
);
502 std::clog
<< "pkgAcqIndexDiffs::QueueNextDiff(): " << Desc
.URI
<< std::endl
;
509 void pkgAcqIndexDiffs::Done(string Message
,unsigned long Size
,string Md5Hash
, /*{{{*/
510 pkgAcquire::MethodConfig
*Cnf
)
513 std::clog
<< "pkgAcqIndexDiffs::Done(): " << Desc
.URI
<< std::endl
;
515 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
518 FinalFile
= _config
->FindDir("Dir::State::lists")+URItoFileName(RealURI
);
520 // sucess in downloading a diff, enter ApplyDiff state
521 if(State
== StateFetchDiff
)
525 std::clog
<< "Sending to gzip method: " << FinalFile
<< std::endl
;
527 string FileName
= LookupTag(Message
,"Filename");
528 State
= StateUnzipDiff
;
530 Desc
.URI
= "gzip:" + FileName
;
531 DestFile
+= ".decomp";
537 // sucess in downloading a diff, enter ApplyDiff state
538 if(State
== StateUnzipDiff
)
541 // rred excepts the patch as $FinalFile.ed
542 Rename(DestFile
,FinalFile
+".ed");
545 std::clog
<< "Sending to rred method: " << FinalFile
<< std::endl
;
547 State
= StateApplyDiff
;
549 Desc
.URI
= "rred:" + FinalFile
;
556 // success in download/apply a diff, queue next (if needed)
557 if(State
== StateApplyDiff
)
559 // remove the just applied patch
560 available_patches
.erase(available_patches
.begin());
565 std::clog
<< "Moving patched file in place: " << std::endl
566 << DestFile
<< " -> " << FinalFile
<< std::endl
;
568 Rename(DestFile
,FinalFile
);
569 chmod(FinalFile
.c_str(),0644);
571 // see if there is more to download
572 if(available_patches
.size() > 0) {
573 new pkgAcqIndexDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
574 ExpectedHash
, ServerSha1
, available_patches
);
581 // AcqIndex::AcqIndex - Constructor /*{{{*/
582 // ---------------------------------------------------------------------
583 /* The package file is added to the queue and a second class is
584 instantiated to fetch the revision file */
585 pkgAcqIndex::pkgAcqIndex(pkgAcquire
*Owner
,
586 string URI
,string URIDesc
,string ShortDesc
,
587 HashString ExpectedHash
, string comprExt
)
588 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
)
590 Decompression
= false;
593 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
594 DestFile
+= URItoFileName(URI
);
598 // autoselect the compression method
599 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
600 if (types
.empty() == true)
603 comprExt
= "." + types
[0];
605 CompressionExtension
= ((comprExt
== "plain" || comprExt
== ".") ? "" : comprExt
);
607 Desc
.URI
= URI
+ CompressionExtension
;
609 Desc
.Description
= URIDesc
;
611 Desc
.ShortDesc
= ShortDesc
;
616 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
617 // ---------------------------------------------------------------------
618 /* The only header we use is the last-modified header. */
619 string
pkgAcqIndex::Custom600Headers()
621 string Final
= _config
->FindDir("Dir::State::lists");
622 Final
+= URItoFileName(RealURI
);
623 if (_config
->FindB("Acquire::GzipIndexes",false))
627 if (stat(Final
.c_str(),&Buf
) != 0)
628 return "\nIndex-File: true";
630 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
633 void pkgAcqIndex::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
) /*{{{*/
635 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
637 for (std::vector
<std::string
>::const_iterator t
= types
.begin();
638 t
!= types
.end(); t
++)
640 // jump over all already tried compression types
641 const unsigned int nameLen
= Desc
.URI
.size() - (*t
).size();
642 if(Desc
.URI
.substr(nameLen
) != *t
)
645 // we want to try it with the next extension (and make sure to
646 // not skip over the end)
648 if (t
== types
.end())
651 // queue new download
652 Desc
.URI
= Desc
.URI
.substr(0, nameLen
) + *t
;
653 new pkgAcqIndex(Owner
, RealURI
, Desc
.Description
, Desc
.ShortDesc
,
654 ExpectedHash
, string(".").append(*t
));
662 // on decompression failure, remove bad versions in partial/
663 if(Decompression
&& Erase
) {
664 string s
= _config
->FindDir("Dir::State::lists") + "partial/";
665 s
+= URItoFileName(RealURI
);
669 Item::Failed(Message
,Cnf
);
672 // AcqIndex::Done - Finished a fetch /*{{{*/
673 // ---------------------------------------------------------------------
674 /* This goes through a number of states.. On the initial fetch the
675 method could possibly return an alternate filename which points
676 to the uncompressed version of the file. If this is so the file
677 is copied into the partial directory. In all other cases the file
678 is decompressed with a gzip uri. */
679 void pkgAcqIndex::Done(string Message
,unsigned long Size
,string Hash
,
680 pkgAcquire::MethodConfig
*Cfg
)
682 Item::Done(Message
,Size
,Hash
,Cfg
);
684 if (Decompression
== true)
686 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
688 std::cerr
<< std::endl
<< RealURI
<< ": Computed Hash: " << Hash
;
689 std::cerr
<< " Expected Hash: " << ExpectedHash
.toStr() << std::endl
;
692 if (!ExpectedHash
.empty() && ExpectedHash
.toStr() != Hash
)
694 Status
= StatAuthError
;
695 ErrorText
= _("Hash Sum mismatch");
696 Rename(DestFile
,DestFile
+ ".FAILED");
699 // Done, move it into position
700 string FinalFile
= _config
->FindDir("Dir::State::lists");
701 FinalFile
+= URItoFileName(RealURI
);
702 Rename(DestFile
,FinalFile
);
703 chmod(FinalFile
.c_str(),0644);
705 /* We restore the original name to DestFile so that the clean operation
707 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
708 DestFile
+= URItoFileName(RealURI
);
710 // Remove the compressed version.
712 unlink(DestFile
.c_str());
719 // Handle the unzipd case
720 string FileName
= LookupTag(Message
,"Alt-Filename");
721 if (FileName
.empty() == false)
723 // The files timestamp matches
724 if (StringToBool(LookupTag(Message
,"Alt-IMS-Hit"),false) == true)
726 Decompression
= true;
728 DestFile
+= ".decomp";
729 Desc
.URI
= "copy:" + FileName
;
735 FileName
= LookupTag(Message
,"Filename");
736 if (FileName
.empty() == true)
739 ErrorText
= "Method gave a blank filename";
742 // The files timestamp matches
743 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
746 if (FileName
== DestFile
)
751 string compExt
= flExtension(flNotDir(URI(Desc
.URI
).Path
));
754 // If we enable compressed indexes and already have gzip, keep it
755 if (_config
->FindB("Acquire::GzipIndexes",false) && compExt
== "gz") {
756 string FinalFile
= _config
->FindDir("Dir::State::lists");
757 FinalFile
+= URItoFileName(RealURI
) + ".gz";
759 // std::clog << "pkgAcqIndex: keeping gzipped " << FinalFile << endl;
760 Rename(DestFile
,FinalFile
);
761 chmod(FinalFile
.c_str(),0644);
763 // Update DestFile for .gz suffix so that the clean operation keeps it
764 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
765 DestFile
+= URItoFileName(RealURI
) + ".gz";
769 // get the binary name for your used compression type
770 decompProg
= _config
->Find(string("Acquire::CompressionTypes::").append(compExt
),"");
771 if(decompProg
.empty() == false);
772 // flExtensions returns the full name if no extension is found
773 // this is why we have this complicated compare operation here
774 // FIMXE: add a new flJustExtension() that return "" if no
775 // extension is found and use that above so that it can
776 // be tested against ""
777 else if(compExt
== flNotDir(URI(Desc
.URI
).Path
))
780 _error
->Error("Unsupported extension: %s", compExt
.c_str());
784 Decompression
= true;
785 DestFile
+= ".decomp";
786 Desc
.URI
= decompProg
+ ":" + FileName
;
788 Mode
= decompProg
.c_str();
791 // AcqIndexTrans::pkgAcqIndexTrans - Constructor /*{{{*/
792 // ---------------------------------------------------------------------
793 /* The Translation file is added to the queue */
794 pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire
*Owner
,
795 string URI
,string URIDesc
,string ShortDesc
)
796 : pkgAcqIndex(Owner
, URI
, URIDesc
, ShortDesc
, HashString(), "")
800 // AcqIndexTrans::Failed - Silence failure messages for missing files /*{{{*/
801 // ---------------------------------------------------------------------
803 void pkgAcqIndexTrans::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
805 if (Cnf
->LocalOnly
== true ||
806 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == false)
815 Item::Failed(Message
,Cnf
);
818 pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire
*Owner
, /*{{{*/
819 string URI
,string URIDesc
,string ShortDesc
,
820 string MetaIndexURI
, string MetaIndexURIDesc
,
821 string MetaIndexShortDesc
,
822 const vector
<IndexTarget
*>* IndexTargets
,
823 indexRecords
* MetaIndexParser
) :
824 Item(Owner
), RealURI(URI
), MetaIndexURI(MetaIndexURI
),
825 MetaIndexURIDesc(MetaIndexURIDesc
), MetaIndexShortDesc(MetaIndexShortDesc
),
826 MetaIndexParser(MetaIndexParser
), IndexTargets(IndexTargets
)
828 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
829 DestFile
+= URItoFileName(URI
);
831 // remove any partial downloaded sig-file in partial/.
832 // it may confuse proxies and is too small to warrant a
833 // partial download anyway
834 unlink(DestFile
.c_str());
837 Desc
.Description
= URIDesc
;
839 Desc
.ShortDesc
= ShortDesc
;
842 string Final
= _config
->FindDir("Dir::State::lists");
843 Final
+= URItoFileName(RealURI
);
845 if (stat(Final
.c_str(),&Buf
) == 0)
847 // File was already in place. It needs to be re-downloaded/verified
848 // because Release might have changed, we do give it a differnt
849 // name than DestFile because otherwise the http method will
850 // send If-Range requests and there are too many broken servers
851 // out there that do not understand them
852 LastGoodSig
= DestFile
+".reverify";
853 Rename(Final
,LastGoodSig
);
859 // pkgAcqMetaSig::Custom600Headers - Insert custom request headers /*{{{*/
860 // ---------------------------------------------------------------------
861 /* The only header we use is the last-modified header. */
862 string
pkgAcqMetaSig::Custom600Headers()
865 if (stat(LastGoodSig
.c_str(),&Buf
) != 0)
866 return "\nIndex-File: true";
868 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
871 void pkgAcqMetaSig::Done(string Message
,unsigned long Size
,string MD5
,
872 pkgAcquire::MethodConfig
*Cfg
)
874 Item::Done(Message
,Size
,MD5
,Cfg
);
876 string FileName
= LookupTag(Message
,"Filename");
877 if (FileName
.empty() == true)
880 ErrorText
= "Method gave a blank filename";
884 if (FileName
!= DestFile
)
886 // We have to copy it into place
888 Desc
.URI
= "copy:" + FileName
;
895 // put the last known good file back on i-m-s hit (it will
896 // be re-verified again)
897 // Else do nothing, we have the new file in DestFile then
898 if(StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
899 Rename(LastGoodSig
, DestFile
);
901 // queue a pkgAcqMetaIndex to be verified against the sig we just retrieved
902 new pkgAcqMetaIndex(Owner
, MetaIndexURI
, MetaIndexURIDesc
, MetaIndexShortDesc
,
903 DestFile
, IndexTargets
, MetaIndexParser
);
907 void pkgAcqMetaSig::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)/*{{{*/
909 string Final
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
911 // if we get a network error we fail gracefully
912 if(Status
== StatTransientNetworkError
)
914 Item::Failed(Message
,Cnf
);
915 // move the sigfile back on transient network failures
916 if(FileExists(DestFile
))
917 Rename(LastGoodSig
,Final
);
919 // set the status back to , Item::Failed likes to reset it
920 Status
= pkgAcquire::Item::StatTransientNetworkError
;
924 // Delete any existing sigfile when the acquire failed
925 unlink(Final
.c_str());
927 // queue a pkgAcqMetaIndex with no sigfile
928 new pkgAcqMetaIndex(Owner
, MetaIndexURI
, MetaIndexURIDesc
, MetaIndexShortDesc
,
929 "", IndexTargets
, MetaIndexParser
);
931 if (Cnf
->LocalOnly
== true ||
932 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == false)
941 Item::Failed(Message
,Cnf
);
944 pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire
*Owner
, /*{{{*/
945 string URI
,string URIDesc
,string ShortDesc
,
947 const vector
<struct IndexTarget
*>* IndexTargets
,
948 indexRecords
* MetaIndexParser
) :
949 Item(Owner
), RealURI(URI
), SigFile(SigFile
), IndexTargets(IndexTargets
),
950 MetaIndexParser(MetaIndexParser
), AuthPass(false), IMSHit(false)
952 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
953 DestFile
+= URItoFileName(URI
);
956 Desc
.Description
= URIDesc
;
958 Desc
.ShortDesc
= ShortDesc
;
964 // pkgAcqMetaIndex::Custom600Headers - Insert custom request headers /*{{{*/
965 // ---------------------------------------------------------------------
966 /* The only header we use is the last-modified header. */
967 string
pkgAcqMetaIndex::Custom600Headers()
969 string Final
= _config
->FindDir("Dir::State::lists");
970 Final
+= URItoFileName(RealURI
);
973 if (stat(Final
.c_str(),&Buf
) != 0)
974 return "\nIndex-File: true";
976 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
979 void pkgAcqMetaIndex::Done(string Message
,unsigned long Size
,string Hash
, /*{{{*/
980 pkgAcquire::MethodConfig
*Cfg
)
982 Item::Done(Message
,Size
,Hash
,Cfg
);
984 // MetaIndexes are done in two passes: one to download the
985 // metaindex with an appropriate method, and a second to verify it
986 // with the gpgv method
988 if (AuthPass
== true)
994 RetrievalDone(Message
);
996 // Still more retrieving to do
1001 // There was no signature file, so we are finished. Download
1002 // the indexes without verification.
1003 QueueIndexes(false);
1007 // There was a signature file, so pass it to gpgv for
1010 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1011 std::cerr
<< "Metaindex acquired, queueing gpg verification ("
1012 << SigFile
<< "," << DestFile
<< ")\n";
1014 Desc
.URI
= "gpgv:" + SigFile
;
1021 void pkgAcqMetaIndex::RetrievalDone(string Message
) /*{{{*/
1023 // We have just finished downloading a Release file (it is not
1026 string FileName
= LookupTag(Message
,"Filename");
1027 if (FileName
.empty() == true)
1030 ErrorText
= "Method gave a blank filename";
1034 if (FileName
!= DestFile
)
1037 Desc
.URI
= "copy:" + FileName
;
1042 // see if the download was a IMSHit
1043 IMSHit
= StringToBool(LookupTag(Message
,"IMS-Hit"),false);
1046 string FinalFile
= _config
->FindDir("Dir::State::lists");
1047 FinalFile
+= URItoFileName(RealURI
);
1049 // If we get a IMS hit we can remove the empty file in partial
1050 // othersie we move the file in place
1052 unlink(DestFile
.c_str());
1054 Rename(DestFile
,FinalFile
);
1056 chmod(FinalFile
.c_str(),0644);
1057 DestFile
= FinalFile
;
1060 void pkgAcqMetaIndex::AuthDone(string Message
) /*{{{*/
1062 // At this point, the gpgv method has succeeded, so there is a
1063 // valid signature from a key in the trusted keyring. We
1064 // perform additional verification of its contents, and use them
1065 // to verify the indexes we are about to download
1067 if (!MetaIndexParser
->Load(DestFile
))
1069 Status
= StatAuthError
;
1070 ErrorText
= MetaIndexParser
->ErrorText
;
1074 if (!VerifyVendor(Message
))
1079 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1080 std::cerr
<< "Signature verification succeeded: "
1081 << DestFile
<< std::endl
;
1083 // Download further indexes with verification
1086 // Done, move signature file into position
1088 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
1089 URItoFileName(RealURI
) + ".gpg";
1090 Rename(SigFile
,VerifiedSigFile
);
1091 chmod(VerifiedSigFile
.c_str(),0644);
1094 void pkgAcqMetaIndex::QueueIndexes(bool verify
) /*{{{*/
1096 for (vector
<struct IndexTarget
*>::const_iterator Target
= IndexTargets
->begin();
1097 Target
!= IndexTargets
->end();
1100 HashString ExpectedIndexHash
;
1103 const indexRecords::checkSum
*Record
= MetaIndexParser
->Lookup((*Target
)->MetaKey
);
1106 Status
= StatAuthError
;
1107 ErrorText
= "Unable to find expected entry "
1108 + (*Target
)->MetaKey
+ " in Meta-index file (malformed Release file?)";
1111 ExpectedIndexHash
= Record
->Hash
;
1112 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1114 std::cerr
<< "Queueing: " << (*Target
)->URI
<< std::endl
;
1115 std::cerr
<< "Expected Hash: " << ExpectedIndexHash
.toStr() << std::endl
;
1117 if (ExpectedIndexHash
.empty())
1119 Status
= StatAuthError
;
1120 ErrorText
= "Unable to find hash sum for "
1121 + (*Target
)->MetaKey
+ " in Meta-index file";
1126 // Queue Packages file (either diff or full packages files, depending
1127 // on the users option)
1128 if(_config
->FindB("Acquire::PDiffs",true) == true)
1129 new pkgAcqDiffIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
1130 (*Target
)->ShortDesc
, ExpectedIndexHash
);
1132 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
1133 (*Target
)->ShortDesc
, ExpectedIndexHash
);
1137 bool pkgAcqMetaIndex::VerifyVendor(string Message
) /*{{{*/
1139 // // Maybe this should be made available from above so we don't have
1140 // // to read and parse it every time?
1141 // pkgVendorList List;
1142 // List.ReadMainList();
1144 // const Vendor* Vndr = NULL;
1145 // for (std::vector<string>::const_iterator I = GPGVOutput.begin(); I != GPGVOutput.end(); I++)
1147 // string::size_type pos = (*I).find("VALIDSIG ");
1148 // if (_config->FindB("Debug::Vendor", false))
1149 // std::cerr << "Looking for VALIDSIG in \"" << (*I) << "\": pos " << pos
1151 // if (pos != std::string::npos)
1153 // string Fingerprint = (*I).substr(pos+sizeof("VALIDSIG"));
1154 // if (_config->FindB("Debug::Vendor", false))
1155 // std::cerr << "Looking for \"" << Fingerprint << "\" in vendor..." <<
1157 // Vndr = List.FindVendor(Fingerprint) != "";
1158 // if (Vndr != NULL);
1162 string::size_type pos
;
1164 // check for missing sigs (that where not fatal because otherwise we had
1167 string msg
= _("There is no public key available for the "
1168 "following key IDs:\n");
1169 pos
= Message
.find("NO_PUBKEY ");
1170 if (pos
!= std::string::npos
)
1172 string::size_type start
= pos
+strlen("NO_PUBKEY ");
1173 string Fingerprint
= Message
.substr(start
, Message
.find("\n")-start
);
1174 missingkeys
+= (Fingerprint
);
1176 if(!missingkeys
.empty())
1177 _error
->Warning("%s", string(msg
+missingkeys
).c_str());
1179 string Transformed
= MetaIndexParser
->GetExpectedDist();
1181 if (Transformed
== "../project/experimental")
1183 Transformed
= "experimental";
1186 pos
= Transformed
.rfind('/');
1187 if (pos
!= string::npos
)
1189 Transformed
= Transformed
.substr(0, pos
);
1192 if (Transformed
== ".")
1197 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1199 std::cerr
<< "Got Codename: " << MetaIndexParser
->GetDist() << std::endl
;
1200 std::cerr
<< "Expecting Dist: " << MetaIndexParser
->GetExpectedDist() << std::endl
;
1201 std::cerr
<< "Transformed Dist: " << Transformed
<< std::endl
;
1204 if (MetaIndexParser
->CheckDist(Transformed
) == false)
1206 // This might become fatal one day
1207 // Status = StatAuthError;
1208 // ErrorText = "Conflicting distribution; expected "
1209 // + MetaIndexParser->GetExpectedDist() + " but got "
1210 // + MetaIndexParser->GetDist();
1212 if (!Transformed
.empty())
1214 _error
->Warning("Conflicting distribution: %s (expected %s but got %s)",
1215 Desc
.Description
.c_str(),
1216 Transformed
.c_str(),
1217 MetaIndexParser
->GetDist().c_str());
1224 // pkgAcqMetaIndex::Failed - no Release file present or no signature file present /*{{{*/
1225 // ---------------------------------------------------------------------
1227 void pkgAcqMetaIndex::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
1229 if (AuthPass
== true)
1231 // if we fail the authentication but got the file via a IMS-Hit
1232 // this means that the file wasn't downloaded and that it might be
1233 // just stale (server problem, proxy etc). we delete what we have
1234 // queue it again without i-m-s
1235 // alternatively we could just unlink the file and let the user try again
1241 unlink(DestFile
.c_str());
1243 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
1244 DestFile
+= URItoFileName(RealURI
);
1250 // gpgv method failed
1251 _error
->Warning("GPG error: %s: %s",
1252 Desc
.Description
.c_str(),
1253 LookupTag(Message
,"Message").c_str());
1257 // No Release file was present, or verification failed, so fall
1258 // back to queueing Packages files without verification
1259 QueueIndexes(false);
1262 // AcqArchive::AcqArchive - Constructor /*{{{*/
1263 // ---------------------------------------------------------------------
1264 /* This just sets up the initial fetch environment and queues the first
1266 pkgAcqArchive::pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
1267 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
1268 string
&StoreFilename
) :
1269 Item(Owner
), Version(Version
), Sources(Sources
), Recs(Recs
),
1270 StoreFilename(StoreFilename
), Vf(Version
.FileList()),
1273 Retries
= _config
->FindI("Acquire::Retries",0);
1275 if (Version
.Arch() == 0)
1277 _error
->Error(_("I wasn't able to locate a file for the %s package. "
1278 "This might mean you need to manually fix this package. "
1279 "(due to missing arch)"),
1280 Version
.ParentPkg().Name());
1284 /* We need to find a filename to determine the extension. We make the
1285 assumption here that all the available sources for this version share
1286 the same extension.. */
1287 // Skip not source sources, they do not have file fields.
1288 for (; Vf
.end() == false; Vf
++)
1290 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
1295 // Does not really matter here.. we are going to fail out below
1296 if (Vf
.end() != true)
1298 // If this fails to get a file name we will bomb out below.
1299 pkgRecords::Parser
&Parse
= Recs
->Lookup(Vf
);
1300 if (_error
->PendingError() == true)
1303 // Generate the final file name as: package_version_arch.foo
1304 StoreFilename
= QuoteString(Version
.ParentPkg().Name(),"_:") + '_' +
1305 QuoteString(Version
.VerStr(),"_:") + '_' +
1306 QuoteString(Version
.Arch(),"_:.") +
1307 "." + flExtension(Parse
.FileName());
1310 // check if we have one trusted source for the package. if so, switch
1311 // to "TrustedOnly" mode
1312 for (pkgCache::VerFileIterator i
= Version
.FileList(); i
.end() == false; i
++)
1314 pkgIndexFile
*Index
;
1315 if (Sources
->FindIndex(i
.File(),Index
) == false)
1317 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1319 std::cerr
<< "Checking index: " << Index
->Describe()
1320 << "(Trusted=" << Index
->IsTrusted() << ")\n";
1322 if (Index
->IsTrusted()) {
1328 // "allow-unauthenticated" restores apts old fetching behaviour
1329 // that means that e.g. unauthenticated file:// uris are higher
1330 // priority than authenticated http:// uris
1331 if (_config
->FindB("APT::Get::AllowUnauthenticated",false) == true)
1335 if (QueueNext() == false && _error
->PendingError() == false)
1336 _error
->Error(_("I wasn't able to locate file for the %s package. "
1337 "This might mean you need to manually fix this package."),
1338 Version
.ParentPkg().Name());
1341 // AcqArchive::QueueNext - Queue the next file source /*{{{*/
1342 // ---------------------------------------------------------------------
1343 /* This queues the next available file version for download. It checks if
1344 the archive is already available in the cache and stashs the MD5 for
1346 bool pkgAcqArchive::QueueNext()
1348 for (; Vf
.end() == false; Vf
++)
1350 // Ignore not source sources
1351 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
1354 // Try to cross match against the source list
1355 pkgIndexFile
*Index
;
1356 if (Sources
->FindIndex(Vf
.File(),Index
) == false)
1359 // only try to get a trusted package from another source if that source
1361 if(Trusted
&& !Index
->IsTrusted())
1364 // Grab the text package record
1365 pkgRecords::Parser
&Parse
= Recs
->Lookup(Vf
);
1366 if (_error
->PendingError() == true)
1369 string PkgFile
= Parse
.FileName();
1370 if(Parse
.SHA256Hash() != "")
1371 ExpectedHash
= HashString("SHA256", Parse
.SHA256Hash());
1372 else if (Parse
.SHA1Hash() != "")
1373 ExpectedHash
= HashString("SHA1", Parse
.SHA1Hash());
1375 ExpectedHash
= HashString("MD5Sum", Parse
.MD5Hash());
1376 if (PkgFile
.empty() == true)
1377 return _error
->Error(_("The package index files are corrupted. No Filename: "
1378 "field for package %s."),
1379 Version
.ParentPkg().Name());
1381 Desc
.URI
= Index
->ArchiveURI(PkgFile
);
1382 Desc
.Description
= Index
->ArchiveInfo(Version
);
1384 Desc
.ShortDesc
= Version
.ParentPkg().Name();
1386 // See if we already have the file. (Legacy filenames)
1387 FileSize
= Version
->Size
;
1388 string FinalFile
= _config
->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile
);
1390 if (stat(FinalFile
.c_str(),&Buf
) == 0)
1392 // Make sure the size matches
1393 if ((unsigned)Buf
.st_size
== Version
->Size
)
1398 StoreFilename
= DestFile
= FinalFile
;
1402 /* Hmm, we have a file and its size does not match, this means it is
1403 an old style mismatched arch */
1404 unlink(FinalFile
.c_str());
1407 // Check it again using the new style output filenames
1408 FinalFile
= _config
->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename
);
1409 if (stat(FinalFile
.c_str(),&Buf
) == 0)
1411 // Make sure the size matches
1412 if ((unsigned)Buf
.st_size
== Version
->Size
)
1417 StoreFilename
= DestFile
= FinalFile
;
1421 /* Hmm, we have a file and its size does not match, this shouldnt
1423 unlink(FinalFile
.c_str());
1426 DestFile
= _config
->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(StoreFilename
);
1428 // Check the destination file
1429 if (stat(DestFile
.c_str(),&Buf
) == 0)
1431 // Hmm, the partial file is too big, erase it
1432 if ((unsigned)Buf
.st_size
> Version
->Size
)
1433 unlink(DestFile
.c_str());
1435 PartialSize
= Buf
.st_size
;
1440 Desc
.URI
= Index
->ArchiveURI(PkgFile
);
1441 Desc
.Description
= Index
->ArchiveInfo(Version
);
1443 Desc
.ShortDesc
= Version
.ParentPkg().Name();
1452 // AcqArchive::Done - Finished fetching /*{{{*/
1453 // ---------------------------------------------------------------------
1455 void pkgAcqArchive::Done(string Message
,unsigned long Size
,string CalcHash
,
1456 pkgAcquire::MethodConfig
*Cfg
)
1458 Item::Done(Message
,Size
,CalcHash
,Cfg
);
1461 if (Size
!= Version
->Size
)
1464 ErrorText
= _("Size mismatch");
1469 if(ExpectedHash
.toStr() != CalcHash
)
1472 ErrorText
= _("Hash Sum mismatch");
1473 if(FileExists(DestFile
))
1474 Rename(DestFile
,DestFile
+ ".FAILED");
1478 // Grab the output filename
1479 string FileName
= LookupTag(Message
,"Filename");
1480 if (FileName
.empty() == true)
1483 ErrorText
= "Method gave a blank filename";
1489 // Reference filename
1490 if (FileName
!= DestFile
)
1492 StoreFilename
= DestFile
= FileName
;
1497 // Done, move it into position
1498 string FinalFile
= _config
->FindDir("Dir::Cache::Archives");
1499 FinalFile
+= flNotDir(StoreFilename
);
1500 Rename(DestFile
,FinalFile
);
1502 StoreFilename
= DestFile
= FinalFile
;
1506 // AcqArchive::Failed - Failure handler /*{{{*/
1507 // ---------------------------------------------------------------------
1508 /* Here we try other sources */
1509 void pkgAcqArchive::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
1511 ErrorText
= LookupTag(Message
,"Message");
1513 /* We don't really want to retry on failed media swaps, this prevents
1514 that. An interesting observation is that permanent failures are not
1516 if (Cnf
->Removable
== true &&
1517 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
1519 // Vf = Version.FileList();
1520 while (Vf
.end() == false) Vf
++;
1521 StoreFilename
= string();
1522 Item::Failed(Message
,Cnf
);
1526 if (QueueNext() == false)
1528 // This is the retry counter
1530 Cnf
->LocalOnly
== false &&
1531 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
1534 Vf
= Version
.FileList();
1535 if (QueueNext() == true)
1539 StoreFilename
= string();
1540 Item::Failed(Message
,Cnf
);
1544 // AcqArchive::IsTrusted - Determine whether this archive comes from a trusted source /*{{{*/
1545 // ---------------------------------------------------------------------
1546 bool pkgAcqArchive::IsTrusted()
1551 // AcqArchive::Finished - Fetching has finished, tidy up /*{{{*/
1552 // ---------------------------------------------------------------------
1554 void pkgAcqArchive::Finished()
1556 if (Status
== pkgAcquire::Item::StatDone
&&
1559 StoreFilename
= string();
1562 // AcqFile::pkgAcqFile - Constructor /*{{{*/
1563 // ---------------------------------------------------------------------
1564 /* The file is added to the queue */
1565 pkgAcqFile::pkgAcqFile(pkgAcquire
*Owner
,string URI
,string Hash
,
1566 unsigned long Size
,string Dsc
,string ShortDesc
,
1567 const string
&DestDir
, const string
&DestFilename
,
1569 Item(Owner
), ExpectedHash(Hash
), IsIndexFile(IsIndexFile
)
1571 Retries
= _config
->FindI("Acquire::Retries",0);
1573 if(!DestFilename
.empty())
1574 DestFile
= DestFilename
;
1575 else if(!DestDir
.empty())
1576 DestFile
= DestDir
+ "/" + flNotDir(URI
);
1578 DestFile
= flNotDir(URI
);
1582 Desc
.Description
= Dsc
;
1585 // Set the short description to the archive component
1586 Desc
.ShortDesc
= ShortDesc
;
1588 // Get the transfer sizes
1591 if (stat(DestFile
.c_str(),&Buf
) == 0)
1593 // Hmm, the partial file is too big, erase it
1594 if ((unsigned)Buf
.st_size
> Size
)
1595 unlink(DestFile
.c_str());
1597 PartialSize
= Buf
.st_size
;
1603 // AcqFile::Done - Item downloaded OK /*{{{*/
1604 // ---------------------------------------------------------------------
1606 void pkgAcqFile::Done(string Message
,unsigned long Size
,string CalcHash
,
1607 pkgAcquire::MethodConfig
*Cnf
)
1609 Item::Done(Message
,Size
,CalcHash
,Cnf
);
1612 if(!ExpectedHash
.empty() && ExpectedHash
.toStr() != CalcHash
)
1615 ErrorText
= "Hash Sum mismatch";
1616 Rename(DestFile
,DestFile
+ ".FAILED");
1620 string FileName
= LookupTag(Message
,"Filename");
1621 if (FileName
.empty() == true)
1624 ErrorText
= "Method gave a blank filename";
1630 // The files timestamp matches
1631 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
1634 // We have to copy it into place
1635 if (FileName
!= DestFile
)
1638 if (_config
->FindB("Acquire::Source-Symlinks",true) == false ||
1639 Cnf
->Removable
== true)
1641 Desc
.URI
= "copy:" + FileName
;
1646 // Erase the file if it is a symlink so we can overwrite it
1648 if (lstat(DestFile
.c_str(),&St
) == 0)
1650 if (S_ISLNK(St
.st_mode
) != 0)
1651 unlink(DestFile
.c_str());
1655 if (symlink(FileName
.c_str(),DestFile
.c_str()) != 0)
1657 ErrorText
= "Link to " + DestFile
+ " failure ";
1664 // AcqFile::Failed - Failure handler /*{{{*/
1665 // ---------------------------------------------------------------------
1666 /* Here we try other sources */
1667 void pkgAcqFile::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
1669 ErrorText
= LookupTag(Message
,"Message");
1671 // This is the retry counter
1673 Cnf
->LocalOnly
== false &&
1674 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
1681 Item::Failed(Message
,Cnf
);
1684 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
1685 // ---------------------------------------------------------------------
1686 /* The only header we use is the last-modified header. */
1687 string
pkgAcqFile::Custom600Headers()
1690 return "\nIndex-File: true";