Merge pull request #314 from kiwix/trust_library

Trust the library.xml information by default.
This commit is contained in:
Matthieu Gautier 2020-01-30 19:02:13 +01:00 committed by GitHub
commit d14ba0c2e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 17 deletions

View File

@ -74,7 +74,7 @@ class Manager
* updated content. * updated content.
* @return True if file has been properly parsed. * @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. * Load a library content store in the string.
@ -87,7 +87,8 @@ class Manager
*/ */
bool readXml(const std::string& xml, bool readXml(const std::string& xml,
const bool readOnly = true, const bool readOnly = true,
const std::string& libraryPath = ""); const std::string& libraryPath = "",
bool trustLibrary = true);
/** /**
* Load a library content stored in a OPDS stream. * Load a library content stored in a OPDS stream.
@ -154,8 +155,9 @@ class Manager
bool readBookFromPath(const std::string& path, Book* book); bool readBookFromPath(const std::string& path, Book* book);
bool parseXmlDom(const pugi::xml_document& doc, bool parseXmlDom(const pugi::xml_document& doc,
const bool readOnly, bool readOnly,
const std::string& libraryPath); const std::string& libraryPath,
bool trustLibrary);
bool parseOpdsDom(const pugi::xml_document& doc, bool parseOpdsDom(const pugi::xml_document& doc,
const std::string& urlHost); const std::string& urlHost);

View File

@ -106,6 +106,7 @@ void Book::updateFromXml(const pugi::xml_node& node, const std::string& baseDir)
path = computeAbsolutePath(baseDir, path); path = computeAbsolutePath(baseDir, path);
} }
m_path = path; m_path = path;
m_pathValid = fileExists(path);
m_title = ATTR("title"); m_title = ATTR("title");
m_description = ATTR("description"); m_description = ATTR("description");
m_language = ATTR("language"); m_language = ATTR("language");

View File

@ -48,8 +48,9 @@ Manager::~Manager()
} }
} }
bool Manager::parseXmlDom(const pugi::xml_document& doc, bool Manager::parseXmlDom(const pugi::xml_document& doc,
const bool readOnly, bool readOnly,
const std::string& libraryPath) const std::string& libraryPath,
bool trustLibrary)
{ {
pugi::xml_node libraryNode = doc.child("library"); pugi::xml_node libraryNode = doc.child("library");
@ -63,12 +64,8 @@ bool Manager::parseXmlDom(const pugi::xml_document& doc,
book.updateFromXml(bookNode, book.updateFromXml(bookNode,
removeLastPathElement(libraryPath)); removeLastPathElement(libraryPath));
/* Update the book properties with the new importer */ if (!trustLibrary && !book.getPath().empty()) {
if (libraryVersion.empty() this->readBookFromPath(book.getPath(), &book);
|| atoi(libraryVersion.c_str()) <= atoi(KIWIX_LIBRARY_VERSION)) {
if (!book.getPath().empty()) {
this->readBookFromPath(book.getPath(), &book);
}
} }
manipulator->addBookToLibrary(book); manipulator->addBookToLibrary(book);
} }
@ -77,15 +74,16 @@ bool Manager::parseXmlDom(const pugi::xml_document& doc,
} }
bool Manager::readXml(const std::string& xml, bool Manager::readXml(const std::string& xml,
const bool readOnly, bool readOnly,
const std::string& libraryPath) const std::string& libraryPath,
bool trustLibrary)
{ {
pugi::xml_document doc; pugi::xml_document doc;
pugi::xml_parse_result result pugi::xml_parse_result result
= doc.load_buffer_inplace((void*)xml.data(), xml.size()); = doc.load_buffer_inplace((void*)xml.data(), xml.size());
if (result) { if (result) {
this->parseXmlDom(doc, readOnly, libraryPath); this->parseXmlDom(doc, readOnly, libraryPath, trustLibrary);
} }
return true; return true;
@ -136,7 +134,10 @@ bool Manager::readOpds(const std::string& content, const std::string& urlHost)
return false; 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; bool retVal = true;
pugi::xml_document doc; pugi::xml_document doc;
@ -148,7 +149,7 @@ bool Manager::readFile(const std::string& path, const bool readOnly)
#endif #endif
if (result) { if (result) {
this->parseXmlDom(doc, readOnly, path); this->parseXmlDom(doc, readOnly, path, trustLibrary);
} else { } else {
retVal = false; retVal = false;
} }