2
This file is part of the Nepomuk KDE project.
3
Copyright (C) 2010-2011 Sebastian Trueg <trueg@kde.org>
4
Copyright (C) 2012-2014 Vishesh Handa <me@vhanda.in>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) version 3, or any
10
later version accepted by the membership of KDE e.V. (or its
11
successor approved by the membership of KDE e.V.), which shall
12
act as a proxy defined in Section 6 of version 3 of the license.
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Lesser General Public License for more details.
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library. If not, see <http://www.gnu.org/licenses/>.
23
#include "fileindexingjob.h"
25
#include "fileindexerconfig.h"
28
#include <qjson/serializer.h>
31
#include <KStandardDirs>
33
#include <QtCore/QFileInfo>
34
#include <QtCore/QTimer>
36
using namespace Baloo;
38
FileIndexingJob::FileIndexingJob(const QVector<uint>& files, QObject* parent)
43
// setup the timer used to kill the indexer process if it seems to get stuck
44
m_processTimer = new QTimer(this);
45
m_processTimer->setSingleShot(true);
46
connect(m_processTimer, SIGNAL(timeout()),
47
this, SLOT(slotProcessTimerTimeout()));
49
m_processTimeout = 5 * 60 * 1000;
52
void FileIndexingJob::start()
54
Q_ASSERT(!m_files.isEmpty());
62
void FileIndexingJob::start(const QVector<uint>& files)
64
// setup the external process which does the actual indexing
65
const QString exe = KStandardDirs::findExe(QLatin1String("baloo_file_extractor"));
69
m_process->disconnect();
75
m_process = new QProcess(this);
78
Q_FOREACH (const uint& file, files)
79
args << QString::number(file);
81
if (!m_customDbPath.isEmpty()) {
82
args << "--db" << m_customDbPath;
86
connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)),
87
this, SLOT(slotIndexedFile(int,QProcess::ExitStatus)));
89
m_process->setProcessChannelMode(QProcess::SeparateChannels);
90
m_process->start(exe, args);
92
m_processTimer->start(m_processTimeout);
95
void FileIndexingJob::slotIndexedFile(int, QProcess::ExitStatus exitStatus)
97
// stop the timer since there is no need to kill the process anymore
98
m_processTimer->stop();
99
m_process->deleteLater();
102
if (exitStatus == QProcess::NormalExit) {
103
if (m_files.isEmpty()) {
109
if (m_args.size() == 1) {
110
uint doc = m_args.first();
111
kError() << "Indexer crashed while indexing" << doc;
112
kError() << "Blacklisting this file";
113
Q_EMIT indexingFailed(doc);
115
if (m_files.isEmpty()) {
125
// Split the number of files into half
126
if (m_files.size() == 1) {
133
int mid = m_files.size()/2;
134
m_args = m_files.mid(mid);
141
void FileIndexingJob::slotProcessTimerTimeout()
143
// Emulate a crash so that we narrow down the file which is taking too long
144
slotIndexedFile(1, QProcess::CrashExit);
147
void FileIndexingJob::setCustomDbPath(const QString& path)
149
m_customDbPath = path;
152
void FileIndexingJob::setTimeoutInterval(int msec)
154
m_processTimeout = msec;
159
#include "fileindexingjob.moc"