File indexing completed on 2024-04-14 03:49:46
0001 /* 0002 This file is part of the KDE Baloo Project 0003 SPDX-FileCopyrightText: 2013-2015 Vishesh Handa <vhanda@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include <KCrash> 0009 0010 #include <iostream> 0011 0012 #include "global.h" 0013 #include "database.h" 0014 #include "fileindexerconfig.h" 0015 #include "priority.h" 0016 #include "migrator.h" 0017 #include "mainhub.h" 0018 0019 #include <QDBusConnection> 0020 #include <QCoreApplication> 0021 #include <QFile> 0022 0023 int main(int argc, char** argv) 0024 { 0025 lowerIOPriority(); 0026 lowerSchedulingPriority(); 0027 lowerPriority(); 0028 0029 QCoreApplication app(argc, argv); 0030 0031 Baloo::FileIndexerConfig indexerConfig; 0032 if (!indexerConfig.indexingEnabled()) { 0033 std::cout << "Baloo File Indexing has been disabled" << std::endl; 0034 return 0; 0035 } 0036 0037 if (!QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.baloo"))) { 0038 qWarning() << "Failed to register via dbus. Another instance is running"; 0039 return 1; 0040 } 0041 0042 // Crash Handling 0043 KCrash::setFlags(KCrash::AutoRestart); 0044 0045 const QString path = Baloo::fileIndexDbPath(); 0046 0047 Baloo::Migrator migrator(path, &indexerConfig); 0048 if (migrator.migrationRequired()) { 0049 migrator.migrate(); 0050 } 0051 0052 bool firstRun = !QFile::exists(path + QStringLiteral("/index")); 0053 0054 // HACK: Until we start using lmdb with robust mutex support. We're just going to remove 0055 // the lock manually in the baloo_file process. 0056 QFile::remove(path + QStringLiteral("/index-lock")); 0057 0058 Baloo::Database *db = Baloo::globalDatabaseInstance(); 0059 0060 /** 0061 * try to open, if that fails, try to unlink the index db and retry 0062 */ 0063 if (!db->open(Baloo::Database::CreateDatabase)) { 0064 // delete old stuff, set to initial run! 0065 qWarning() << "Failed to create database, removing corrupted database."; 0066 QFile::remove(path + QStringLiteral("/index")); 0067 QFile::remove(path + QStringLiteral("/index-lock")); 0068 firstRun = true; 0069 0070 // try to create now after cleanup, if still no works => fail 0071 if (!db->open(Baloo::Database::CreateDatabase)) { 0072 qWarning() << "Failed to create database after deleting corrupted one."; 0073 return 1; 0074 } 0075 } 0076 0077 Baloo::MainHub hub(db, &indexerConfig, firstRun); 0078 return app.exec(); 0079 }