8#include "statuscommand.h"
9#include "indexerconfig.h"
13#include "transaction.h"
16#include "fileindexerinterface.h"
17#include "schedulerinterface.h"
18#include "maininterface.h"
19#include "indexerstate.h"
21#include <KLocalizedString>
28 return QStringLiteral(
"status");
31QString StatusCommand::description()
33 return i18n(
"Print the status of the Indexer");
39 enum class FileStatus : uint8_t {
46 enum class IndexStateReason : uint8_t {
49 WaitingForIndexingBoth,
50 WaitingForBasicIndexing,
52 WaitingForContentIndexing,
57 FileStatus m_fileStatus;
58 IndexStateReason m_indexState;
64 using FileStatus = FileIndexStatus::FileStatus;
65 using IndexStateReason = FileIndexStatus::IndexStateReason;
67 bool onlyBasicIndexing = cfg.onlyBasicIndexing();
73 return FileIndexStatus{filePath, FileStatus::NonExisting, IndexStateReason::NoFileOrDirectory, 0};
76 FileStatus fileStatus = fileInfo.
isSymLink() ? FileStatus::SymLink :
77 fileInfo.
isFile() ? FileStatus::RegularFile :
78 fileInfo.
isDir() ? FileStatus::Directory : FileStatus::Other;
80 if (fileStatus == FileStatus::Other || fileStatus == FileStatus::SymLink) {
81 return FileIndexStatus{filePath, fileStatus, IndexStateReason::NoFileOrDirectory, 0};
85 return FileIndexStatus{filePath, fileStatus, IndexStateReason::ExcludedByPath, 0};
88 if (onlyBasicIndexing || fileStatus == FileStatus::Directory) {
89 if (!tr.hasDocument(
id)) {
90 return FileIndexStatus{filePath, fileStatus, IndexStateReason::WaitingForBasicIndexing, 0};
92 return FileIndexStatus{filePath, fileStatus, IndexStateReason::BasicIndexingDone, 0};
97 if (!tr.hasDocument(
id)) {
98 return FileIndexStatus{filePath, fileStatus, IndexStateReason::WaitingForIndexingBoth, 0};
99 }
else if (tr.inPhaseOne(
id)) {
100 return FileIndexStatus{filePath, fileStatus, IndexStateReason::WaitingForContentIndexing, 0};
101 }
else if (tr.hasFailed(
id)) {
102 return FileIndexStatus{filePath, fileStatus, IndexStateReason::FailedToIndex, 0};
104 uint32_t size = tr.documentData(
id).
size();
105 return FileIndexStatus{filePath, fileStatus, IndexStateReason::Done, size};
110 using FileStatus = FileIndexStatus::FileStatus;
111 using IndexStateReason = FileIndexStatus::IndexStateReason;
117 { IndexStateReason::NoFileOrDirectory,
i18n(
"File ignored") },
118 { IndexStateReason::ExcludedByPath,
i18n(
"Basic Indexing: Disabled") },
119 { IndexStateReason::WaitingForIndexingBoth,
i18n(
"Basic Indexing: Scheduled") },
120 { IndexStateReason::WaitingForBasicIndexing,
i18n(
"Basic Indexing: Scheduled") },
121 { IndexStateReason::BasicIndexingDone,
i18n(
"Basic Indexing: Done") },
122 { IndexStateReason::WaitingForContentIndexing,
i18n(
"Basic Indexing: Done") },
123 { IndexStateReason::FailedToIndex,
i18n(
"Basic Indexing: Done") },
124 { IndexStateReason::Done,
i18n(
"Basic Indexing: Done") },
128 { IndexStateReason::NoFileOrDirectory,
QString() },
129 { IndexStateReason::ExcludedByPath,
QString() },
130 { IndexStateReason::WaitingForIndexingBoth,
i18n(
"Content Indexing: Scheduled") },
131 { IndexStateReason::WaitingForBasicIndexing,
QString() },
132 { IndexStateReason::BasicIndexingDone,
QString() },
133 { IndexStateReason::WaitingForContentIndexing,
i18n(
"Content Indexing: Scheduled") },
134 { IndexStateReason::FailedToIndex,
i18n(
"Content Indexing: Failed") },
135 { IndexStateReason::Done,
i18n(
"Content Indexing: Done") },
138 for (
const auto& fileName : args) {
139 const auto file = collectFileStatus(tr, cfg, fileName);
141 if (file.m_fileStatus == FileStatus::NonExisting) {
142 err <<
i18n(
"Ignoring non-existent file %1", file.m_filePath) <<
'\n';
146 if (file.m_fileStatus == FileStatus::SymLink || file.m_fileStatus == FileStatus::Other) {
147 err <<
i18n(
"Ignoring symlink/special file %1", file.m_filePath) <<
'\n';
151 out <<
i18n(
"File: %1", file.m_filePath) <<
'\n';
152 out << basicIndexStateValue[file.m_indexState] <<
'\n';
153 const QString contentState = contentIndexStateValue[file.m_indexState];
155 out << contentState <<
'\n';
161 using FileStatus = FileIndexStatus::FileStatus;
162 using IndexStateReason = FileIndexStatus::IndexStateReason;
168 { IndexStateReason::NoFileOrDirectory, QStringLiteral(
"No regular file or directory") },
169 { IndexStateReason::ExcludedByPath, QStringLiteral(
"Indexing disabled") },
170 { IndexStateReason::WaitingForIndexingBoth, QStringLiteral(
"Basic and Content indexing scheduled") },
171 { IndexStateReason::WaitingForBasicIndexing, QStringLiteral(
"Basic indexing scheduled") },
172 { IndexStateReason::BasicIndexingDone, QStringLiteral(
"Basic indexing done") },
173 { IndexStateReason::WaitingForContentIndexing, QStringLiteral(
"Content indexing scheduled") },
174 { IndexStateReason::FailedToIndex, QStringLiteral(
"Content indexing failed") },
175 { IndexStateReason::Done, QStringLiteral(
"Content indexing done") },
178 for (
const auto& fileName : args) {
179 const auto file = collectFileStatus(tr, cfg, fileName);
181 if (file.m_fileStatus == FileStatus::NonExisting) {
182 err <<
i18n(
"Ignoring non-existent file %1", file.m_filePath) <<
'\n';
186 if (file.m_fileStatus == FileStatus::SymLink || file.m_fileStatus == FileStatus::Other) {
187 err <<
i18n(
"Ignoring symlink/special file %1", file.m_filePath) <<
'\n';
191 out << simpleIndexStateValue[file.m_indexState];
192 out <<
": " << file.m_filePath <<
'\n';
198 using FileStatus = FileIndexStatus::FileStatus;
199 using IndexStateReason = FileIndexStatus::IndexStateReason;
205 { IndexStateReason::NoFileOrDirectory, QStringLiteral(
"nofile") },
206 { IndexStateReason::ExcludedByPath, QStringLiteral(
"disabled") },
207 { IndexStateReason::WaitingForIndexingBoth, QStringLiteral(
"scheduled") },
208 { IndexStateReason::WaitingForBasicIndexing, QStringLiteral(
"scheduled") },
209 { IndexStateReason::BasicIndexingDone, QStringLiteral(
"done") },
210 { IndexStateReason::WaitingForContentIndexing, QStringLiteral(
"scheduled") },
211 { IndexStateReason::FailedToIndex, QStringLiteral(
"failed") },
212 { IndexStateReason::Done, QStringLiteral(
"done") },
216 { IndexStateReason::NoFileOrDirectory, QStringLiteral(
"nofile") },
217 { IndexStateReason::ExcludedByPath, QStringLiteral(
"none") },
218 { IndexStateReason::WaitingForIndexingBoth, QStringLiteral(
"content") },
219 { IndexStateReason::WaitingForBasicIndexing, QStringLiteral(
"basic") },
220 { IndexStateReason::BasicIndexingDone, QStringLiteral(
"basic") },
221 { IndexStateReason::WaitingForContentIndexing, QStringLiteral(
"content") },
222 { IndexStateReason::FailedToIndex, QStringLiteral(
"content") },
223 { IndexStateReason::Done, QStringLiteral(
"content") },
226 for (
const auto& fileName : args) {
227 const auto file = collectFileStatus(tr, cfg, fileName);
229 if (file.m_fileStatus == FileStatus::NonExisting) {
230 err <<
i18n(
"Ignoring non-existent file %1", file.m_filePath) <<
'\n';
234 if (file.m_fileStatus == FileStatus::SymLink || file.m_fileStatus == FileStatus::Other) {
235 err <<
i18n(
"Ignoring symlink/special file %1", file.m_filePath) <<
'\n';
240 fileInfo[QStringLiteral(
"file")] = file.m_filePath;
241 fileInfo[QStringLiteral(
"indexing")] = jsonIndexLevelValue[file.m_indexState];
242 fileInfo[QStringLiteral(
"status")] = jsonIndexStateValue[file.m_indexState];
244 filesInfo.
append(fileInfo);
258 const QStringList allowedFormats({QStringLiteral(
"simple"), QStringLiteral(
"json"), QStringLiteral(
"multiline")});
259 const QString format = parser.
value(QStringLiteral(
"format"));
261 if (!allowedFormats.contains(format)) {
262 err <<
i18n(
"Output format \"%1\" is invalid, use one of:\n", format);
263 for (
const auto& format : allowedFormats) {
264 err <<
i18nc(
"bullet list item with output format",
"- %1\n", format);
270 if (!cfg.fileIndexingEnabled()) {
271 err <<
i18n(
"Baloo is currently disabled. To enable, please run %1\n", QStringLiteral(
"balooctl enable"));
275 Database *db = globalDatabaseInstance();
276 if (!db->open(Database::ReadOnlyDatabase)) {
277 err <<
i18n(
"Baloo Index could not be opened\n");
281 Transaction tr(db, Transaction::ReadOnly);
287 org::kde::baloo::main mainInterface(QStringLiteral(
"org.kde.baloo"),
291 org::kde::baloo::scheduler schedulerinterface(QStringLiteral(
"org.kde.baloo"),
292 QStringLiteral(
"/scheduler"),
295 bool running = mainInterface.isValid();
298 org::kde::baloo::fileindexer indexerInterface(QStringLiteral(
"org.kde.baloo"),
299 QStringLiteral(
"/fileindexer"),
302 const QString currentFile = indexerInterface.currentFile();
304 out <<
i18n(
"Baloo File Indexer is running\n");
306 out <<
i18n(
"Indexer state: %1", stateString(IndexerState::ContentIndexing)) <<
'\n';
307 out <<
i18nc(
"currently indexed file",
"Indexing: %1", currentFile) <<
'\n';
309 out <<
i18n(
"Indexer state: %1", stateString(schedulerinterface.state())) <<
'\n';
313 out <<
i18n(
"Baloo File Indexer is not running\n");
316 uint phaseOne = tr.phaseOneSize();
317 uint total = tr.size();
318 uint failed = tr.failedIds(100).size();
320 out <<
i18n(
"Total files indexed: %1", total) <<
'\n';
321 out <<
i18n(
"Files waiting for content indexing: %1", phaseOne) <<
'\n';
322 out <<
i18n(
"Files failed to index: %1", failed) <<
'\n';
327 const auto size = indexInfo.size();
330 out <<
i18n(
"Current size of index is %1", format.formatByteSize(size, 2)) <<
'\n';
332 out <<
i18n(
"Index does not exist yet\n");
334 }
else if (format == allowedFormats[0]){
335 printSimpleFormat(tr, cfg, args);
336 }
else if (format == allowedFormats[1]){
337 printJSON(tr, cfg, args);
339 printMultiLine(tr, cfg, args);
This class allows it to access the current config, to read and modify it.
bool shouldBeIndexed(const QString &path) const
Check if the file or folder path should be indexed.
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)
qsizetype size() const const
QStringList positionalArguments() const const
QString value(const QCommandLineOption &option) const const
QDBusConnection sessionBus()
QByteArray encodeName(const QString &fileName)
QString absoluteFilePath() const const
bool isFile() const const
bool isSymLink() const const
void append(const QJsonValue &value)
void setArray(const QJsonArray &array)
QByteArray toJson(JsonFormat format) const const
bool isEmpty() const const
bool isEmpty() const const