File indexing completed on 2024-04-28 03:51:54
0001 /* 0002 This file is part of the KDE Baloo Project 0003 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include <QDebug> 0009 #include <QTemporaryDir> 0010 #include <QFile> 0011 #include <QDir> 0012 #include <QElapsedTimer> 0013 #include <functional> 0014 0015 #include "documenturldb.h" 0016 #include "idutils.h" 0017 0018 using namespace Baloo; 0019 0020 int main(int /* argc */, char** /* argv */) 0021 { 0022 MDB_env* env; 0023 MDB_txn* txn; 0024 0025 QTemporaryDir tempDir; 0026 qDebug() << tempDir.path(); 0027 0028 mdb_env_create(&env); 0029 mdb_env_set_maxdbs(env, 2); 0030 mdb_env_set_mapsize(env, 1048576000); 0031 0032 // The directory needs to be created before opening the environment 0033 QByteArray path = QFile::encodeName(tempDir.path()); 0034 mdb_env_open(env, path.constData(), MDB_NOMEMINIT | MDB_WRITEMAP, 0664); 0035 mdb_txn_begin(env, nullptr, 0, &txn); 0036 0037 { 0038 DocumentUrlDB db(IdTreeDB::create(txn), IdFilenameDB::create(txn), txn); 0039 QElapsedTimer timer; 0040 timer.start(); 0041 0042 uint num = 0; 0043 std::function<void (const QDir&, quint64)> recurse = [&db, &num, &recurse](const QDir& dir, quint64 dirId) -> void { 0044 const auto entryInfos = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries); 0045 for (const auto& entryInfo : entryInfos) { 0046 QByteArray path = QFile::encodeName(entryInfo.absoluteFilePath()); 0047 auto entryId = filePathToId(path); 0048 db.put(entryId, dirId, path); 0049 num++; 0050 0051 if ((num % 10000) == 0) { 0052 qDebug() << num; 0053 } 0054 0055 if (entryInfo.isSymLink()) { 0056 // qDebug() << "skip" << entryInfo; 0057 } else if (entryInfo.isDir()) { 0058 // qDebug() << "recurse" << entryInfo; 0059 recurse(entryInfo.absoluteFilePath(), entryId); 0060 } 0061 } 0062 }; 0063 0064 QByteArray homePath = QFile::encodeName(QDir::homePath()); 0065 recurse(QDir::home(), filePathToId(homePath)); 0066 0067 mdb_txn_commit(txn); 0068 0069 qDebug() << "Done" << timer.elapsed() << "msecs"; 0070 } 0071 0072 // Cleanup 0073 //mdb_txn_abort(txn); 0074 mdb_env_close(env); 0075 0076 return 0; 0077 }