X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/9498d18252a848b06f281434c173cece967ebbf6..bd668fbb93a536135f8a001f98a7485158a5075f:/apt-pkg/acquire-item.cc diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index a7132ce1d..7cae6c8b7 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -345,7 +345,7 @@ void pkgAcqDiffIndex::Done(string Message,unsigned long Size,string Md5Hash, */ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner, string URI,string URIDesc,string ShortDesc, - HashString ExpectedMD5, + HashString ExpectedHash, vector diffs) : Item(Owner), RealURI(URI), ExpectedHash(ExpectedHash), available_patches(diffs) @@ -641,7 +641,7 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash, std::cerr << " Expected Hash: " << ExpectedHash.toStr() << std::endl; } - if (!ExpectedHash.empty() && !ExpectedHash.VerifyFile(DestFile)) + if (!ExpectedHash.empty() && ExpectedHash.toStr() != Hash) { Status = StatAuthError; ErrorText = _("Hash Sum mismatch"); @@ -675,7 +675,6 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash, // The files timestamp matches if (StringToBool(LookupTag(Message,"Alt-IMS-Hit"),false) == true) return; - Decompression = true; Local = true; DestFile += ".decomp"; @@ -702,7 +701,7 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string Hash, Local = true; string compExt = Desc.URI.substr(Desc.URI.size()-3); - char *decompProg; + const char *decompProg; if(compExt == "bz2") decompProg = "bzip2"; else if(compExt == ".gz") @@ -771,16 +770,19 @@ pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner, Desc.Owner = this; Desc.ShortDesc = ShortDesc; Desc.URI = URI; - string Final = _config->FindDir("Dir::State::lists"); Final += URItoFileName(RealURI); struct stat Buf; if (stat(Final.c_str(),&Buf) == 0) { - // File was already in place. It needs to be re-verified - // because Release might have changed, so Move it into partial - Rename(Final,DestFile); + // File was already in place. It needs to be re-downloaded/verified + // because Release might have changed, we do give it a differnt + // name than DestFile because otherwise the http method will + // send If-Range requests and there are too many broken servers + // out there that do not understand them + LastGoodSig = DestFile+".reverify"; + Rename(Final,LastGoodSig); } QueueURI(Desc); @@ -792,7 +794,7 @@ pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner, string pkgAcqMetaSig::Custom600Headers() { struct stat Buf; - if (stat(DestFile.c_str(),&Buf) != 0) + if (stat(LastGoodSig.c_str(),&Buf) != 0) return "\nIndex-File: true"; return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime); @@ -822,6 +824,12 @@ void pkgAcqMetaSig::Done(string Message,unsigned long Size,string MD5, Complete = true; + // put the last known good file back on i-m-s hit (it will + // be re-verified again) + // Else do nothing, we have the new file in DestFile then + if(StringToBool(LookupTag(Message,"IMS-Hit"),false) == true) + Rename(LastGoodSig, DestFile); + // queue a pkgAcqMetaIndex to be verified against the sig we just retrieved new pkgAcqMetaIndex(Owner, MetaIndexURI, MetaIndexURIDesc, MetaIndexShortDesc, DestFile, IndexTargets, MetaIndexParser); @@ -838,7 +846,7 @@ void pkgAcqMetaSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf) Item::Failed(Message,Cnf); // move the sigfile back on transient network failures if(FileExists(DestFile)) - Rename(DestFile,Final); + Rename(LastGoodSig,Final); // set the status back to , Item::Failed likes to reset it Status = pkgAcquire::Item::StatTransientNetworkError; @@ -966,18 +974,18 @@ void pkgAcqMetaIndex::RetrievalDone(string Message) // see if the download was a IMSHit IMSHit = StringToBool(LookupTag(Message,"IMS-Hit"),false); - Complete = true; string FinalFile = _config->FindDir("Dir::State::lists"); FinalFile += URItoFileName(RealURI); - // The files timestamp matches - if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == false) - { - // Move it into position + // If we get a IMS hit we can remove the empty file in partial + // othersie we move the file in place + if (IMSHit) + unlink(DestFile.c_str()); + else Rename(DestFile,FinalFile); - } + chmod(FinalFile.c_str(),0644); DestFile = FinalFile; } @@ -1296,11 +1304,11 @@ bool pkgAcqArchive::QueueNext() string PkgFile = Parse.FileName(); if(Parse.SHA256Hash() != "") - hash = HashString("SHA256", Parse.SHA256Hash()); + ExpectedHash = HashString("SHA256", Parse.SHA256Hash()); else if (Parse.SHA1Hash() != "") - hash = HashString("SHA1", Parse.SHA1Hash()); + ExpectedHash = HashString("SHA1", Parse.SHA1Hash()); else - hash = HashString("MD5Sum", Parse.MD5Hash()); + ExpectedHash = HashString("MD5Sum", Parse.MD5Hash()); if (PkgFile.empty() == true) return _error->Error(_("The package index files are corrupted. No Filename: " "field for package %s."), @@ -1394,7 +1402,7 @@ void pkgAcqArchive::Done(string Message,unsigned long Size,string CalcHash, } // Check the hash - if(!hash.VerifyFile(DestFile)) + if(ExpectedHash.toStr() != CalcHash) { Status = StatError; ErrorText = _("Hash Sum mismatch"); @@ -1492,10 +1500,10 @@ void pkgAcqArchive::Finished() // AcqFile::pkgAcqFile - Constructor /*{{{*/ // --------------------------------------------------------------------- /* The file is added to the queue */ -pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI,string MD5, +pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI,string Hash, unsigned long Size,string Dsc,string ShortDesc, const string &DestDir, const string &DestFilename) : - Item(Owner), hash(MD5) + Item(Owner), ExpectedHash(Hash) { Retries = _config->FindI("Acquire::Retries",0); @@ -1537,8 +1545,8 @@ void pkgAcqFile::Done(string Message,unsigned long Size,string CalcHash, { Item::Done(Message,Size,CalcHash,Cnf); - // Check the md5 - if(!hash.VerifyFile(DestFile)) + // Check the hash + if(!ExpectedHash.empty() && ExpectedHash.toStr() != CalcHash) { Status = StatError; ErrorText = "Hash Sum mismatch";