File indexing completed on 2024-04-14 03:49:45
0001 /* 0002 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> 0003 SPDX-FileCopyrightText: 2015 Pinak Ahuja <pinak.ahuja@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #include "baloodebug.h" 0009 #include "extractorprocess.h" 0010 0011 using namespace Baloo; 0012 0013 ExtractorProcess::ExtractorProcess(const QString& extractorPath, QObject* parent) 0014 : QObject(parent) 0015 , m_extractorPath(extractorPath) 0016 , m_extractorProcess(this) 0017 , m_controller(&m_extractorProcess, &m_extractorProcess) 0018 { 0019 using ControllerPipe = Baloo::Private::ControllerPipe; 0020 0021 connect(&m_extractorProcess, &QProcess::readyRead, &m_controller, &ControllerPipe::processStatusData); 0022 connect(&m_controller, &ControllerPipe::urlStarted, this, &ExtractorProcess::startedIndexingFile); 0023 connect(&m_controller, &ControllerPipe::urlFinished, this, [this](const QString& url) { 0024 Q_EMIT finishedIndexingFile(url, true); 0025 }); 0026 connect(&m_controller, &ControllerPipe::urlFailed, this, [this](const QString& url) { 0027 Q_EMIT finishedIndexingFile(url, false); 0028 }); 0029 connect(&m_controller, &ControllerPipe::batchFinished, this, [this]() { 0030 qCDebug(BALOO) << "Batch finished"; 0031 Q_EMIT done(); 0032 }); 0033 0034 connect(&m_extractorProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), [=](int exitCode, QProcess::ExitStatus exitStatus) { 0035 if (exitStatus == QProcess::CrashExit) { 0036 qCWarning(BALOO) << "Extractor crashed"; 0037 Q_EMIT failed(); 0038 } else if (exitCode == 1) { 0039 // DB open error 0040 Q_EMIT failed(); 0041 } else if (exitCode == 2) { 0042 // DB transaction commit error 0043 Q_EMIT failed(); 0044 } else if (exitCode == 253) { 0045 // DrKonqi mangles signals depending on the core_pattern 0046 // and does a regular exit with status 253 instead 0047 qCWarning(BALOO) << "Extractor probably crashed"; 0048 Q_EMIT failed(); 0049 } else if (exitCode != 0) { 0050 qCWarning(BALOO) << "Unexpected exit code:" << exitCode; 0051 Q_EMIT failed(); 0052 } 0053 }); 0054 0055 m_extractorProcess.setProgram(m_extractorPath); 0056 m_extractorProcess.setProcessChannelMode(QProcess::ForwardedErrorChannel); 0057 m_extractorProcess.start(); 0058 } 0059 0060 ExtractorProcess::~ExtractorProcess() 0061 { 0062 m_extractorProcess.closeWriteChannel(); 0063 m_extractorProcess.waitForFinished(); 0064 m_extractorProcess.close(); 0065 } 0066 0067 void ExtractorProcess::start() 0068 { 0069 m_extractorProcess.start(QIODevice::Unbuffered | QIODevice::ReadWrite); 0070 m_extractorProcess.waitForStarted(); 0071 m_extractorProcess.setReadChannel(QProcess::StandardOutput); 0072 } 0073 0074 void ExtractorProcess::index(const QVector<quint64>& fileIds) 0075 { 0076 Q_ASSERT(!fileIds.isEmpty()); 0077 m_controller.processIds(fileIds); 0078 } 0079 0080 #include "moc_extractorprocess.cpp"