summaryrefslogtreecommitdiffstats
path: root/qthelper.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-21 10:25:53 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-21 10:47:00 -0700
commit200572398920e418e548080ac1b4617a11f48270 (patch)
treeede94d26036c222246b3c43ec34c5dafc2bf22aa /qthelper.cpp
parentb27538feba70b942a9b5d3eb5eae171e04d52461 (diff)
downloadsubsurface-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.cpp11
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)