From e1fd385d598e17c77a8b8175b8674b219b45cd8d Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 24 Oct 2015 12:57:21 +0200 Subject: Make convertArchivefileToPng a transaction Delete the original file if we converted a pic to PNG, but only if the database transaction succeeded. --- helper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'helper.cpp') diff --git a/helper.cpp b/helper.cpp index b913f65..76f637a 100644 --- a/helper.cpp +++ b/helper.cpp @@ -346,6 +346,7 @@ namespace Helper { retval[3] = dest; //Full path retval[6] = newMd5; //md5sum QSqlDatabase db = QSqlDatabase::database("treedb"); + db.transaction(); int id = data.at(4).toInt(); QSqlQuery q(db); q.prepare("UPDATE pics SET tfilename = :fn, cmd5sum = :md5, isize = :size, tformat = :format WHERE ipicsid = :id"); @@ -356,7 +357,12 @@ namespace Helper { q.bindValue(":id", id); if(q.exec()){ + QFile::remove(data.at(3).toString()); + db.commit(); return retval; + }else{ + QFile::remove(dest); + db.rollback(); } } return PicData(); -- cgit v1.2.3-70-g09d2