diff --git a/src/file/autotest/fileindexingjob/extractor.cpp b/src/file/autotest/fileindexingjob/extractor.cpp index a6d14d74..aa31258a 100644 --- a/src/file/autotest/fileindexingjob/extractor.cpp +++ b/src/file/autotest/fileindexingjob/extractor.cpp @@ -1,83 +1,83 @@ /* * This file is part of the KDE Baloo Project * Copyright (C) 2014 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) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * 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, see . * */ #include #include #include #include #include #include #include #include #include #include int main(int argc, char* argv[]) { KAboutData aboutData("baloo_file_extractor_dummy", 0, KLocalizedString(), "0.1", KLocalizedString()); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineOptions options; options.add("+[url]", KLocalizedString()); KCmdLineArgs::addCmdLineOptions(options); const KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); int argCount = args->count(); if (argCount == 0) { QTextStream err(stderr); err << "Must input url/id of the file to be indexed"; return 1; } KComponentData data(aboutData, KComponentData::RegisterAsMainComponent); QByteArray failArr = qgetenv("BALOO_EXTRACTOR_FAIL_FILE"); QByteArray timeoutArr = qgetenv("BALOO_EXTRACTOR_TIMEOUT_FILE"); if (failArr.isEmpty() && timeoutArr.isEmpty()) { return 0; } QStringList failFiles = QString::fromUtf8(failArr).split(",", QString::SkipEmptyParts); QStringList timeoutFiles = QString::fromUtf8(timeoutArr).split(",", QString::SkipEmptyParts); for (int i = 0; i < args->count(); i++) { QString fid = args->arg(i); if (failFiles.contains(fid)) { // kill oneself raise(SIGKILL); return -1; } if (timeoutFiles.contains(fid)) { // 100 msecs - usleep(100 * 1000); + sleep(100); } } return 0; } diff --git a/src/xapian/xapiandatabase.cpp b/src/xapian/xapiandatabase.cpp index 8f661fc2..f5657eac 100644 --- a/src/xapian/xapiandatabase.cpp +++ b/src/xapian/xapiandatabase.cpp @@ -1,201 +1,202 @@ /* * Copyright (C) 2014 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 "xapiandatabase.h" #include "xapiandocument.h" #include #include #include #ifdef __GNUC__ #include -#include #endif +#include + using namespace Baloo; XapianDatabase::XapianDatabase(const QString& path, bool writeOnly) : m_db(0) , m_writeOnly(writeOnly) { QDir().mkpath(path); m_path = path.toUtf8().constData(); if (!writeOnly) { try { createWritableDb(); m_db = new Xapian::Database(m_path); } catch (const Xapian::DatabaseError& err) { kError() << "Serious Error: " << err.get_error_string(); kError() << err.get_msg().c_str() << err.get_context().c_str() << err.get_description().c_str(); } // Possible errors - DatabaseLock error // Corrupt and InvalidID error } else { m_wDb = createWritableDb(); } } XapianDatabase::~XapianDatabase() { delete m_db; } void XapianDatabase::replaceDocument(uint id, const XapianDocument& doc) { replaceDocument(id, doc.doc()); } void XapianDatabase::replaceDocument(uint id, const Xapian::Document& doc) { if (m_writeOnly) { try { m_wDb.replace_document(id, doc); } catch (const Xapian::Error&) { } return; } m_docsToAdd << qMakePair(id, doc); } void XapianDatabase::deleteDocument(uint id) { if (m_writeOnly) { try { m_wDb.delete_document(id); } catch (const Xapian::Error&) { } return; } m_docsToRemove << id; } void XapianDatabase::commit() { if (m_writeOnly) { try { m_wDb.commit(); } catch (const Xapian::Error& err) { kError() << err.get_error_string(); } return; } if (m_docsToAdd.isEmpty() && m_docsToRemove.isEmpty()) { return; } Xapian::WritableDatabase wdb = createWritableDb(); kDebug() << "Adding:" << m_docsToAdd.size() << "docs"; Q_FOREACH (const DocIdPair& doc, m_docsToAdd) { try { wdb.replace_document(doc.first, doc.second); } catch (const Xapian::Error&) { } } kDebug() << "Removing:" << m_docsToRemove.size() << "docs"; Q_FOREACH (Xapian::docid id, m_docsToRemove) { try { wdb.delete_document(id); } catch (const Xapian::Error&) { } } try { wdb.commit(); m_db->reopen(); } catch (const Xapian::Error& err) { kError() << err.get_error_string(); } kDebug() << "Xapian Committed"; m_docsToAdd.clear(); m_docsToRemove.clear(); #ifdef __GNUC__ malloc_trim(0); #endif } XapianDocument XapianDatabase::document(uint id) { try { Xapian::Document xdoc; if (m_writeOnly) { xdoc = m_wDb.get_document(id); } else { xdoc = m_db->get_document(id); } return XapianDocument(xdoc); } catch (const Xapian::DatabaseModifiedError&) { m_db->reopen(); return document(id); } catch (const Xapian::Error&) { return XapianDocument(); } } Xapian::WritableDatabase XapianDatabase::createWritableDb() { // We need to keep sleeping for a required amount, until we reach // a threshold. That's when we decide to abort? for (int i = 1; i <= 20; i++) { try { Xapian::WritableDatabase wdb(m_path, Xapian::DB_CREATE_OR_OPEN); return wdb; } catch (const Xapian::DatabaseLockError&) { - usleep(i * 50 * 1000); + sleep(i * 50 ); } catch (const Xapian::DatabaseModifiedError&) { - usleep(i * 50 * 1000); + sleep(i * 50 ); } catch (const Xapian::DatabaseCreateError& err) { kDebug() << err.get_error_string(); return Xapian::WritableDatabase(); } catch (const Xapian::DatabaseCorruptError& err) { kError() << "Database Corrupted - What did you do?"; kError() << err.get_error_string(); return Xapian::WritableDatabase(); } catch (...) { kError() << "Bananana Error"; return Xapian::WritableDatabase(); } } kError() << "Could not obtain lock for Xapian Database. This is bad"; return Xapian::WritableDatabase(); }