diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index d82d65f..9b905a1 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -452,8 +452,8 @@ int main(int argc, char **argv) { vector::iterator itr; kiwix::Book currentBook; for ( itr = booksIds.begin(); itr != booksIds.end(); ++itr ) { + bool zimFileOk = false; libraryManager.getBookById(*itr, currentBook); - string humanReadableId = currentBook.getHumanReadableIdFromPath(); zimPath = currentBook.pathAbsolute; if (!zimPath.empty()) { @@ -463,38 +463,42 @@ int main(int argc, char **argv) { kiwix::Reader *reader = NULL; try { reader = new kiwix::Reader(zimPath); + zimFileOk = true; } catch (...) { - cerr << "Unable to open the ZIM file '" << zimPath << "'." << endl; - exit(1); + cerr << "Unable to open the ZIM file '" << zimPath << "'." << endl; } - readers[humanReadableId] = reader; + + if (zimFileOk) { + string humanReadableId = currentBook.getHumanReadableIdFromPath(); + readers[humanReadableId] = reader; - /* Instanciate the ZIM index (if necessary) */ - kiwix::Searcher *searcher = NULL; - if (indexPath != "") { - bool hasSearchIndex = false; - - /* Try to load the search */ - try { - if (currentBook.indexType == kiwix::XAPIAN) { - searcher = new kiwix::XapianSearcher(indexPath); - } else if (currentBook.indexType == kiwix::CLUCENE) { + /* Instanciate the ZIM index (if necessary) */ + kiwix::Searcher *searcher = NULL; + if (indexPath != "") { + bool hasSearchIndex = false; + + /* Try to load the search */ + try { + if (currentBook.indexType == kiwix::XAPIAN) { + searcher = new kiwix::XapianSearcher(indexPath); + } else if (currentBook.indexType == kiwix::CLUCENE) { #ifndef _WIN32 - searcher = new kiwix::CluceneSearcher(indexPath); + searcher = new kiwix::CluceneSearcher(indexPath); #endif - } else { - throw("Unknown index type"); + } else { + throw("Unknown index type"); + } + hasSearchIndex = true; + } catch (...) { + cerr << "Unable to open the search index '" << zimPath << "'." << endl; + } + + if (hasSearchIndex) { + searcher->setProtocolPrefix("/"); + searcher->setSearchProtocolPrefix("/search?"); + searcher->setContentHumanReadableId(humanReadableId); + searchers[humanReadableId] = searcher; } - hasSearchIndex = true; - } catch (...) { - cerr << "Unable to open the search index '" << zimPath << "'." << endl; - } - - if (hasSearchIndex) { - searcher->setProtocolPrefix("/"); - searcher->setSearchProtocolPrefix("/search?"); - searcher->setContentHumanReadableId(humanReadableId); - searchers[humanReadableId] = searcher; } } } @@ -504,7 +508,7 @@ int main(int argc, char **argv) { string welcomeBooksHtml; for ( itr = booksIds.begin(); itr != booksIds.end(); ++itr ) { libraryManager.getBookById(*itr, currentBook); - if (!currentBook.path.empty()) { + if (!currentBook.path.empty() && readers.find(currentBook.getHumanReadableIdFromPath()) != readers.end()) { welcomeBooksHtml += "

" + currentBook.title + "

\ \ \