7#include <QCoreApplication>
8#include <QCommandLineParser>
12#include <KLocalizedString>
19#include <QDBusConnection>
20#include <QDBusConnectionInterface>
24#include "transaction.h"
25#include "databasesize.h"
29#include "indexerconfig.h"
31#include "fileindexerconfig.h"
32#include "monitorcommand.h"
33#include "schedulerinterface.h"
34#include "maininterface.h"
35#include "indexerstate.h"
36#include "configcommand.h"
37#include "statuscommand.h"
52 aboutData.addAuthor(
i18n(
"Vishesh Handa"),
QString(), QStringLiteral(
"vhanda@kde.org"));
57 parser.addPositionalArgument(QStringLiteral(
"command"),
i18n(
"The command to execute"));
59 parser.addPositionalArgument(QStringLiteral(
"status"),
i18n(
"Print the status of the indexer"));
60 parser.addPositionalArgument(QStringLiteral(
"enable"),
i18n(
"Enable the file indexer"));
61 parser.addPositionalArgument(QStringLiteral(
"disable"),
i18n(
"Disable the file indexer"));
62 parser.addPositionalArgument(QStringLiteral(
"purge"),
i18n(
"Remove the index database"));
63 parser.addPositionalArgument(QStringLiteral(
"suspend"),
i18n(
"Suspend the file indexer"));
64 parser.addPositionalArgument(QStringLiteral(
"resume"),
i18n(
"Resume the file indexer"));
65 parser.addPositionalArgument(QStringLiteral(
"check"),
i18n(
"Check for any unindexed files and index them"));
66 parser.addPositionalArgument(QStringLiteral(
"index"),
i18n(
"Index the specified files"));
67 parser.addPositionalArgument(QStringLiteral(
"clear"),
i18n(
"Forget the specified files"));
68 parser.addPositionalArgument(QStringLiteral(
"config"),
i18n(
"Modify the Baloo configuration"));
69 parser.addPositionalArgument(QStringLiteral(
"monitor"),
i18n(
"Monitor the file indexer"));
70 parser.addPositionalArgument(QStringLiteral(
"indexSize"),
i18n(
"Display the disk space used by index"));
71 parser.addPositionalArgument(QStringLiteral(
"failed"),
i18n(
"Display files which could not be indexed"));
74 "Output format <%1|%2|%3>.\nThe default format is \"%1\".\nOnly applies to \"%4\"",
75 QStringLiteral(
"multiline"),
76 QStringLiteral(
"json"),
77 QStringLiteral(
"simple"),
78 QStringLiteral(
"balooctl status <file>"));
79 parser.addOption({{QStringLiteral(
"f"), QStringLiteral(
"format")},
94 org::kde::baloo::main
mainInterface(QStringLiteral(
"org.kde.baloo"),
99 QStringLiteral(
"/scheduler"),
103 ConfigCommand command;
104 return command.exec(
parser);
113 bool isEnabled =
false;
122 cfg.setFileIndexingEnabled(isEnabled);
127 out <<
"File Indexer already running\n";
129 out <<
"Enabling and starting the File Indexer\n";
133 out <<
"Disabling and stopping the File Indexer\n";
146 out <<
"Stopping the File Indexer ...";
147 for (
int i = 5 * 60;
i; --
i) {
158 out <<
" - failed to stop!\n";
163 const QString path = fileIndexDbPath() + QStringLiteral(
"/index");
165 out <<
"Deleted the index database\n";
169 out <<
"Restarting the File Indexer\n";
177 out <<
"File Indexer suspended\n";
183 out <<
"File Indexer resumed\n";
189 out <<
"Started search for unindexed files\n";
194 if (
parser.positionalArguments().
size() < 2) {
195 out <<
"Please enter a filename to index\n";
199 Database *db = globalDatabaseInstance();
200 if (!db->open(Database::ReadWriteDatabase)) {
201 out <<
"Baloo Index could not be opened\n";
205 Transaction tr(db, Transaction::ReadWrite);
207 for (
int i = 1;
i <
parser.positionalArguments().size(); ++
i) {
211 out <<
"Could not stat file: " << url <<
'\n';
214 if (tr.inPhaseOne(
id)) {
215 out <<
"Skipping: " << url <<
" Reason: Already scheduled for indexing\n";
218 if (!tr.documentData(
id).isEmpty()) {
219 out <<
"Skipping: " << url <<
" Reason: Already indexed\n";
223 out <<
"Indexing " << url <<
'\n';
227 out <<
"File(s) indexed\n";
233 if (
parser.positionalArguments().
size() < 2) {
234 out <<
"Please enter a filename to index\n";
238 Database *db = globalDatabaseInstance();
239 if (!db->open(Database::ReadWriteDatabase)) {
240 out <<
"Baloo Index could not be opened\n";
244 Transaction tr(db, Transaction::ReadWrite);
246 for (
int i = 1;
i <
parser.positionalArguments().size(); ++
i) {
252 out <<
"File not found on filesystem or in DB: " << url <<
'\n';
255 out <<
"File has been deleted, clearing from DB: " << url <<
'\n';
258 out <<
"Clearing " << url <<
'\n';
261 tr.removeDocument(
id);
264 out <<
"File(s) cleared\n";
270 Database *db = globalDatabaseInstance();
271 if (!db->open(Database::ReadOnlyDatabase)) {
272 out <<
"Baloo Index could not be opened\n";
276 Transaction tr(db, Transaction::ReadOnly);
278 const quint64 limit = 128;
281 out <<
"All Files were indexed successfully\n";
285 out <<
"The following files could not be indexed:\n";
286 for (
auto id : failedIds) {
287 out << tr.documentUrl(
id) <<
'\n';
289 if (failedIds.
size() == limit) {
290 out <<
"... list truncated\n";
296 Database *db = globalDatabaseInstance();
297 if (!db->open(Database::ReadOnlyDatabase)) {
298 out <<
"Baloo Index could not be opened\n";
304 Transaction tr(db, Transaction::ReadOnly);
311 out.setFieldWidth(20);
313 out.setFieldWidth(0);
315 out.setFieldWidth(15);
316 out << format.formatByteSize(size, 2);
317 out.setFieldWidth(10);
319 out.setFieldWidth(0);
323 out <<
"File Size: " << format.formatByteSize(size.actualSize, 2) <<
"\n";
325 prFunc(QStringLiteral(
"PostingDB"), size.postingDb);
326 prFunc(QStringLiteral(
"PositionDB"), size.positionDb);
327 prFunc(QStringLiteral(
"DocTerms"), size.docTerms);
328 prFunc(QStringLiteral(
"DocFilenameTerms"), size.docFilenameTerms);
329 prFunc(QStringLiteral(
"DocXattrTerms"), size.docXattrTerms);
330 prFunc(QStringLiteral(
"IdTree"), size.idTree);
331 prFunc(QStringLiteral(
"IdFileName"), size.idFilename);
332 prFunc(QStringLiteral(
"DocTime"), size.docTime);
333 prFunc(QStringLiteral(
"DocData"), size.docData);
334 prFunc(QStringLiteral(
"ContentIndexingDB"), size.contentIndexingIds);
335 prFunc(QStringLiteral(
"FailedIdsDB"), size.failedIds);
336 prFunc(QStringLiteral(
"MTimeDB"), size.mtimeDb);
static void setApplicationData(const KAboutData &aboutData)
Q_SCRIPTABLE Q_NOREPLY void start()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Implements storage for docIds without any associated data Instantiated for:
QString path(const QString &relativePath)
QString name(StandardShortcut id)
void processEvents(QEventLoop::ProcessEventsFlags flags)
QDBusConnection sessionBus()
QByteArray encodeName(const QString &fileName)
QString absoluteFilePath() const const
const_reference at(qsizetype i) const const
bool isEmpty() const const
qsizetype size() const const
bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
QString number(double n, char format, int precision)
QTextStream & flush(QTextStream &stream)
void msleep(unsigned long msecs)