From 33990a7379d5ea93fb1b3fa72b47c51e4f7f5ef8 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 12 Aug 2017 19:28:23 +0200 Subject: Fix consistency check Actually, removing stray pictures never worked, because the call to that function was commented out. Also, remove the clear functions stray files and stray ids and lock the mutex in place. They were only called once, so we can do it inside the function. And don't forget to clear the picture Ids. Finally, fix the logic for activating the cleanup button. --- consistencycheck.cpp | 22 ++++++++-------------- consistencycheck.h | 2 -- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/consistencycheck.cpp b/consistencycheck.cpp index 1583093..d5d1aa8 100644 --- a/consistencycheck.cpp +++ b/consistencycheck.cpp @@ -176,7 +176,7 @@ void ConsistencyCheck::checkerFinished(){ mCancelExit->disconnect(); connect(mCancelExit, SIGNAL(clicked()), this, SLOT(accept())); mChecker->setCancel(false); - if(!mChecker->strayFiles().isEmpty() || !mChecker->strayFileIds().isEmpty()){ + if(!mChecker->strayPicIds().isEmpty() || !mChecker->strayFileIds().isEmpty() || mChecker->strayFiles().isEmpty()){ mCleanup->setEnabled(true); } } @@ -202,7 +202,7 @@ void ConsistencyCheck::cleanup(){ QString msg = QString(tr("Really delete %1 pictures from database?")).arg(QString::number(picIds.count())); int retval = QMessageBox::critical(this, tr("Delete from database"), msg, QMessageBox::Yes | QMessageBox::No); if(retval == QMessageBox::Yes){ - //mChecker->deleteIds(fileIds); + mChecker->deletePicIds(picIds); } } } @@ -258,11 +258,6 @@ const QStringList ConsistencyChecker::strayFiles(){ return mStrayFiles; } -void ConsistencyChecker::clearStrayFiles(){ - QMutexLocker locker(&mStrayFilesMutex); - mStrayFiles.clear(); -} - const QList ConsistencyChecker::strayFileIds(){ QMutexLocker locker(&mStrayFileIdMutex); return mStrayFileIds; @@ -273,11 +268,6 @@ const QList ConsistencyChecker::strayPicIds(){ return mStrayPicIds; } -void ConsistencyChecker::clearStrayIds(){ - QMutexLocker locker(&mStrayFileIdMutex); - mStrayFileIds.clear(); -} - void ConsistencyChecker::setCancel(bool cancel){ QMutexLocker locker(&mCancelMutex); mCanceled = cancel; @@ -302,8 +292,6 @@ void ConsistencyChecker::deletePicIds(const QList &ids){ } void ConsistencyChecker::run(){ - clearStrayFiles(); - clearStrayIds(); if(mMode == ConsistencyCheck::FsCheck){ fsCheck(); } @@ -387,6 +375,12 @@ void ConsistencyChecker::doDbCheckPics(){ } void ConsistencyChecker::dbCheck(){ + mStrayFileIdMutex.lock(); + mStrayFileIds.clear(); + mStrayFileIdMutex.unlock(); + mStrayPicsIdMutex.lock(); + mStrayPicIds.clear(); + mStrayPicsIdMutex.unlock(); QSqlQuery numFilesQ("SELECT COUNT(*) FROM files", mDb); int numFiles; while(numFilesQ.next()){ diff --git a/consistencycheck.h b/consistencycheck.h index 6f54dcb..7f445eb 100644 --- a/consistencycheck.h +++ b/consistencycheck.h @@ -70,10 +70,8 @@ class ConsistencyChecker : public QThread { void setStatus(int status) { mStatus = status; } void check(); const QStringList strayFiles(); - void clearStrayFiles(); const QList strayFileIds(); const QList strayPicIds(); - void clearStrayIds(); public slots: void setCancel(bool cancel); -- cgit v1.2.3-70-g09d2