From 200572398920e418e548080ac1b4617a11f48270 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 21 Jun 2015 10:25:53 -0700 Subject: Make helper function deal with files that don't exist Ignoring when you can't open a file and happily hashing its contents seems wrong. Signed-off-by: Dirk Hohndel --- qthelper.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'qthelper.cpp') diff --git a/qthelper.cpp b/qthelper.cpp index 274e04822..aab06d8b1 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -819,10 +819,13 @@ QByteArray hashFile(const QString filename) { QCryptographicHash hash(QCryptographicHash::Sha1); QFile imagefile(filename); - imagefile.open(QIODevice::ReadOnly); - hash.addData(&imagefile); - add_hash(filename, hash.result()); - return hash.result(); + if (imagefile.open(QIODevice::ReadOnly)) { + hash.addData(&imagefile); + add_hash(filename, hash.result()); + return hash.result(); + } else { + return QByteArray(); + } } void learnHash(struct picture *picture, QByteArray hash) -- cgit v1.2.3-70-g09d2