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(localFileName: tr.documentUrl(id));
38
39 if (!QFile::exists(fileName: url)) {
40 qCDebug(BALOO) << "not exists: " << url;
41 return true;
42 }
43
44 if (!m_config->shouldBeIndexed(path: 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(filePath: QFile::encodeName(fileName: folder));
55 if (id > 0 && tr.hasDocument(id)) {
56 tr.removeRecursively(parentId: id, shouldDelete);
57 }
58 }
59 tr.commit();
60
61 Q_EMIT done();
62}
63
64#include "moc_indexcleaner.cpp"
65

source code of baloo/src/file/indexcleaner.cpp