Baloo

newfileindexer.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Vishesh Handa <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #include "newfileindexer.h"
8 #include "basicindexingjob.h"
9 #include "fileindexerconfig.h"
10 
11 #include "database.h"
12 #include "transaction.h"
13 
14 #include <QMimeDatabase>
15 #include <QFileInfo>
16 
17 using namespace Baloo;
18 
19 NewFileIndexer::NewFileIndexer(Database* db, const FileIndexerConfig* config, const QStringList& newFiles)
20  : m_db(db)
21  , m_config(config)
22  , m_files(newFiles)
23 {
24  Q_ASSERT(m_db);
25  Q_ASSERT(m_config);
26  Q_ASSERT(!m_files.isEmpty());
27 }
28 
29 void NewFileIndexer::run()
30 {
31  QMimeDatabase mimeDb;
32  BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel
33  : BasicIndexingJob::MarkForContentIndexing;
34 
35  Transaction tr(m_db, Transaction::ReadWrite);
36 
37  for (const QString& filePath : std::as_const(m_files)) {
38  Q_ASSERT(!filePath.endsWith(QLatin1Char('/')));
39 
41  QFileInfo fileInfo(filePath);
42 
43  if (fileInfo.isSymLink()) {
44  continue;
45  }
46 
47  if (fileInfo.isDir()) {
48  if (!m_config->shouldFolderBeIndexed(filePath)) {
49  continue;
50  }
51  mimetype = QStringLiteral("inode/directory");
52 
53  } else {
54  QString fileName = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1);
55  if (!m_config->shouldFileBeIndexed(fileName)) {
56  continue;
57  }
59  }
60 
61  BasicIndexingJob job(filePath, mimetype, level);
62  if (!job.index()) {
63  continue;
64  }
65 
66  // The same file can be sent twice though it shouldn't be.
67  // Lets just silently ignore it instead of crashing
68  if (tr.hasDocument(job.document().id())) {
69  continue;
70  }
71  tr.addDocument(job.document());
72  }
73 
74  tr.commit();
75  Q_EMIT done();
76 }
77 
78 #include "moc_newfileindexer.cpp"
Q_EMITQ_EMIT
QStringView level(QStringView ifopt)
KIOCORE_EXPORT MimetypeJob * mimetype(const QUrl &url, JobFlags flags=DefaultFlags)
Implements storage for docIds without any associated data Instantiated for:
Definition: coding.cpp:11
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
KSharedConfigPtr config()
bool shouldFileBeIndexed(const QString &fileName) const
Check fileName for all exclude filters.
QMimeType mimeTypeForFile(const QString &fileName, QMimeDatabase::MatchMode mode) const const
QString mid(int position, int n) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
bool shouldFolderBeIndexed(const QString &path) const
Check if the folder at path should be indexed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.