From: Christoph Cullmann Date: Sun, 11 Sep 2016 13:07:47 +0000 Subject: Make odf indexer more error prove, check if the files are there (and are files at all) (meta.xml + content.xml) X-Git-Url: http://quickgit.kde.org/?p=kfilemetadata.git&a=commitdiff&h=40730d75397aefb92145f86fc6abc9b303c56cfe --- Make odf indexer more error prove, check if the files are there (and are files at all) (meta.xml + content.xml) REVIEW: 128886 BUG 364748 => if you download this odt's to indexed directories your baloo will die on each index, be careful --- --- a/src/extractors/odfextractor.cpp +++ b/src/extractors/odfextractor.cpp @@ -2,6 +2,7 @@ Copyright (C) 2013 Vishesh Handa Copyright (C) 2012 Jörg Ehrichs + Copyright (C) 2016 Christoph Cullmann This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -59,19 +60,18 @@ return; } - const QStringList entries = directory->entries(); - if (!entries.contains(QStringLiteral("meta.xml"))) { + // we need a meta xml file in the archive! + const auto metaXml = directory->entry(QStringLiteral("meta.xml")); + if (!metaXml || !metaXml->isFile()) { qWarning() << "Invalid document structure (meta.xml is missing)"; return; } QDomDocument metaData(QStringLiteral("metaData")); - const KArchiveFile* file = static_cast(directory->entry(QStringLiteral("meta.xml"))); - metaData.setContent(file->data()); + metaData.setContent(static_cast(metaXml)->data()); // parse metadata ... QDomElement docElem = metaData.documentElement(); - QDomNode n = docElem.firstChild().firstChild(); // ... ... content while (!n.isNull()) { QDomElement e = n.toElement(); @@ -129,9 +129,14 @@ return; } - const KArchiveFile* contentsFile = static_cast(directory->entry(QStringLiteral("content.xml"))); - QXmlStreamReader xml(contentsFile->createDevice()); + // for content indexing, we need content xml file + const auto contentXml = directory->entry(QStringLiteral("content.xml")); + if (!contentXml || !contentXml->isFile()) { + qWarning() << "Invalid document structure (content.xml is missing)"; + return; + } + QXmlStreamReader xml(static_cast(contentXml)->createDevice()); while (!xml.atEnd()) { xml.readNext(); if (xml.isCharacters()) {