diff options
-rw-r--r-- | apt-pkg/acquire-item.cc | 2 | ||||
-rw-r--r-- | apt-pkg/contrib/hashes.cc | 21 |
2 files changed, 15 insertions, 8 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 01ce0e650..1090912f5 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1175,7 +1175,7 @@ void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,HashStri else if (State == StateApplyDiff) { // see if we really got the expected file - if(ExpectedHashes.usable() && !ExpectedHashes.VerifyFile(DestFile)) + if(ExpectedHashes.usable() && ExpectedHashes != Hashes) { RenameOnError(HashSumMismatch); return; diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index 953465091..0fa443b4a 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -204,15 +204,22 @@ bool HashStringList::push_back(const HashString &hashString) /*{{{*/ /*}}}*/ bool HashStringList::VerifyFile(std::string filename) const /*{{{*/ { - if (list.empty() == true) - return false; - HashString const * const hs = find(NULL); - if (hs == NULL || hs->VerifyFile(filename) == false) + if (usable() == false) return false; + + Hashes hashes(*this); + FileFd file(filename, FileFd::ReadOnly); HashString const * const hsf = find("Checksum-FileSize"); - if (hsf != NULL && hsf->VerifyFile(filename) == false) - return false; - return true; + if (hsf != NULL) + { + std::string fileSize; + strprintf(fileSize, "%llu", file.FileSize()); + if (hsf->HashValue() != fileSize) + return false; + } + hashes.AddFD(file); + HashStringList const hsl = hashes.GetHashStringList(); + return hsl == *this; } /*}}}*/ bool HashStringList::operator==(HashStringList const &other) const /*{{{*/ |