summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/hashes.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-05-12 11:18:17 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-05-12 13:29:54 +0200
commit495b7a615a2d8f485beadf88c6ed298f5bbe50c2 (patch)
treeb921790586315139e106f855abcdad18b6ce4480 /apt-pkg/contrib/hashes.cc
parentdcbb364fc69e1108b3fea3adb12a7ba83d9af467 (diff)
implement VerifyFile as all-hashes check
It isn't used much compared to what the methodname suggests, but in the remaining uses it can't hurt to check more than strictly necessary by calculating and verifying with all hashes we can compare with rather than "just" the best known hash.
Diffstat (limited to 'apt-pkg/contrib/hashes.cc')
-rw-r--r--apt-pkg/contrib/hashes.cc21
1 files changed, 14 insertions, 7 deletions
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 /*{{{*/