Baloo

indexcleaner.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "indexcleaner.h"
8#include "fileindexerconfig.h"
9
10#include "database.h"
11#include "transaction.h"
12#include "idutils.h"
13
14#include "baloodebug.h"
15
16#include <QFile>
17
18using namespace Baloo;
19
20IndexCleaner::IndexCleaner(Database* db, FileIndexerConfig* config)
21 : m_db(db)
22 , m_config(config)
23{
24 Q_ASSERT(db);
25 Q_ASSERT(config);
26}
27
28void IndexCleaner::run()
29{
30 Transaction tr(m_db, Transaction::ReadWrite);
31
32 auto shouldDelete = [&](quint64 id) {
33 if (!id) {
34 return false;
35 }
36
37 const QString url = QFile::decodeName(tr.documentUrl(id));
38
39 if (!QFile::exists(url)) {
40 qCDebug(BALOO) << "not exists: " << url;
41 return true;
42 }
43
44 if (!m_config->shouldBeIndexed(url)) {
45 qCDebug(BALOO) << "should not be indexed: " << url;
46 return true;
47 }
48
49 return false;
50 };
51
52 const auto excludeFolders = m_config->excludeFolders();
53 for (const QString& folder : excludeFolders) {
54 quint64 id = filePathToId(QFile::encodeName(folder));
55 if (id > 0 && tr.hasDocument(id)) {
56 tr.removeRecursively(id, shouldDelete);
57 }
58 }
59 tr.commit();
60
61 Q_EMIT done();
62}
63
64#include "moc_indexcleaner.cpp"
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
QStringList excludeFolders() const
Folders that are excluded from indexing.
bool shouldBeIndexed(const QString &path) const
Check if file or folder path should be indexed taking into account the includeFolders(),...
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
QString decodeName(const QByteArray &localFileName)
QByteArray encodeName(const QString &fileName)
bool exists() const const
Q_EMITQ_EMIT
QString tr(const char *sourceText, const char *disambiguation, int n)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:51:50 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.