diff --git a/src/file/extractor/app.h b/src/file/extractor/app.h --- a/src/file/extractor/app.h +++ b/src/file/extractor/app.h @@ -47,15 +47,16 @@ Q_OBJECT public: - explicit App(QObject* parent = nullptr); + explicit App(Database* db); private Q_SLOTS: void slotNewInput(); void processNextFile(); private: void index(Transaction* tr, const QString& filePath, quint64 id); + Database* m_db; QMimeDatabase m_mimeDb; KFileMetaData::ExtractorCollection m_extractorCollection; diff --git a/src/file/extractor/app.cpp b/src/file/extractor/app.cpp --- a/src/file/extractor/app.cpp +++ b/src/file/extractor/app.cpp @@ -44,8 +44,8 @@ using namespace Baloo; -App::App(QObject* parent) - : QObject(parent) +App::App(Database* db) + : m_db(db) , m_notifyNewData(STDIN_FILENO, QSocketNotifier::Read) , m_input() , m_inputStream(&m_input) @@ -73,15 +73,14 @@ return; } - Database *db = globalDatabaseInstance(); - if (!db->open(Database::ReadWriteDatabase)) { - qCritical() << "Failed to open the database"; - exit(1); + if (m_tr) { + // Parent proccess yielded us a new batch while previous have not yet finished + // This should not happen, but better play safe + m_tr->commit(); + delete m_tr; } - Q_ASSERT(m_tr == nullptr); - - m_tr = new Transaction(db, Transaction::ReadWrite); + m_tr = new Transaction(m_db, Transaction::ReadWrite); // FIXME: The transaction is open for way too long. We should just open it for when we're // committing the data not during the extraction. diff --git a/src/file/extractor/main.cpp b/src/file/extractor/main.cpp --- a/src/file/extractor/main.cpp +++ b/src/file/extractor/main.cpp @@ -21,6 +21,8 @@ */ #include "app.h" +#include "global.h" +#include "baloodebug.h" #include "../priority.h" #include @@ -32,6 +34,8 @@ #include #include +using namespace Baloo; + int main(int argc, char* argv[]) { lowerIOPriority(); @@ -56,6 +60,12 @@ QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); - Baloo::App appObject; + Database *db = globalDatabaseInstance(); + if (!db->open(Database::ReadWriteDatabase)) { + qCCritical(BALOO) << "Failed to open the database"; + return 1; + } + + App appObject(db); return app.exec(); }