File indexing completed on 2024-04-21 03:51:45
0001 /* 0002 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include "indexcleaner.h" 0008 #include "fileindexerconfig.h" 0009 0010 #include "database.h" 0011 #include "transaction.h" 0012 #include "idutils.h" 0013 0014 #include "baloodebug.h" 0015 0016 #include <QFile> 0017 0018 using namespace Baloo; 0019 0020 IndexCleaner::IndexCleaner(Database* db, FileIndexerConfig* config) 0021 : m_db(db) 0022 , m_config(config) 0023 { 0024 Q_ASSERT(db); 0025 Q_ASSERT(config); 0026 } 0027 0028 void IndexCleaner::run() 0029 { 0030 Transaction tr(m_db, Transaction::ReadWrite); 0031 0032 auto shouldDelete = [&](quint64 id) { 0033 if (!id) { 0034 return false; 0035 } 0036 0037 const QString url = QFile::decodeName(tr.documentUrl(id)); 0038 0039 if (!QFile::exists(url)) { 0040 qCDebug(BALOO) << "not exists: " << url; 0041 return true; 0042 } 0043 0044 if (!m_config->shouldBeIndexed(url)) { 0045 qCDebug(BALOO) << "should not be indexed: " << url; 0046 return true; 0047 } 0048 0049 return false; 0050 }; 0051 0052 const auto excludeFolders = m_config->excludeFolders(); 0053 for (const QString& folder : excludeFolders) { 0054 quint64 id = filePathToId(QFile::encodeName(folder)); 0055 if (id > 0 && tr.hasDocument(id)) { 0056 tr.removeRecursively(id, shouldDelete); 0057 } 0058 } 0059 tr.commit(); 0060 0061 Q_EMIT done(); 0062 } 0063 0064 #include "moc_indexcleaner.cpp"