diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-06-21 10:25:53 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-06-21 10:47:00 -0700 |
commit | 200572398920e418e548080ac1b4617a11f48270 (patch) | |
tree | ede94d26036c222246b3c43ec34c5dafc2bf22aa /qthelper.cpp | |
parent | b27538feba70b942a9b5d3eb5eae171e04d52461 (diff) | |
download | subsurface-200572398920e418e548080ac1b4617a11f48270.tar.gz |
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 <dirk@hohndel.org>
Diffstat (limited to 'qthelper.cpp')
-rw-r--r-- | qthelper.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
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) |