summaryrefslogtreecommitdiff
path: root/apt-pkg/acquire-item.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-05-13 16:09:12 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-05-13 16:09:12 +0200
commit8eafc759544298211cd0bfaa3919afc0fadd47d1 (patch)
treee1a6e74d6d1abdc177316b9422aae3723f727732 /apt-pkg/acquire-item.cc
parent495b7a615a2d8f485beadf88c6ed298f5bbe50c2 (diff)
detect Releasefile IMS hits even if the server doesn't
Not all servers we are talking to support If-Modified-Since and some are not even sending Last-Modified for us, so in an effort to detect such hits we run a hashsum check on the 'old' compared to the 'new' file, we got the hashes for the 'new' already for "free" from the methods anyway and hence just need to calculated the old ones. This allows us to detect hits even with unsupported servers, which in turn means we benefit from all the new hit behavior also here.
Diffstat (limited to 'apt-pkg/acquire-item.cc')
-rw-r--r--apt-pkg/acquire-item.cc31
1 files changed, 23 insertions, 8 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 1090912f5..78dace12c 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -253,7 +253,10 @@ bool pkgAcquire::Item::Rename(string From,string To)
strprintf(S, _("rename failed, %s (%s -> %s)."), strerror(errno),
From.c_str(),To.c_str());
Status = StatError;
- ErrorText += S;
+ if (ErrorText.empty())
+ ErrorText = S;
+ else
+ ErrorText = ErrorText + ": " + S;
return false;
}
/*}}}*/
@@ -1794,7 +1797,7 @@ void pkgAcqMetaSig::Done(string Message,unsigned long long Size,
if(AuthPass == false)
{
- if(CheckDownloadDone(Message) == true)
+ if(CheckDownloadDone(Message, Hashes) == true)
{
// destfile will be modified to point to MetaIndexFile for the
// gpgv method, so we need to save it here
@@ -1837,7 +1840,8 @@ void pkgAcqMetaSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf)/*{{{*/
Status = StatDone;
} else {
_error->Error("%s", downgrade_msg.c_str());
- Rename(MetaIndexFile, MetaIndexFile+".FAILED");
+ if (TransactionManager->IMSHit == false)
+ Rename(MetaIndexFile, MetaIndexFile+".FAILED");
Item::Failed("Message: " + downgrade_msg, Cnf);
TransactionManager->AbortTransaction();
return;
@@ -1922,12 +1926,12 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size, /*{{{*/
{
Item::Done(Message,Size,Hashes,Cfg);
- if(CheckDownloadDone(Message))
+ if(CheckDownloadDone(Message, Hashes))
{
// we have a Release file, now download the Signature, all further
// verify/queue for additional downloads will be done in the
// pkgAcqMetaSig::Done() code
- std::string MetaIndexFile = DestFile;
+ std::string const MetaIndexFile = DestFile;
new pkgAcqMetaSig(Owner, TransactionManager,
MetaIndexSigURI, MetaIndexSigURIDesc,
MetaIndexSigShortDesc, MetaIndexFile, IndexTargets,
@@ -2008,7 +2012,7 @@ void pkgAcqMetaBase::QueueForSignatureVerify(const std::string &MetaIndexFile,
}
/*}}}*/
// pkgAcqMetaBase::CheckDownloadDone /*{{{*/
-bool pkgAcqMetaBase::CheckDownloadDone(const std::string &Message)
+bool pkgAcqMetaBase::CheckDownloadDone(const std::string &Message, HashStringList const &Hashes)
{
// We have just finished downloading a Release file (it is not
// verified yet)
@@ -2031,7 +2035,18 @@ bool pkgAcqMetaBase::CheckDownloadDone(const std::string &Message)
// make sure to verify against the right file on I-M-S hit
IMSHit = StringToBool(LookupTag(Message,"IMS-Hit"),false);
- if(IMSHit)
+ if (IMSHit == false)
+ {
+ // detect IMS-Hits servers haven't detected by Hash comparison
+ std::string FinalFile = GetFinalFilename();
+ if (RealFileExists(FinalFile) && Hashes.VerifyFile(FinalFile) == true)
+ {
+ IMSHit = true;
+ unlink(DestFile.c_str());
+ }
+ }
+
+ if(IMSHit == true)
{
// for simplicity, the transaction manager is always InRelease
// even if it doesn't exist.
@@ -2273,7 +2288,7 @@ void pkgAcqMetaClearSig::Done(std::string Message,unsigned long long Size,
if(AuthPass == false)
{
- if(CheckDownloadDone(Message) == true)
+ if(CheckDownloadDone(Message, Hashes) == true)
QueueForSignatureVerify(DestFile, DestFile);
return;
}