Baloo

file/main.cpp
1 /*
2  This file is part of the KDE Baloo Project
3  SPDX-FileCopyrightText: 2013-2015 Vishesh Handa <[email protected]>
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 
23 int main(int argc, char** argv)
24 {
25  lowerIOPriority();
26  lowerSchedulingPriority();
27  lowerPriority();
28 
29  QCoreApplication app(argc, argv);
30 
31  Baloo::FileIndexerConfig indexerConfig;
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 }
bool remove()
KCRASH_EXPORT void setFlags(KCrash::CrashFlags flags)
bool exists() const const
QDBusConnection sessionBus()
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
QString path(const QString &relativePath)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.