From e42e061d45763a8c691da8a86ef32bb0f6857b10 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 11 Sep 2019 11:30:59 +0200 Subject: [PATCH] Add a way to specify a library to use with kiwix-serve. If kiwix-desktop use a `library.xml` in the same directory than the executable, we need to use it instead of the default one. Instead of detect again the `library.xml` to use, let `kiwix-desktop` set the library to use. This also fix a issue when `/` is not a valid path separator in windows. --- include/kiwixserve.h | 4 +++- src/kiwixserve.cpp | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/kiwixserve.h b/include/kiwixserve.h index 54deb390b..dcf5a0642 100644 --- a/include/kiwixserve.h +++ b/include/kiwixserve.h @@ -2,6 +2,7 @@ #define KIWIXLIB_KIWIX_SERVE_H_ #include +#include class Subprocess; namespace kiwix { @@ -9,7 +10,7 @@ namespace kiwix { class KiwixServe { public: - KiwixServe(int port = 8181); + KiwixServe(const std::string& libraryPath, int port = 8181); ~KiwixServe(); void run(); @@ -20,6 +21,7 @@ class KiwixServe private: std::unique_ptr mp_kiwixServe; int m_port; + std::string m_libraryPath; }; }; //end namespace kiwix diff --git a/src/kiwixserve.cpp b/src/kiwixserve.cpp index c1dcdfbd6..1111fec17 100644 --- a/src/kiwixserve.cpp +++ b/src/kiwixserve.cpp @@ -14,7 +14,9 @@ namespace kiwix { -KiwixServe::KiwixServe(int port) : m_port(port) +KiwixServe::KiwixServe(const std::string& libraryPath, int port) + : m_port(port), + m_libraryPath(libraryPath) { } @@ -43,13 +45,12 @@ void KiwixServe::run() // Try to use a potential installed kiwix-serve. callCmd.push_back(KIWIXSERVE_CMD); } - std::string libraryPath = getDataDirectory() + "/library.xml"; std::string attachProcessOpt = "-a" + to_string(pid); std::string portOpt = "-p" + to_string(m_port); callCmd.push_back(attachProcessOpt.c_str()); callCmd.push_back(portOpt.c_str()); callCmd.push_back("-l"); - callCmd.push_back(libraryPath.c_str()); + callCmd.push_back(m_libraryPath.c_str()); mp_kiwixServe = Subprocess::run(callCmd); }