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>
41 // Acquire::Item::Item - Constructor /*{{{*/
42 // ---------------------------------------------------------------------
44 pkgAcquire::Item::Item(pkgAcquire
*Owner
) : Owner(Owner
), FileSize(0),
45 PartialSize(0), Mode(0), ID(0), Complete(false),
46 Local(false), QueueCounter(0)
52 // Acquire::Item::~Item - Destructor /*{{{*/
53 // ---------------------------------------------------------------------
55 pkgAcquire::Item::~Item()
60 // Acquire::Item::Failed - Item failed to download /*{{{*/
61 // ---------------------------------------------------------------------
62 /* We return to an idle state if there are still other queues that could
64 void pkgAcquire::Item::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
67 ErrorText
= LookupTag(Message
,"Message");
68 if (QueueCounter
<= 1)
70 /* This indicates that the file is not available right now but might
71 be sometime later. If we do a retry cycle then this should be
73 if (Cnf
->LocalOnly
== true &&
74 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
86 // Acquire::Item::Start - Item has begun to download /*{{{*/
87 // ---------------------------------------------------------------------
88 /* Stash status and the file size. Note that setting Complete means
89 sub-phases of the acquire process such as decompresion are operating */
90 void pkgAcquire::Item::Start(string
/*Message*/,unsigned long Size
)
92 Status
= StatFetching
;
93 if (FileSize
== 0 && Complete
== false)
97 // Acquire::Item::Done - Item downloaded OK /*{{{*/
98 // ---------------------------------------------------------------------
100 void pkgAcquire::Item::Done(string Message
,unsigned long Size
,string Hash
,
101 pkgAcquire::MethodConfig
*Cnf
)
103 // We just downloaded something..
104 string FileName
= LookupTag(Message
,"Filename");
105 // we only inform the Log class if it was actually not a local thing
106 if (Complete
== false && !Local
&& FileName
== DestFile
)
109 Owner
->Log
->Fetched(Size
,atoi(LookupTag(Message
,"Resume-Point","0").c_str()));
116 ErrorText
= string();
117 Owner
->Dequeue(this);
120 // Acquire::Item::Rename - Rename a file /*{{{*/
121 // ---------------------------------------------------------------------
122 /* This helper function is used by alot of item methods as thier final
124 void pkgAcquire::Item::Rename(string From
,string To
)
126 if (rename(From
.c_str(),To
.c_str()) != 0)
129 snprintf(S
,sizeof(S
),_("rename failed, %s (%s -> %s)."),strerror(errno
),
130 From
.c_str(),To
.c_str());
136 // AcqDiffIndex::AcqDiffIndex - Constructor /*{{{*/
137 // ---------------------------------------------------------------------
138 /* Get the DiffIndex file first and see if there are patches availabe
139 * If so, create a pkgAcqIndexDiffs fetcher that will get and apply the
140 * patches. If anything goes wrong in that process, it will fall back to
141 * the original packages file
143 pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire
*Owner
,
144 string URI
,string URIDesc
,string ShortDesc
,
145 HashString ExpectedHash
)
146 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
),
150 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
152 Desc
.Description
= URIDesc
+ "/DiffIndex";
154 Desc
.ShortDesc
= ShortDesc
;
155 Desc
.URI
= URI
+ ".diff/Index";
157 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
158 DestFile
+= URItoFileName(URI
) + string(".DiffIndex");
161 std::clog
<< "pkgAcqDiffIndex: " << Desc
.URI
<< std::endl
;
163 // look for the current package file
164 CurrentPackagesFile
= _config
->FindDir("Dir::State::lists");
165 CurrentPackagesFile
+= URItoFileName(RealURI
);
167 // FIXME: this file:/ check is a hack to prevent fetching
168 // from local sources. this is really silly, and
169 // should be fixed cleanly as soon as possible
170 if(!FileExists(CurrentPackagesFile
) ||
171 Desc
.URI
.substr(0,strlen("file:/")) == "file:/")
173 // we don't have a pkg file or we don't want to queue
175 std::clog
<< "No index file, local or canceld by user" << std::endl
;
181 std::clog
<< "pkgAcqIndexDiffs::pkgAcqIndexDiffs(): "
182 << CurrentPackagesFile
<< std::endl
;
188 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
189 // ---------------------------------------------------------------------
190 /* The only header we use is the last-modified header. */
191 string
pkgAcqDiffIndex::Custom600Headers()
193 string Final
= _config
->FindDir("Dir::State::lists");
194 Final
+= URItoFileName(RealURI
) + string(".IndexDiff");
197 std::clog
<< "Custom600Header-IMS: " << Final
<< std::endl
;
200 if (stat(Final
.c_str(),&Buf
) != 0)
201 return "\nIndex-File: true";
203 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
206 bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile
) /*{{{*/
209 std::clog
<< "pkgAcqIndexDiffs::ParseIndexDiff() " << IndexDiffFile
214 vector
<DiffInfo
> available_patches
;
216 FileFd
Fd(IndexDiffFile
,FileFd::ReadOnly
);
218 if (_error
->PendingError() == true)
221 if(TF
.Step(Tags
) == true)
227 string
const tmp
= Tags
.FindS("SHA1-Current");
228 std::stringstream
ss(tmp
);
229 ss
>> ServerSha1
>> size
;
230 unsigned long const ServerSize
= atol(size
.c_str());
232 FileFd
fd(CurrentPackagesFile
, FileFd::ReadOnly
);
234 SHA1
.AddFD(fd
.Fd(), fd
.Size());
235 string
const local_sha1
= SHA1
.Result();
237 if(local_sha1
== ServerSha1
)
239 // we have the same sha1 as the server
241 std::clog
<< "Package file is up-to-date" << std::endl
;
242 // set found to true, this will queue a pkgAcqIndexDiffs with
243 // a empty availabe_patches
249 std::clog
<< "SHA1-Current: " << ServerSha1
<< std::endl
;
251 // check the historie and see what patches we need
252 string
const history
= Tags
.FindS("SHA1-History");
253 std::stringstream
hist(history
);
254 while(hist
>> d
.sha1
>> size
>> d
.file
)
256 // read until the first match is found
257 // from that point on, we probably need all diffs
258 if(d
.sha1
== local_sha1
)
260 else if (found
== false)
264 std::clog
<< "Need to get diff: " << d
.file
<< std::endl
;
265 available_patches
.push_back(d
);
268 if (available_patches
.empty() == false)
270 // patching with too many files is rather slow compared to a fast download
271 unsigned long const fileLimit
= _config
->FindI("Acquire::PDiffs::FileLimit", 0);
272 if (fileLimit
!= 0 && fileLimit
< available_patches
.size())
275 std::clog
<< "Need " << available_patches
.size() << " diffs (Limit is " << fileLimit
276 << ") so fallback to complete download" << std::endl
;
280 // see if the patches are too big
281 found
= false; // it was true and it will be true again at the end
282 d
= *available_patches
.begin();
283 string
const firstPatch
= d
.file
;
284 unsigned long patchesSize
= 0;
285 std::stringstream
patches(Tags
.FindS("SHA1-Patches"));
286 while(patches
>> d
.sha1
>> size
>> d
.file
)
288 if (firstPatch
== d
.file
)
290 else if (found
== false)
293 patchesSize
+= atol(size
.c_str());
295 unsigned long const sizeLimit
= ServerSize
* _config
->FindI("Acquire::PDiffs::SizeLimit", 100);
296 if (sizeLimit
> 0 && (sizeLimit
/100) < patchesSize
)
299 std::clog
<< "Need " << patchesSize
<< " bytes (Limit is " << sizeLimit
/100
300 << ") so fallback to complete download" << std::endl
;
306 // we have something, queue the next diff
310 string::size_type
const last_space
= Description
.rfind(" ");
311 if(last_space
!= string::npos
)
312 Description
.erase(last_space
, Description
.size()-last_space
);
313 new pkgAcqIndexDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
314 ExpectedHash
, ServerSha1
, available_patches
);
322 // Nothing found, report and return false
323 // Failing here is ok, if we return false later, the full
324 // IndexFile is queued
326 std::clog
<< "Can't find a patch in the index file" << std::endl
;
330 void pkgAcqDiffIndex::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
) /*{{{*/
333 std::clog
<< "pkgAcqDiffIndex failed: " << Desc
.URI
<< std::endl
334 << "Falling back to normal index file aquire" << std::endl
;
336 new pkgAcqIndex(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
344 void pkgAcqDiffIndex::Done(string Message
,unsigned long Size
,string Md5Hash
, /*{{{*/
345 pkgAcquire::MethodConfig
*Cnf
)
348 std::clog
<< "pkgAcqDiffIndex::Done(): " << Desc
.URI
<< std::endl
;
350 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
353 FinalFile
= _config
->FindDir("Dir::State::lists")+URItoFileName(RealURI
);
355 // sucess in downloading the index
357 FinalFile
+= string(".IndexDiff");
359 std::clog
<< "Renaming: " << DestFile
<< " -> " << FinalFile
361 Rename(DestFile
,FinalFile
);
362 chmod(FinalFile
.c_str(),0644);
363 DestFile
= FinalFile
;
365 if(!ParseDiffIndex(DestFile
))
366 return Failed("", NULL
);
374 // AcqIndexDiffs::AcqIndexDiffs - Constructor /*{{{*/
375 // ---------------------------------------------------------------------
376 /* The package diff is added to the queue. one object is constructed
377 * for each diff and the index
379 pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire
*Owner
,
380 string URI
,string URIDesc
,string ShortDesc
,
381 HashString ExpectedHash
,
383 vector
<DiffInfo
> diffs
)
384 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
),
385 available_patches(diffs
), ServerSha1(ServerSha1
)
388 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
389 DestFile
+= URItoFileName(URI
);
391 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
393 Description
= URIDesc
;
395 Desc
.ShortDesc
= ShortDesc
;
397 if(available_patches
.size() == 0)
399 // we are done (yeah!)
405 State
= StateFetchDiff
;
410 void pkgAcqIndexDiffs::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
) /*{{{*/
413 std::clog
<< "pkgAcqIndexDiffs failed: " << Desc
.URI
<< std::endl
414 << "Falling back to normal index file aquire" << std::endl
;
415 new pkgAcqIndex(Owner
, RealURI
, Description
,Desc
.ShortDesc
,
420 // Finish - helper that cleans the item out of the fetcher queue /*{{{*/
421 void pkgAcqIndexDiffs::Finish(bool allDone
)
423 // we restore the original name, this is required, otherwise
424 // the file will be cleaned
427 DestFile
= _config
->FindDir("Dir::State::lists");
428 DestFile
+= URItoFileName(RealURI
);
430 if(!ExpectedHash
.empty() && !ExpectedHash
.VerifyFile(DestFile
))
432 Status
= StatAuthError
;
433 ErrorText
= _("MD5Sum mismatch");
434 Rename(DestFile
,DestFile
+ ".FAILED");
439 // this is for the "real" finish
444 std::clog
<< "\n\nallDone: " << DestFile
<< "\n" << std::endl
;
449 std::clog
<< "Finishing: " << Desc
.URI
<< std::endl
;
456 bool pkgAcqIndexDiffs::QueueNextDiff() /*{{{*/
459 // calc sha1 of the just patched file
460 string FinalFile
= _config
->FindDir("Dir::State::lists");
461 FinalFile
+= URItoFileName(RealURI
);
463 FileFd
fd(FinalFile
, FileFd::ReadOnly
);
465 SHA1
.AddFD(fd
.Fd(), fd
.Size());
466 string local_sha1
= string(SHA1
.Result());
468 std::clog
<< "QueueNextDiff: "
469 << FinalFile
<< " (" << local_sha1
<< ")"<<std::endl
;
471 // final file reached before all patches are applied
472 if(local_sha1
== ServerSha1
)
478 // remove all patches until the next matching patch is found
479 // this requires the Index file to be ordered
480 for(vector
<DiffInfo
>::iterator I
=available_patches
.begin();
481 available_patches
.size() > 0 &&
482 I
!= available_patches
.end() &&
483 (*I
).sha1
!= local_sha1
;
486 available_patches
.erase(I
);
489 // error checking and falling back if no patch was found
490 if(available_patches
.size() == 0)
496 // queue the right diff
497 Desc
.URI
= string(RealURI
) + ".diff/" + available_patches
[0].file
+ ".gz";
498 Desc
.Description
= Description
+ " " + available_patches
[0].file
+ string(".pdiff");
499 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
500 DestFile
+= URItoFileName(RealURI
+ ".diff/" + available_patches
[0].file
);
503 std::clog
<< "pkgAcqIndexDiffs::QueueNextDiff(): " << Desc
.URI
<< std::endl
;
510 void pkgAcqIndexDiffs::Done(string Message
,unsigned long Size
,string Md5Hash
, /*{{{*/
511 pkgAcquire::MethodConfig
*Cnf
)
514 std::clog
<< "pkgAcqIndexDiffs::Done(): " << Desc
.URI
<< std::endl
;
516 Item::Done(Message
,Size
,Md5Hash
,Cnf
);
519 FinalFile
= _config
->FindDir("Dir::State::lists")+URItoFileName(RealURI
);
521 // sucess in downloading a diff, enter ApplyDiff state
522 if(State
== StateFetchDiff
)
526 std::clog
<< "Sending to gzip method: " << FinalFile
<< std::endl
;
528 string FileName
= LookupTag(Message
,"Filename");
529 State
= StateUnzipDiff
;
531 Desc
.URI
= "gzip:" + FileName
;
532 DestFile
+= ".decomp";
538 // sucess in downloading a diff, enter ApplyDiff state
539 if(State
== StateUnzipDiff
)
542 // rred excepts the patch as $FinalFile.ed
543 Rename(DestFile
,FinalFile
+".ed");
546 std::clog
<< "Sending to rred method: " << FinalFile
<< std::endl
;
548 State
= StateApplyDiff
;
550 Desc
.URI
= "rred:" + FinalFile
;
557 // success in download/apply a diff, queue next (if needed)
558 if(State
== StateApplyDiff
)
560 // remove the just applied patch
561 available_patches
.erase(available_patches
.begin());
566 std::clog
<< "Moving patched file in place: " << std::endl
567 << DestFile
<< " -> " << FinalFile
<< std::endl
;
569 Rename(DestFile
,FinalFile
);
570 chmod(FinalFile
.c_str(),0644);
572 // see if there is more to download
573 if(available_patches
.size() > 0) {
574 new pkgAcqIndexDiffs(Owner
, RealURI
, Description
, Desc
.ShortDesc
,
575 ExpectedHash
, ServerSha1
, available_patches
);
582 // AcqIndex::AcqIndex - Constructor /*{{{*/
583 // ---------------------------------------------------------------------
584 /* The package file is added to the queue and a second class is
585 instantiated to fetch the revision file */
586 pkgAcqIndex::pkgAcqIndex(pkgAcquire
*Owner
,
587 string URI
,string URIDesc
,string ShortDesc
,
588 HashString ExpectedHash
, string comprExt
)
589 : Item(Owner
), RealURI(URI
), ExpectedHash(ExpectedHash
)
591 Decompression
= false;
594 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
595 DestFile
+= URItoFileName(URI
);
599 // autoselect the compression method
600 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
601 if (types
.empty() == true)
604 comprExt
= "." + types
[0];
606 CompressionExtension
= ((comprExt
== "plain" || comprExt
== ".") ? "" : comprExt
);
608 Desc
.URI
= URI
+ CompressionExtension
;
610 Desc
.Description
= URIDesc
;
612 Desc
.ShortDesc
= ShortDesc
;
617 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
618 // ---------------------------------------------------------------------
619 /* The only header we use is the last-modified header. */
620 string
pkgAcqIndex::Custom600Headers()
622 string Final
= _config
->FindDir("Dir::State::lists");
623 Final
+= URItoFileName(RealURI
);
626 if (stat(Final
.c_str(),&Buf
) != 0)
627 return "\nIndex-File: true";
629 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
632 void pkgAcqIndex::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
) /*{{{*/
634 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
636 for (std::vector
<std::string
>::const_iterator t
= types
.begin();
637 t
!= types
.end(); t
++)
639 // jump over all already tried compression types
640 const unsigned int nameLen
= Desc
.URI
.size() - (*t
).size();
641 if(Desc
.URI
.substr(nameLen
) != *t
)
644 // we want to try it with the next extension (and make sure to
645 // not skip over the end)
647 if (t
== types
.end())
650 // queue new download
651 Desc
.URI
= Desc
.URI
.substr(0, nameLen
) + *t
;
652 new pkgAcqIndex(Owner
, RealURI
, Desc
.Description
, Desc
.ShortDesc
,
653 ExpectedHash
, string(".").append(*t
));
661 // on decompression failure, remove bad versions in partial/
662 if(Decompression
&& Erase
) {
663 string s
= _config
->FindDir("Dir::State::lists") + "partial/";
664 s
+= URItoFileName(RealURI
);
668 Item::Failed(Message
,Cnf
);
671 // AcqIndex::Done - Finished a fetch /*{{{*/
672 // ---------------------------------------------------------------------
673 /* This goes through a number of states.. On the initial fetch the
674 method could possibly return an alternate filename which points
675 to the uncompressed version of the file. If this is so the file
676 is copied into the partial directory. In all other cases the file
677 is decompressed with a gzip uri. */
678 void pkgAcqIndex::Done(string Message
,unsigned long Size
,string Hash
,
679 pkgAcquire::MethodConfig
*Cfg
)
681 Item::Done(Message
,Size
,Hash
,Cfg
);
683 if (Decompression
== true)
685 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
687 std::cerr
<< std::endl
<< RealURI
<< ": Computed Hash: " << Hash
;
688 std::cerr
<< " Expected Hash: " << ExpectedHash
.toStr() << std::endl
;
691 if (!ExpectedHash
.empty() && ExpectedHash
.toStr() != Hash
)
693 Status
= StatAuthError
;
694 ErrorText
= _("Hash Sum mismatch");
695 Rename(DestFile
,DestFile
+ ".FAILED");
698 // Done, move it into position
699 string FinalFile
= _config
->FindDir("Dir::State::lists");
700 FinalFile
+= URItoFileName(RealURI
);
701 Rename(DestFile
,FinalFile
);
702 chmod(FinalFile
.c_str(),0644);
704 /* We restore the original name to DestFile so that the clean operation
706 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
707 DestFile
+= URItoFileName(RealURI
);
709 // Remove the compressed version.
711 unlink(DestFile
.c_str());
718 // Handle the unzipd case
719 string FileName
= LookupTag(Message
,"Alt-Filename");
720 if (FileName
.empty() == false)
722 // The files timestamp matches
723 if (StringToBool(LookupTag(Message
,"Alt-IMS-Hit"),false) == true)
725 Decompression
= true;
727 DestFile
+= ".decomp";
728 Desc
.URI
= "copy:" + FileName
;
734 FileName
= LookupTag(Message
,"Filename");
735 if (FileName
.empty() == true)
738 ErrorText
= "Method gave a blank filename";
741 // The files timestamp matches
742 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
745 if (FileName
== DestFile
)
750 string compExt
= flExtension(flNotDir(URI(Desc
.URI
).Path
));
753 // get the binary name for your used compression type
754 decompProg
= _config
->Find(string("Acquire::CompressionTypes::").append(compExt
),"");
755 if(decompProg
.empty() == false);
756 // flExtensions returns the full name if no extension is found
757 // this is why we have this complicated compare operation here
758 // FIMXE: add a new flJustExtension() that return "" if no
759 // extension is found and use that above so that it can
760 // be tested against ""
761 else if(compExt
== flNotDir(URI(Desc
.URI
).Path
))
764 _error
->Error("Unsupported extension: %s", compExt
.c_str());
768 Decompression
= true;
769 DestFile
+= ".decomp";
770 Desc
.URI
= decompProg
+ ":" + FileName
;
772 Mode
= decompProg
.c_str();
775 // AcqIndexTrans::pkgAcqIndexTrans - Constructor /*{{{*/
776 // ---------------------------------------------------------------------
777 /* The Translation file is added to the queue */
778 pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire
*Owner
,
779 string URI
,string URIDesc
,string ShortDesc
)
780 : pkgAcqIndex(Owner
, URI
, URIDesc
, ShortDesc
, HashString(), "")
784 // AcqIndexTrans::Failed - Silence failure messages for missing files /*{{{*/
785 // ---------------------------------------------------------------------
787 void pkgAcqIndexTrans::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
789 if (Cnf
->LocalOnly
== true ||
790 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == false)
799 Item::Failed(Message
,Cnf
);
802 pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire
*Owner
, /*{{{*/
803 string URI
,string URIDesc
,string ShortDesc
,
804 string MetaIndexURI
, string MetaIndexURIDesc
,
805 string MetaIndexShortDesc
,
806 const vector
<IndexTarget
*>* IndexTargets
,
807 indexRecords
* MetaIndexParser
) :
808 Item(Owner
), RealURI(URI
), MetaIndexURI(MetaIndexURI
),
809 MetaIndexURIDesc(MetaIndexURIDesc
), MetaIndexShortDesc(MetaIndexShortDesc
),
810 MetaIndexParser(MetaIndexParser
), IndexTargets(IndexTargets
)
812 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
813 DestFile
+= URItoFileName(URI
);
815 // remove any partial downloaded sig-file in partial/.
816 // it may confuse proxies and is too small to warrant a
817 // partial download anyway
818 unlink(DestFile
.c_str());
821 Desc
.Description
= URIDesc
;
823 Desc
.ShortDesc
= ShortDesc
;
826 string Final
= _config
->FindDir("Dir::State::lists");
827 Final
+= URItoFileName(RealURI
);
829 if (stat(Final
.c_str(),&Buf
) == 0)
831 // File was already in place. It needs to be re-downloaded/verified
832 // because Release might have changed, we do give it a differnt
833 // name than DestFile because otherwise the http method will
834 // send If-Range requests and there are too many broken servers
835 // out there that do not understand them
836 LastGoodSig
= DestFile
+".reverify";
837 Rename(Final
,LastGoodSig
);
843 // pkgAcqMetaSig::Custom600Headers - Insert custom request headers /*{{{*/
844 // ---------------------------------------------------------------------
845 /* The only header we use is the last-modified header. */
846 string
pkgAcqMetaSig::Custom600Headers()
849 if (stat(LastGoodSig
.c_str(),&Buf
) != 0)
850 return "\nIndex-File: true";
852 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
855 void pkgAcqMetaSig::Done(string Message
,unsigned long Size
,string MD5
,
856 pkgAcquire::MethodConfig
*Cfg
)
858 Item::Done(Message
,Size
,MD5
,Cfg
);
860 string FileName
= LookupTag(Message
,"Filename");
861 if (FileName
.empty() == true)
864 ErrorText
= "Method gave a blank filename";
868 if (FileName
!= DestFile
)
870 // We have to copy it into place
872 Desc
.URI
= "copy:" + FileName
;
879 // put the last known good file back on i-m-s hit (it will
880 // be re-verified again)
881 // Else do nothing, we have the new file in DestFile then
882 if(StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
883 Rename(LastGoodSig
, DestFile
);
885 // queue a pkgAcqMetaIndex to be verified against the sig we just retrieved
886 new pkgAcqMetaIndex(Owner
, MetaIndexURI
, MetaIndexURIDesc
, MetaIndexShortDesc
,
887 DestFile
, IndexTargets
, MetaIndexParser
);
891 void pkgAcqMetaSig::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)/*{{{*/
893 string Final
= _config
->FindDir("Dir::State::lists") + URItoFileName(RealURI
);
895 // if we get a network error we fail gracefully
896 if(Status
== StatTransientNetworkError
)
898 Item::Failed(Message
,Cnf
);
899 // move the sigfile back on transient network failures
900 if(FileExists(DestFile
))
901 Rename(LastGoodSig
,Final
);
903 // set the status back to , Item::Failed likes to reset it
904 Status
= pkgAcquire::Item::StatTransientNetworkError
;
908 // Delete any existing sigfile when the acquire failed
909 unlink(Final
.c_str());
911 // queue a pkgAcqMetaIndex with no sigfile
912 new pkgAcqMetaIndex(Owner
, MetaIndexURI
, MetaIndexURIDesc
, MetaIndexShortDesc
,
913 "", IndexTargets
, MetaIndexParser
);
915 if (Cnf
->LocalOnly
== true ||
916 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == false)
925 Item::Failed(Message
,Cnf
);
928 pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire
*Owner
, /*{{{*/
929 string URI
,string URIDesc
,string ShortDesc
,
931 const vector
<struct IndexTarget
*>* IndexTargets
,
932 indexRecords
* MetaIndexParser
) :
933 Item(Owner
), RealURI(URI
), SigFile(SigFile
), IndexTargets(IndexTargets
),
934 MetaIndexParser(MetaIndexParser
), AuthPass(false), IMSHit(false)
936 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
937 DestFile
+= URItoFileName(URI
);
940 Desc
.Description
= URIDesc
;
942 Desc
.ShortDesc
= ShortDesc
;
948 // pkgAcqMetaIndex::Custom600Headers - Insert custom request headers /*{{{*/
949 // ---------------------------------------------------------------------
950 /* The only header we use is the last-modified header. */
951 string
pkgAcqMetaIndex::Custom600Headers()
953 string Final
= _config
->FindDir("Dir::State::lists");
954 Final
+= URItoFileName(RealURI
);
957 if (stat(Final
.c_str(),&Buf
) != 0)
958 return "\nIndex-File: true";
960 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
963 void pkgAcqMetaIndex::Done(string Message
,unsigned long Size
,string Hash
, /*{{{*/
964 pkgAcquire::MethodConfig
*Cfg
)
966 Item::Done(Message
,Size
,Hash
,Cfg
);
968 // MetaIndexes are done in two passes: one to download the
969 // metaindex with an appropriate method, and a second to verify it
970 // with the gpgv method
972 if (AuthPass
== true)
978 RetrievalDone(Message
);
980 // Still more retrieving to do
985 // There was no signature file, so we are finished. Download
986 // the indexes without verification.
991 // There was a signature file, so pass it to gpgv for
994 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
995 std::cerr
<< "Metaindex acquired, queueing gpg verification ("
996 << SigFile
<< "," << DestFile
<< ")\n";
998 Desc
.URI
= "gpgv:" + SigFile
;
1005 void pkgAcqMetaIndex::RetrievalDone(string Message
) /*{{{*/
1007 // We have just finished downloading a Release file (it is not
1010 string FileName
= LookupTag(Message
,"Filename");
1011 if (FileName
.empty() == true)
1014 ErrorText
= "Method gave a blank filename";
1018 if (FileName
!= DestFile
)
1021 Desc
.URI
= "copy:" + FileName
;
1026 // see if the download was a IMSHit
1027 IMSHit
= StringToBool(LookupTag(Message
,"IMS-Hit"),false);
1030 string FinalFile
= _config
->FindDir("Dir::State::lists");
1031 FinalFile
+= URItoFileName(RealURI
);
1033 // If we get a IMS hit we can remove the empty file in partial
1034 // othersie we move the file in place
1036 unlink(DestFile
.c_str());
1038 Rename(DestFile
,FinalFile
);
1040 chmod(FinalFile
.c_str(),0644);
1041 DestFile
= FinalFile
;
1044 void pkgAcqMetaIndex::AuthDone(string Message
) /*{{{*/
1046 // At this point, the gpgv method has succeeded, so there is a
1047 // valid signature from a key in the trusted keyring. We
1048 // perform additional verification of its contents, and use them
1049 // to verify the indexes we are about to download
1051 if (!MetaIndexParser
->Load(DestFile
))
1053 Status
= StatAuthError
;
1054 ErrorText
= MetaIndexParser
->ErrorText
;
1058 if (!VerifyVendor(Message
))
1063 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1064 std::cerr
<< "Signature verification succeeded: "
1065 << DestFile
<< std::endl
;
1067 // Download further indexes with verification
1070 // Done, move signature file into position
1072 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
1073 URItoFileName(RealURI
) + ".gpg";
1074 Rename(SigFile
,VerifiedSigFile
);
1075 chmod(VerifiedSigFile
.c_str(),0644);
1078 void pkgAcqMetaIndex::QueueIndexes(bool verify
) /*{{{*/
1080 for (vector
<struct IndexTarget
*>::const_iterator Target
= IndexTargets
->begin();
1081 Target
!= IndexTargets
->end();
1084 HashString ExpectedIndexHash
;
1087 const indexRecords::checkSum
*Record
= MetaIndexParser
->Lookup((*Target
)->MetaKey
);
1090 Status
= StatAuthError
;
1091 ErrorText
= "Unable to find expected entry "
1092 + (*Target
)->MetaKey
+ " in Meta-index file (malformed Release file?)";
1095 ExpectedIndexHash
= Record
->Hash
;
1096 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1098 std::cerr
<< "Queueing: " << (*Target
)->URI
<< std::endl
;
1099 std::cerr
<< "Expected Hash: " << ExpectedIndexHash
.toStr() << std::endl
;
1101 if (ExpectedIndexHash
.empty())
1103 Status
= StatAuthError
;
1104 ErrorText
= "Unable to find hash sum for "
1105 + (*Target
)->MetaKey
+ " in Meta-index file";
1110 // Queue Packages file (either diff or full packages files, depending
1111 // on the users option)
1112 if(_config
->FindB("Acquire::PDiffs",true) == true)
1113 new pkgAcqDiffIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
1114 (*Target
)->ShortDesc
, ExpectedIndexHash
);
1116 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
1117 (*Target
)->ShortDesc
, ExpectedIndexHash
);
1121 bool pkgAcqMetaIndex::VerifyVendor(string Message
) /*{{{*/
1123 // // Maybe this should be made available from above so we don't have
1124 // // to read and parse it every time?
1125 // pkgVendorList List;
1126 // List.ReadMainList();
1128 // const Vendor* Vndr = NULL;
1129 // for (std::vector<string>::const_iterator I = GPGVOutput.begin(); I != GPGVOutput.end(); I++)
1131 // string::size_type pos = (*I).find("VALIDSIG ");
1132 // if (_config->FindB("Debug::Vendor", false))
1133 // std::cerr << "Looking for VALIDSIG in \"" << (*I) << "\": pos " << pos
1135 // if (pos != std::string::npos)
1137 // string Fingerprint = (*I).substr(pos+sizeof("VALIDSIG"));
1138 // if (_config->FindB("Debug::Vendor", false))
1139 // std::cerr << "Looking for \"" << Fingerprint << "\" in vendor..." <<
1141 // Vndr = List.FindVendor(Fingerprint) != "";
1142 // if (Vndr != NULL);
1146 string::size_type pos
;
1148 // check for missing sigs (that where not fatal because otherwise we had
1151 string msg
= _("There is no public key available for the "
1152 "following key IDs:\n");
1153 pos
= Message
.find("NO_PUBKEY ");
1154 if (pos
!= std::string::npos
)
1156 string::size_type start
= pos
+strlen("NO_PUBKEY ");
1157 string Fingerprint
= Message
.substr(start
, Message
.find("\n")-start
);
1158 missingkeys
+= (Fingerprint
);
1160 if(!missingkeys
.empty())
1161 _error
->Warning("%s", string(msg
+missingkeys
).c_str());
1163 string Transformed
= MetaIndexParser
->GetExpectedDist();
1165 if (Transformed
== "../project/experimental")
1167 Transformed
= "experimental";
1170 pos
= Transformed
.rfind('/');
1171 if (pos
!= string::npos
)
1173 Transformed
= Transformed
.substr(0, pos
);
1176 if (Transformed
== ".")
1181 if (_config
->FindB("Acquire::Check-Valid-Until", true)) {
1182 if (MetaIndexParser
->GetValidUntil() > 0 &&
1183 time(NULL
) > MetaIndexParser
->GetValidUntil()) {
1184 return _error
->Error(_("Release file expired, ignoring %s (valid until %s)"),
1186 TimeRFC1123(MetaIndexParser
->GetValidUntil()).c_str());
1190 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1192 std::cerr
<< "Got Codename: " << MetaIndexParser
->GetDist() << std::endl
;
1193 std::cerr
<< "Expecting Dist: " << MetaIndexParser
->GetExpectedDist() << std::endl
;
1194 std::cerr
<< "Transformed Dist: " << Transformed
<< std::endl
;
1197 if (MetaIndexParser
->CheckDist(Transformed
) == false)
1199 // This might become fatal one day
1200 // Status = StatAuthError;
1201 // ErrorText = "Conflicting distribution; expected "
1202 // + MetaIndexParser->GetExpectedDist() + " but got "
1203 // + MetaIndexParser->GetDist();
1205 if (!Transformed
.empty())
1207 _error
->Warning(_("Conflicting distribution: %s (expected %s but got %s)"),
1208 Desc
.Description
.c_str(),
1209 Transformed
.c_str(),
1210 MetaIndexParser
->GetDist().c_str());
1217 // pkgAcqMetaIndex::Failed - no Release file present or no signature file present /*{{{*/
1218 // ---------------------------------------------------------------------
1220 void pkgAcqMetaIndex::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
1222 if (AuthPass
== true)
1224 // if we fail the authentication but got the file via a IMS-Hit
1225 // this means that the file wasn't downloaded and that it might be
1226 // just stale (server problem, proxy etc). we delete what we have
1227 // queue it again without i-m-s
1228 // alternatively we could just unlink the file and let the user try again
1234 unlink(DestFile
.c_str());
1236 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
1237 DestFile
+= URItoFileName(RealURI
);
1243 // gpgv method failed
1244 _error
->Warning("GPG error: %s: %s",
1245 Desc
.Description
.c_str(),
1246 LookupTag(Message
,"Message").c_str());
1250 // No Release file was present, or verification failed, so fall
1251 // back to queueing Packages files without verification
1252 QueueIndexes(false);
1255 // AcqArchive::AcqArchive - Constructor /*{{{*/
1256 // ---------------------------------------------------------------------
1257 /* This just sets up the initial fetch environment and queues the first
1259 pkgAcqArchive::pkgAcqArchive(pkgAcquire
*Owner
,pkgSourceList
*Sources
,
1260 pkgRecords
*Recs
,pkgCache::VerIterator
const &Version
,
1261 string
&StoreFilename
) :
1262 Item(Owner
), Version(Version
), Sources(Sources
), Recs(Recs
),
1263 StoreFilename(StoreFilename
), Vf(Version
.FileList()),
1266 Retries
= _config
->FindI("Acquire::Retries",0);
1268 if (Version
.Arch() == 0)
1270 _error
->Error(_("I wasn't able to locate a file for the %s package. "
1271 "This might mean you need to manually fix this package. "
1272 "(due to missing arch)"),
1273 Version
.ParentPkg().Name());
1277 /* We need to find a filename to determine the extension. We make the
1278 assumption here that all the available sources for this version share
1279 the same extension.. */
1280 // Skip not source sources, they do not have file fields.
1281 for (; Vf
.end() == false; Vf
++)
1283 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
1288 // Does not really matter here.. we are going to fail out below
1289 if (Vf
.end() != true)
1291 // If this fails to get a file name we will bomb out below.
1292 pkgRecords::Parser
&Parse
= Recs
->Lookup(Vf
);
1293 if (_error
->PendingError() == true)
1296 // Generate the final file name as: package_version_arch.foo
1297 StoreFilename
= QuoteString(Version
.ParentPkg().Name(),"_:") + '_' +
1298 QuoteString(Version
.VerStr(),"_:") + '_' +
1299 QuoteString(Version
.Arch(),"_:.") +
1300 "." + flExtension(Parse
.FileName());
1303 // check if we have one trusted source for the package. if so, switch
1304 // to "TrustedOnly" mode
1305 for (pkgCache::VerFileIterator i
= Version
.FileList(); i
.end() == false; i
++)
1307 pkgIndexFile
*Index
;
1308 if (Sources
->FindIndex(i
.File(),Index
) == false)
1310 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1312 std::cerr
<< "Checking index: " << Index
->Describe()
1313 << "(Trusted=" << Index
->IsTrusted() << ")\n";
1315 if (Index
->IsTrusted()) {
1321 // "allow-unauthenticated" restores apts old fetching behaviour
1322 // that means that e.g. unauthenticated file:// uris are higher
1323 // priority than authenticated http:// uris
1324 if (_config
->FindB("APT::Get::AllowUnauthenticated",false) == true)
1328 if (QueueNext() == false && _error
->PendingError() == false)
1329 _error
->Error(_("I wasn't able to locate file for the %s package. "
1330 "This might mean you need to manually fix this package."),
1331 Version
.ParentPkg().Name());
1334 // AcqArchive::QueueNext - Queue the next file source /*{{{*/
1335 // ---------------------------------------------------------------------
1336 /* This queues the next available file version for download. It checks if
1337 the archive is already available in the cache and stashs the MD5 for
1339 bool pkgAcqArchive::QueueNext()
1341 string
const ForceHash
= _config
->Find("Acquire::ForceHash");
1342 for (; Vf
.end() == false; Vf
++)
1344 // Ignore not source sources
1345 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
1348 // Try to cross match against the source list
1349 pkgIndexFile
*Index
;
1350 if (Sources
->FindIndex(Vf
.File(),Index
) == false)
1353 // only try to get a trusted package from another source if that source
1355 if(Trusted
&& !Index
->IsTrusted())
1358 // Grab the text package record
1359 pkgRecords::Parser
&Parse
= Recs
->Lookup(Vf
);
1360 if (_error
->PendingError() == true)
1363 string PkgFile
= Parse
.FileName();
1364 if (ForceHash
.empty() == false)
1366 if(stringcasecmp(ForceHash
, "sha256") == 0)
1367 ExpectedHash
= HashString("SHA256", Parse
.SHA256Hash());
1368 else if (stringcasecmp(ForceHash
, "sha1") == 0)
1369 ExpectedHash
= HashString("SHA1", Parse
.SHA1Hash());
1371 ExpectedHash
= HashString("MD5Sum", Parse
.MD5Hash());
1376 if ((Hash
= Parse
.SHA256Hash()).empty() == false)
1377 ExpectedHash
= HashString("SHA256", Hash
);
1378 else if ((Hash
= Parse
.SHA1Hash()).empty() == false)
1379 ExpectedHash
= HashString("SHA1", Hash
);
1381 ExpectedHash
= HashString("MD5Sum", Parse
.MD5Hash());
1383 if (PkgFile
.empty() == true)
1384 return _error
->Error(_("The package index files are corrupted. No Filename: "
1385 "field for package %s."),
1386 Version
.ParentPkg().Name());
1388 Desc
.URI
= Index
->ArchiveURI(PkgFile
);
1389 Desc
.Description
= Index
->ArchiveInfo(Version
);
1391 Desc
.ShortDesc
= Version
.ParentPkg().Name();
1393 // See if we already have the file. (Legacy filenames)
1394 FileSize
= Version
->Size
;
1395 string FinalFile
= _config
->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile
);
1397 if (stat(FinalFile
.c_str(),&Buf
) == 0)
1399 // Make sure the size matches
1400 if ((unsigned)Buf
.st_size
== Version
->Size
)
1405 StoreFilename
= DestFile
= FinalFile
;
1409 /* Hmm, we have a file and its size does not match, this means it is
1410 an old style mismatched arch */
1411 unlink(FinalFile
.c_str());
1414 // Check it again using the new style output filenames
1415 FinalFile
= _config
->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename
);
1416 if (stat(FinalFile
.c_str(),&Buf
) == 0)
1418 // Make sure the size matches
1419 if ((unsigned)Buf
.st_size
== Version
->Size
)
1424 StoreFilename
= DestFile
= FinalFile
;
1428 /* Hmm, we have a file and its size does not match, this shouldnt
1430 unlink(FinalFile
.c_str());
1433 DestFile
= _config
->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(StoreFilename
);
1435 // Check the destination file
1436 if (stat(DestFile
.c_str(),&Buf
) == 0)
1438 // Hmm, the partial file is too big, erase it
1439 if ((unsigned)Buf
.st_size
> Version
->Size
)
1440 unlink(DestFile
.c_str());
1442 PartialSize
= Buf
.st_size
;
1447 Desc
.URI
= Index
->ArchiveURI(PkgFile
);
1448 Desc
.Description
= Index
->ArchiveInfo(Version
);
1450 Desc
.ShortDesc
= Version
.ParentPkg().Name();
1459 // AcqArchive::Done - Finished fetching /*{{{*/
1460 // ---------------------------------------------------------------------
1462 void pkgAcqArchive::Done(string Message
,unsigned long Size
,string CalcHash
,
1463 pkgAcquire::MethodConfig
*Cfg
)
1465 Item::Done(Message
,Size
,CalcHash
,Cfg
);
1468 if (Size
!= Version
->Size
)
1471 ErrorText
= _("Size mismatch");
1476 if(ExpectedHash
.toStr() != CalcHash
)
1479 ErrorText
= _("Hash Sum mismatch");
1480 if(FileExists(DestFile
))
1481 Rename(DestFile
,DestFile
+ ".FAILED");
1485 // Grab the output filename
1486 string FileName
= LookupTag(Message
,"Filename");
1487 if (FileName
.empty() == true)
1490 ErrorText
= "Method gave a blank filename";
1496 // Reference filename
1497 if (FileName
!= DestFile
)
1499 StoreFilename
= DestFile
= FileName
;
1504 // Done, move it into position
1505 string FinalFile
= _config
->FindDir("Dir::Cache::Archives");
1506 FinalFile
+= flNotDir(StoreFilename
);
1507 Rename(DestFile
,FinalFile
);
1509 StoreFilename
= DestFile
= FinalFile
;
1513 // AcqArchive::Failed - Failure handler /*{{{*/
1514 // ---------------------------------------------------------------------
1515 /* Here we try other sources */
1516 void pkgAcqArchive::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
1518 ErrorText
= LookupTag(Message
,"Message");
1520 /* We don't really want to retry on failed media swaps, this prevents
1521 that. An interesting observation is that permanent failures are not
1523 if (Cnf
->Removable
== true &&
1524 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
1526 // Vf = Version.FileList();
1527 while (Vf
.end() == false) Vf
++;
1528 StoreFilename
= string();
1529 Item::Failed(Message
,Cnf
);
1533 if (QueueNext() == false)
1535 // This is the retry counter
1537 Cnf
->LocalOnly
== false &&
1538 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
1541 Vf
= Version
.FileList();
1542 if (QueueNext() == true)
1546 StoreFilename
= string();
1547 Item::Failed(Message
,Cnf
);
1551 // AcqArchive::IsTrusted - Determine whether this archive comes from a trusted source /*{{{*/
1552 // ---------------------------------------------------------------------
1553 bool pkgAcqArchive::IsTrusted()
1558 // AcqArchive::Finished - Fetching has finished, tidy up /*{{{*/
1559 // ---------------------------------------------------------------------
1561 void pkgAcqArchive::Finished()
1563 if (Status
== pkgAcquire::Item::StatDone
&&
1566 StoreFilename
= string();
1569 // AcqFile::pkgAcqFile - Constructor /*{{{*/
1570 // ---------------------------------------------------------------------
1571 /* The file is added to the queue */
1572 pkgAcqFile::pkgAcqFile(pkgAcquire
*Owner
,string URI
,string Hash
,
1573 unsigned long Size
,string Dsc
,string ShortDesc
,
1574 const string
&DestDir
, const string
&DestFilename
,
1576 Item(Owner
), ExpectedHash(Hash
), IsIndexFile(IsIndexFile
)
1578 Retries
= _config
->FindI("Acquire::Retries",0);
1580 if(!DestFilename
.empty())
1581 DestFile
= DestFilename
;
1582 else if(!DestDir
.empty())
1583 DestFile
= DestDir
+ "/" + flNotDir(URI
);
1585 DestFile
= flNotDir(URI
);
1589 Desc
.Description
= Dsc
;
1592 // Set the short description to the archive component
1593 Desc
.ShortDesc
= ShortDesc
;
1595 // Get the transfer sizes
1598 if (stat(DestFile
.c_str(),&Buf
) == 0)
1600 // Hmm, the partial file is too big, erase it
1601 if ((unsigned)Buf
.st_size
> Size
)
1602 unlink(DestFile
.c_str());
1604 PartialSize
= Buf
.st_size
;
1610 // AcqFile::Done - Item downloaded OK /*{{{*/
1611 // ---------------------------------------------------------------------
1613 void pkgAcqFile::Done(string Message
,unsigned long Size
,string CalcHash
,
1614 pkgAcquire::MethodConfig
*Cnf
)
1616 Item::Done(Message
,Size
,CalcHash
,Cnf
);
1619 if(!ExpectedHash
.empty() && ExpectedHash
.toStr() != CalcHash
)
1622 ErrorText
= "Hash Sum mismatch";
1623 Rename(DestFile
,DestFile
+ ".FAILED");
1627 string FileName
= LookupTag(Message
,"Filename");
1628 if (FileName
.empty() == true)
1631 ErrorText
= "Method gave a blank filename";
1637 // The files timestamp matches
1638 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
1641 // We have to copy it into place
1642 if (FileName
!= DestFile
)
1645 if (_config
->FindB("Acquire::Source-Symlinks",true) == false ||
1646 Cnf
->Removable
== true)
1648 Desc
.URI
= "copy:" + FileName
;
1653 // Erase the file if it is a symlink so we can overwrite it
1655 if (lstat(DestFile
.c_str(),&St
) == 0)
1657 if (S_ISLNK(St
.st_mode
) != 0)
1658 unlink(DestFile
.c_str());
1662 if (symlink(FileName
.c_str(),DestFile
.c_str()) != 0)
1664 ErrorText
= "Link to " + DestFile
+ " failure ";
1671 // AcqFile::Failed - Failure handler /*{{{*/
1672 // ---------------------------------------------------------------------
1673 /* Here we try other sources */
1674 void pkgAcqFile::Failed(string Message
,pkgAcquire::MethodConfig
*Cnf
)
1676 ErrorText
= LookupTag(Message
,"Message");
1678 // This is the retry counter
1680 Cnf
->LocalOnly
== false &&
1681 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
1688 Item::Failed(Message
,Cnf
);
1691 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
1692 // ---------------------------------------------------------------------
1693 /* The only header we use is the last-modified header. */
1694 string
pkgAcqFile::Custom600Headers()
1697 return "\nIndex-File: true";