diff --git a/src/file/firstrunindexer.cpp b/src/file/firstrunindexer.cpp index eb9651a0..c8364451 100644 --- a/src/file/firstrunindexer.cpp +++ b/src/file/firstrunindexer.cpp @@ -1,87 +1,88 @@ /* * Copyright (C) 2015 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "firstrunindexer.h" #include "basicindexingjob.h" #include "fileindexerconfig.h" #include "filtereddiriterator.h" #include "database.h" #include "transaction.h" #include using namespace Baloo; FirstRunIndexer::FirstRunIndexer(Database* db, FileIndexerConfig* config, const QStringList& folders) : m_db(db) , m_config(config) , m_folders(folders) { Q_ASSERT(m_db); Q_ASSERT(m_config); Q_ASSERT(!m_folders.isEmpty()); } void FirstRunIndexer::run() { Q_ASSERT(m_config->isInitialRun()); { Transaction tr(m_db, Transaction::ReadOnly); Q_ASSERT_X(tr.size() == 0, "FirstRunIndexer", "The database is not empty on first run"); } QMimeDatabase mimeDb; + BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel + : BasicIndexingJob::MarkForContentIndexing; for (const QString& folder : qAsConst(m_folders)) { Transaction tr(m_db, Transaction::ReadWrite); FilteredDirIterator it(m_config, folder); while (!it.next().isEmpty()) { QString mimetype = mimeDb.mimeTypeForFile(it.filePath(), QMimeDatabase::MatchExtension).name(); if (!m_config->shouldMimeTypeBeIndexed(mimetype)) { continue; } - BasicIndexingJob::IndexingLevel level = - m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel : BasicIndexingJob::MarkForContentIndexing; + BasicIndexingJob job(it.filePath(), mimetype, level); if (!job.index()) { continue; } // Even though this is the first run, because 2 hard links will resolve to the same id, // we land up crashing (due to the asserts in addDocument). // Hence we are checking before. // FIXME: Silently ignore hard links! // if (tr.hasDocument(job.document().id())) { continue; } tr.addDocument(job.document()); } // FIXME: This would consume too much memory. We should make some more commits // based on how much memory we consume tr.commit(); } m_config->setInitialRun(false); Q_EMIT done(); } diff --git a/src/file/modifiedfileindexer.cpp b/src/file/modifiedfileindexer.cpp index 6ac9f822..a8e82ce7 100644 --- a/src/file/modifiedfileindexer.cpp +++ b/src/file/modifiedfileindexer.cpp @@ -1,108 +1,108 @@ /* * Copyright (C) 2015 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "modifiedfileindexer.h" #include "basicindexingjob.h" #include "fileindexerconfig.h" #include "idutils.h" #include "database.h" #include "transaction.h" #include #include #include #include using namespace Baloo; ModifiedFileIndexer::ModifiedFileIndexer(Database* db, const FileIndexerConfig* config, const QStringList& files) : m_db(db) , m_config(config) , m_files(files) { Q_ASSERT(m_db); Q_ASSERT(m_config); Q_ASSERT(!m_files.isEmpty()); } void ModifiedFileIndexer::run() { QMimeDatabase mimeDb; + BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel + : BasicIndexingJob::MarkForContentIndexing; Transaction tr(m_db, Transaction::ReadWrite); for (const QString& filePath : qAsConst(m_files)) { Q_ASSERT(!filePath.endsWith('/')); QString fileName = filePath.mid(filePath.lastIndexOf('/') + 1); if (!m_config->shouldFileBeIndexed(fileName)) { continue; } QString mimetype = mimeDb.mimeTypeForFile(filePath, QMimeDatabase::MatchExtension).name(); if (!m_config->shouldMimeTypeBeIndexed(mimetype)) { continue; } quint64 fileId = filePathToId(QFile::encodeName(filePath)); if (!fileId) { continue; } DocumentTimeDB::TimeInfo timeInfo = tr.documentTimeInfo(fileId); // FIXME: Using QFileInfo over here is quite expensive! QFileInfo fileInfo(filePath); // A folders mtime is updated when a new file is added / removed / renamed // we don't really need to reindex a folder when that happens // In fact, we never need to reindex a folder if (timeInfo.mTime && fileInfo.isDir()) { continue; } bool mTimeChanged = timeInfo.mTime != fileInfo.lastModified().toTime_t(); bool cTimeChanged = timeInfo.cTime != fileInfo.metadataChangeTime().toTime_t(); if (!mTimeChanged && !cTimeChanged) { continue; } // FIXME: The BasicIndexingJob extracts too much info. We only need the time - BasicIndexingJob::IndexingLevel level = - m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel : BasicIndexingJob::MarkForContentIndexing; BasicIndexingJob job(filePath, mimetype, level); if (!job.index()) { continue; } // we can get modified events for files which do not exist // cause Baloo was not running and missed those events if (tr.hasDocument(job.document().id())) { tr.replaceDocument(job.document(), DocumentTime); } else { tr.addDocument(job.document()); } } tr.commit(); Q_EMIT done(); } diff --git a/src/file/newfileindexer.cpp b/src/file/newfileindexer.cpp index 5452927d..d6e4d838 100644 --- a/src/file/newfileindexer.cpp +++ b/src/file/newfileindexer.cpp @@ -1,77 +1,77 @@ /* * Copyright (C) 2015 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "newfileindexer.h" #include "basicindexingjob.h" #include "fileindexerconfig.h" #include "database.h" #include "transaction.h" #include using namespace Baloo; NewFileIndexer::NewFileIndexer(Database* db, const FileIndexerConfig* config, const QStringList& newFiles) : m_db(db) , m_config(config) , m_files(newFiles) { Q_ASSERT(m_db); Q_ASSERT(m_config); Q_ASSERT(!m_files.isEmpty()); } void NewFileIndexer::run() { QMimeDatabase mimeDb; + BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel + : BasicIndexingJob::MarkForContentIndexing; Transaction tr(m_db, Transaction::ReadWrite); for (const QString& filePath : qAsConst(m_files)) { Q_ASSERT(!filePath.endsWith(QLatin1Char('/'))); QString fileName = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1); if (!m_config->shouldFileBeIndexed(fileName)) { continue; } QString mimetype = mimeDb.mimeTypeForFile(filePath, QMimeDatabase::MatchExtension).name(); if (!m_config->shouldMimeTypeBeIndexed(mimetype)) { continue; } - BasicIndexingJob::IndexingLevel level = - m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel : BasicIndexingJob::MarkForContentIndexing; BasicIndexingJob job(filePath, mimetype, level); if (!job.index()) { continue; } // The same file can be sent twice though it shouldn't be. // Lets just silently ignore it instead of crashing if (tr.hasDocument(job.document().id())) { continue; } tr.addDocument(job.document()); } tr.commit(); Q_EMIT done(); } diff --git a/src/file/xattrindexer.cpp b/src/file/xattrindexer.cpp index 009a7ebf..c4ed5bb1 100644 --- a/src/file/xattrindexer.cpp +++ b/src/file/xattrindexer.cpp @@ -1,82 +1,82 @@ /* * Copyright (C) 2015 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "xattrindexer.h" #include "basicindexingjob.h" #include "fileindexerconfig.h" #include "database.h" #include "transaction.h" #include using namespace Baloo; XAttrIndexer::XAttrIndexer(Database* db, const FileIndexerConfig* config, const QStringList& files) : m_db(db) , m_config(config) , m_files(files) { Q_ASSERT(m_db); Q_ASSERT(m_config); Q_ASSERT(!m_files.isEmpty()); } void XAttrIndexer::run() { QMimeDatabase mimeDb; + BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel + : BasicIndexingJob::MarkForContentIndexing; Transaction tr(m_db, Transaction::ReadWrite); for (const QString& filePath : qAsConst(m_files)) { Q_ASSERT(!filePath.endsWith(QLatin1Char('/'))); QString fileName = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1); if (!m_config->shouldFileBeIndexed(fileName)) { continue; } QString mimetype = mimeDb.mimeTypeForFile(filePath, QMimeDatabase::MatchExtension).name(); if (!m_config->shouldMimeTypeBeIndexed(mimetype)) { continue; } // FIXME: The BasicIndexingJob extracts too much info. We only need the xattr - BasicIndexingJob::IndexingLevel level = - m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel : BasicIndexingJob::MarkForContentIndexing; BasicIndexingJob job(filePath, mimetype, level); if (!job.index()) { continue; } // FIXME: This slightly defeats the point of having separate indexers // But we can get xattr changes of a file, even when it doesn't exist // cause we missed its creation somehow if (!tr.hasDocument(job.document().id())) { tr.addDocument(job.document()); continue; } // FIXME: Do we also need to update the ctime of the file? tr.replaceDocument(job.document(), XAttrTerms); } tr.commit(); Q_EMIT done(); }