[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kfilemetadata] /: Make odf indexer more error prove, check if the files are there (and are files at
From: Christoph Cullmann <cullmann () kde ! org>
Date: 2016-09-11 13:08:56
Message-ID: E1bj4VE-0000wI-Ql () code ! kde ! org
[Download RAW message or body]
Git commit 40730d75397aefb92145f86fc6abc9b303c56cfe by Christoph Cullmann.
Committed on 11/09/2016 at 13:07.
Pushed by cullmann into branch 'master'.
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
M +19 -3 autotests/odfextractortest.cpp
M +3 -0 autotests/odfextractortest.h
A +- -- autotests/samplefiles/test_missing_content.odt
A +- -- autotests/samplefiles/test_missing_meta.odt
M +12 -7 src/extractors/odfextractor.cpp
http://commits.kde.org/kfilemetadata/40730d75397aefb92145f86fc6abc9b303c56cfe
diff --git a/autotests/odfextractortest.cpp b/autotests/odfextractortest.cpp
index bea3640..1b68d3b 100644
--- a/autotests/odfextractortest.cpp
+++ b/autotests/odfextractortest.cpp
@@ -1,6 +1,7 @@
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright (C) 2014 Vishesh Handa <me@vhanda.in>
+ * Copyright (C) 2016 Christoph Cullmann <cullmann@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -37,7 +38,7 @@ QString OdfExtractorTest::testFilePath(const QString& fileName) \
const
void OdfExtractorTest::testText()
{
- QScopedPointer<ExtractorPlugin> plugin(new OdfExtractor(this));
+ QScopedPointer<ExtractorPlugin> plugin(new OdfExtractor());
SimpleExtractionResult result(testFilePath(QStringLiteral("test.odt")), \
QStringLiteral("application/vnd.oasis.opendocument.text")); \
plugin->extract(&result); @@ -62,7 +63,7 @@ void OdfExtractorTest::testText()
void OdfExtractorTest::testTextMetaDataOnly()
{
- QScopedPointer<ExtractorPlugin> plugin(new OdfExtractor(this));
+ QScopedPointer<ExtractorPlugin> plugin(new OdfExtractor());
SimpleExtractionResult result(testFilePath(QStringLiteral("test.odt")), \
QStringLiteral("application/vnd.oasis.opendocument.text"), \
ExtractionResult::ExtractMetaData); plugin->extract(&result);
@@ -74,7 +75,7 @@ void OdfExtractorTest::testTextMetaDataOnly()
void OdfExtractorTest::testPresentation()
{
- QScopedPointer<ExtractorPlugin> plugin(new OdfExtractor(this));
+ QScopedPointer<ExtractorPlugin> plugin(new OdfExtractor());
SimpleExtractionResult result(testFilePath(QStringLiteral("test.odp")), \
QStringLiteral("application/vnd.oasis.opendocument.presentation")); \
plugin->extract(&result); @@ -90,5 +91,20 @@ void \
OdfExtractorTest::testPresentation() QCOMPARE(result.text(), \
QStringLiteral("KFileMetaData Pres ")); }
+void OdfExtractorTest::testTextMissingMetaNoCrash()
+{
+ QScopedPointer<ExtractorPlugin> plugin(new OdfExtractor());
+
+ SimpleExtractionResult \
result(testFilePath(QStringLiteral("test_missing_meta.odt")), \
QStringLiteral("application/vnd.oasis.opendocument.text")); + \
plugin->extract(&result); +}
+
+void OdfExtractorTest::testTextMissingContentNoCrash()
+{
+ QScopedPointer<ExtractorPlugin> plugin(new OdfExtractor());
+
+ SimpleExtractionResult \
result(testFilePath(QStringLiteral("test_missing_content.odt")), \
QStringLiteral("application/vnd.oasis.opendocument.text")); + \
plugin->extract(&result); +}
QTEST_MAIN(OdfExtractorTest)
diff --git a/autotests/odfextractortest.h b/autotests/odfextractortest.h
index 3e6a1c7..89642ce 100644
--- a/autotests/odfextractortest.h
+++ b/autotests/odfextractortest.h
@@ -1,6 +1,7 @@
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright (C) 2014 Vishesh Handa <me@vhanda.in>
+ * Copyright (C) 2016 Christoph Cullmann <cullmann@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -35,6 +36,8 @@ private Q_SLOTS:
void testPresentation();
+ void testTextMissingMetaNoCrash();
+ void testTextMissingContentNoCrash();
};
#endif // ODFEXTRACTORTEST_H
diff --git a/autotests/samplefiles/test_missing_content.odt \
b/autotests/samplefiles/test_missing_content.odt new file mode 100644
index 0000000..7f7ac4b
Binary files /dev/null and b/autotests/samplefiles/test_missing_content.odt differ
diff --git a/autotests/samplefiles/test_missing_meta.odt \
b/autotests/samplefiles/test_missing_meta.odt new file mode 100644
index 0000000..8549639
Binary files /dev/null and b/autotests/samplefiles/test_missing_meta.odt differ
diff --git a/src/extractors/odfextractor.cpp b/src/extractors/odfextractor.cpp
index 948f3e0..3d224dc 100644
--- a/src/extractors/odfextractor.cpp
+++ b/src/extractors/odfextractor.cpp
@@ -2,6 +2,7 @@
<one line to give the library's name and an idea of what it does.>
Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
Copyright (C) 2012 Jörg Ehrichs <joerg.ehrichs@gmx.de>
+ Copyright (C) 2016 Christoph Cullmann <cullmann@kde.org>
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 @@ void OdfExtractor::extract(ExtractionResult* result)
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<const \
KArchiveFile*>(directory->entry(QStringLiteral("meta.xml")));
- metaData.setContent(file->data());
+ metaData.setContent(static_cast<const KArchiveFile*>(metaXml)->data());
// parse metadata ...
QDomElement docElem = metaData.documentElement();
-
QDomNode n = docElem.firstChild().firstChild(); // <office:document-meta> ... \
<office:meta> ... content while (!n.isNull()) {
QDomElement e = n.toElement();
@@ -129,9 +129,14 @@ void OdfExtractor::extract(ExtractionResult* result)
return;
}
- const KArchiveFile* contentsFile = static_cast<const \
KArchiveFile*>(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<const \
KArchiveFile*>(contentXml)->createDevice()); while (!xml.atEnd()) {
xml.readNext();
if (xml.isCharacters()) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic