diff --git a/src/engine/transaction.h b/src/engine/transaction.h --- a/src/engine/transaction.h +++ b/src/engine/transaction.h @@ -113,6 +113,7 @@ m_writeTrans->removeRecursively(id, shouldDelete); } + void pruneFsTree(); void replaceDocument(const Document& doc, DocumentOperations operations); void setPhaseOne(quint64 id); void removePhaseOne(quint64 id); diff --git a/src/engine/transaction.cpp b/src/engine/transaction.cpp --- a/src/engine/transaction.cpp +++ b/src/engine/transaction.cpp @@ -254,6 +254,28 @@ m_writeTrans->replaceDocument(doc, operations); } +void Transaction::pruneFsTree() +{ + DocumentUrlDB docUrlDb(m_dbis.idTreeDbi, m_dbis.idFilenameDbi, m_txn); + + auto map = docUrlDb.toTestMap(); + + QTextStream out(stdout); + out << "Total Document IDs: " << map.size() << endl; + + int count = 0; + for (quint64 id: map.keys()) { + QByteArray url = docUrlDb.get(id); + if (!QFileInfo::exists(url)) { + out << "Purging " << id << endl; + m_writeTrans->removeDocument(id); + count++; + } + } + + out << "Removed Entries: " << count << " (" << count * 100.0 / map.size() << "%)" << endl; +} + void Transaction::commit() { Q_ASSERT(m_txn); diff --git a/src/tools/balooctl/main.cpp b/src/tools/balooctl/main.cpp --- a/src/tools/balooctl/main.cpp +++ b/src/tools/balooctl/main.cpp @@ -87,6 +87,7 @@ parser.addPositionalArgument(QStringLiteral("clear"), i18n("Forget the specified files")); parser.addPositionalArgument(QStringLiteral("config"), i18n("Modify the Baloo configuration")); parser.addPositionalArgument(QStringLiteral("monitor"), i18n("Monitor the file indexer")); + parser.addPositionalArgument(QStringLiteral("pruneDb"), i18n("Purge invalid index entries")); parser.addPositionalArgument(QStringLiteral("indexSize"), i18n("Display the disk space used by index")); parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("f") << QStringLiteral("format"), i18n("Output format <%1|%2|%3>.\nOnly applies to \"%4\"", @@ -322,6 +323,19 @@ return mon.exec(parser); } + if (command == QStringLiteral("pruneDb")) { + Database *db = globalDatabaseInstance(); + if (!db->open(Database::ReadOnlyDatabase)) { + out << "Baloo Index could not be opened\n"; + return 1; + } + + Transaction tr(db, Transaction::ReadOnly); + out << "Checking file paths .. " << endl; + tr.pruneFsTree(); + return 0; + } + /* TODO: Make separate executable if (command == QStringLiteral("checkDb")) {