From 417749a3fc73329ebc2f2249f1543e43c5631039 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Tue, 19 Apr 2011 06:29:19 +0000 Subject: [PATCH] + 2nd regression fix --- src/server/kiwix-serve.cpp | 64 ++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index be60be6..b43b28e 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -416,33 +416,6 @@ int main(int argc, char **argv) { /* Instanciate the ZIM index (if necessary) */ if (indexPath != "") { - /* Change the current dir to binary dir */ - /* Non portable linux solution */ - readlink("/proc/self/exe", rootPath, PATH_MAX); - chdir(dirname(rootPath)); - - /* Try to load the result template */ - try { - fstream templateStream; - templateStream.open("../share/kiwix/static/results.tmpl", ifstream::in); - - if (templateStream.fail()) { - templateStream.open("../../static/results.tmpl", ifstream::in); - - if (templateStream.fail()) { - throw "Unable to find a result template file."; - } else { - realpath("../../static/results.tmpl", rootPath); - searcher->setResultTemplatePath(rootPath); - } - } else { - realpath("../share/kiwix/static/results.tmpl", rootPath); - searcher->setResultTemplatePath(rootPath); - } - } catch (...) { - cerr << "Unable to open the result template file." << endl; - exit(1); - } /* Try with the XapianSearcher */ try { @@ -463,9 +436,40 @@ int main(int argc, char **argv) { } } - /* searcher configuration */ - searcher->setProtocolPrefix("/"); - searcher->setSearchProtocolPrefix("/search?"); + /* searcher configuration */ + if (hasSearchIndex) { + + /* Change the current dir to binary dir */ + /* Non portable linux solution */ + readlink("/proc/self/exe", rootPath, PATH_MAX); + chdir(dirname(rootPath)); + + /* Try to load the result template */ + try { + fstream templateStream; + templateStream.open("../share/kiwix/static/results.tmpl", ifstream::in); + + if (templateStream.fail()) { + templateStream.open("../../static/results.tmpl", ifstream::in); + + if (templateStream.fail()) { + throw "Unable to find a result template file."; + } else { + realpath("../../static/results.tmpl", rootPath); + searcher->setResultTemplatePath(rootPath); + } + } else { + realpath("../share/kiwix/static/results.tmpl", rootPath); + searcher->setResultTemplatePath(rootPath); + } + } catch (...) { + cerr << "Unable to open the result template file." << endl; + exit(1); + } + + searcher->setProtocolPrefix("/"); + searcher->setSearchProtocolPrefix("/search?"); + } } else { hasSearchIndex = false;