From 34257cfc1f65787d4e1bf6b1c72a0e4a8b14bf48 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 29 Jan 2020 18:13:56 +0100 Subject: [PATCH] Trust the library.xml information by default. Do not try to read the zim file and update the book when parsing a library.xml. Needed by kiwix/kiwix-tools#319 --- include/manager.h | 10 ++++++---- src/book.cpp | 1 + src/manager.cpp | 27 ++++++++++++++------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/include/manager.h b/include/manager.h index 13087ca70..49bc6c8d8 100644 --- a/include/manager.h +++ b/include/manager.h @@ -74,7 +74,7 @@ class Manager * updated content. * @return True if file has been properly parsed. */ - bool readFile(const std::string& path, const bool readOnly = true); + bool readFile(const std::string& path, bool readOnly = true, bool trustLibrary = true); /** * Load a library content store in the string. @@ -87,7 +87,8 @@ class Manager */ bool readXml(const std::string& xml, const bool readOnly = true, - const std::string& libraryPath = ""); + const std::string& libraryPath = "", + bool trustLibrary = true); /** * Load a library content stored in a OPDS stream. @@ -154,8 +155,9 @@ class Manager bool readBookFromPath(const std::string& path, Book* book); bool parseXmlDom(const pugi::xml_document& doc, - const bool readOnly, - const std::string& libraryPath); + bool readOnly, + const std::string& libraryPath, + bool trustLibrary); bool parseOpdsDom(const pugi::xml_document& doc, const std::string& urlHost); diff --git a/src/book.cpp b/src/book.cpp index 8b2f30db7..d8e90d7ca 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -106,6 +106,7 @@ void Book::updateFromXml(const pugi::xml_node& node, const std::string& baseDir) path = computeAbsolutePath(baseDir, path); } m_path = path; + m_pathValid = fileExists(path); m_title = ATTR("title"); m_description = ATTR("description"); m_language = ATTR("language"); diff --git a/src/manager.cpp b/src/manager.cpp index cf2534856..a524d380b 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -48,8 +48,9 @@ Manager::~Manager() } } bool Manager::parseXmlDom(const pugi::xml_document& doc, - const bool readOnly, - const std::string& libraryPath) + bool readOnly, + const std::string& libraryPath, + bool trustLibrary) { pugi::xml_node libraryNode = doc.child("library"); @@ -63,12 +64,8 @@ bool Manager::parseXmlDom(const pugi::xml_document& doc, book.updateFromXml(bookNode, removeLastPathElement(libraryPath)); - /* Update the book properties with the new importer */ - if (libraryVersion.empty() - || atoi(libraryVersion.c_str()) <= atoi(KIWIX_LIBRARY_VERSION)) { - if (!book.getPath().empty()) { - this->readBookFromPath(book.getPath(), &book); - } + if (!trustLibrary && !book.getPath().empty()) { + this->readBookFromPath(book.getPath(), &book); } manipulator->addBookToLibrary(book); } @@ -77,15 +74,16 @@ bool Manager::parseXmlDom(const pugi::xml_document& doc, } bool Manager::readXml(const std::string& xml, - const bool readOnly, - const std::string& libraryPath) + bool readOnly, + const std::string& libraryPath, + bool trustLibrary) { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_buffer_inplace((void*)xml.data(), xml.size()); if (result) { - this->parseXmlDom(doc, readOnly, libraryPath); + this->parseXmlDom(doc, readOnly, libraryPath, trustLibrary); } return true; @@ -136,7 +134,10 @@ bool Manager::readOpds(const std::string& content, const std::string& urlHost) return false; } -bool Manager::readFile(const std::string& path, const bool readOnly) +bool Manager::readFile( + const std::string& path, + bool readOnly, + bool trustLibrary) { bool retVal = true; pugi::xml_document doc; @@ -148,7 +149,7 @@ bool Manager::readFile(const std::string& path, const bool readOnly) #endif if (result) { - this->parseXmlDom(doc, readOnly, path); + this->parseXmlDom(doc, readOnly, path, trustLibrary); } else { retVal = false; }