Baloo

file/main.cpp
1/*
2 This file is part of the KDE Baloo Project
3 SPDX-FileCopyrightText: 2013-2015 Vishesh Handa <vhanda@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include <KCrash>
9
10#include <iostream>
11
12#include "global.h"
13#include "database.h"
14#include "fileindexerconfig.h"
15#include "priority.h"
16#include "migrator.h"
17#include "mainhub.h"
18
19#include <QDBusConnection>
20#include <QCoreApplication>
21#include <QFile>
22
23int main(int argc, char** argv)
24{
25 lowerIOPriority();
26 lowerSchedulingPriority();
27 lowerPriority();
28
30
32 if (!indexerConfig.indexingEnabled()) {
33 std::cout << "Baloo File Indexing has been disabled" << std::endl;
34 return 0;
35 }
36
37 if (!QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.baloo"))) {
38 qWarning() << "Failed to register via dbus. Another instance is running";
39 return 1;
40 }
41
42 // Crash Handling
44
45 const QString path = Baloo::fileIndexDbPath();
46
47 Baloo::Migrator migrator(path, &indexerConfig);
48 if (migrator.migrationRequired()) {
49 migrator.migrate();
50 }
51
52 bool firstRun = !QFile::exists(path + QStringLiteral("/index"));
53
54 // HACK: Until we start using lmdb with robust mutex support. We're just going to remove
55 // the lock manually in the baloo_file process.
56 QFile::remove(path + QStringLiteral("/index-lock"));
57
58 Baloo::Database *db = Baloo::globalDatabaseInstance();
59
60 /**
61 * try to open, if that fails, try to unlink the index db and retry
62 */
63 if (!db->open(Baloo::Database::CreateDatabase)) {
64 // delete old stuff, set to initial run!
65 qWarning() << "Failed to create database, removing corrupted database.";
66 QFile::remove(path + QStringLiteral("/index"));
67 QFile::remove(path + QStringLiteral("/index-lock"));
68 firstRun = true;
69
70 // try to create now after cleanup, if still no works => fail
71 if (!db->open(Baloo::Database::CreateDatabase)) {
72 qWarning() << "Failed to create database after deleting corrupted one.";
73 return 1;
74 }
75 }
76
77 Baloo::MainHub hub(db, &indexerConfig, firstRun);
78 return app.exec();
79}
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
KCRASH_EXPORT void setFlags(KCrash::CrashFlags flags)
QString path(const QString &relativePath)
QDBusConnection sessionBus()
bool exists() const const
bool remove()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.