From 083406a85ded6e0285c3bb42f0dc1ddffc0b31a1 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 3 Mar 2025 11:07:40 -0600 Subject: [PATCH] portal configuration --- repertory/repertory/include/ui/handlers.hpp | 6 ++-- repertory/repertory/src/ui/handlers.cpp | 37 ++++++++++++++------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/repertory/repertory/include/ui/handlers.hpp b/repertory/repertory/include/ui/handlers.hpp index 7ef260f0..437db1f0 100644 --- a/repertory/repertory/include/ui/handlers.hpp +++ b/repertory/repertory/include/ui/handlers.hpp @@ -42,6 +42,7 @@ public: private: mgmt_app_config *config_; + std::string repertory_binary_; httplib::Server *server_; private: @@ -60,9 +61,8 @@ private: void handle_put_set_value_by_name(auto &&req, auto &&res); - static auto read_process(provider_type prov, std::string_view name, - std::string_view command) - -> std::vector; + auto read_process(provider_type prov, std::string_view name, + std::string_view command) const -> std::vector; }; } // namespace repertory::ui diff --git a/repertory/repertory/src/ui/handlers.cpp b/repertory/repertory/src/ui/handlers.cpp index 0e391e78..392d8875 100644 --- a/repertory/repertory/src/ui/handlers.cpp +++ b/repertory/repertory/src/ui/handlers.cpp @@ -33,7 +33,13 @@ namespace repertory::ui { handlers::handlers(mgmt_app_config *config, httplib::Server *server) - : config_(config), server_(server) { + : config_(config), +#if defined(_WIN32) + repertory_binary_(utils::path::combine(".", {"repertory.exe"})), +#else // !defined(_WIN32) + repertory_binary_(utils::path::combine(".", {"repertory"})), +#endif // defined(_WIN32) + server_(server) { REPERTORY_USES_FUNCTION_NAME(); server_->set_pre_routing_handler( @@ -232,10 +238,9 @@ void handlers::handle_get_mount_status(auto &&req, auto &&res) const { auto lines = handlers::read_process(prov, name, "-status"); - nlohmann::json result{ - nlohmann::json::parse(utils::string::join(lines, '\n')).at(status_name), - }; - if (result["Location"].empty()) { + nlohmann::json result( + nlohmann::json::parse(utils::string::join(lines, '\n')).at(status_name)); + if (result["Location"].get().empty()) { result["Location"] = config_->get_mount_location(prov, name); } else { config_->set_mount_location(prov, name, @@ -280,7 +285,7 @@ void handlers::handle_put_set_value_by_name(auto &&req, auto &&res) { } auto handlers::read_process(provider_type prov, std::string_view name, - std::string_view command) + std::string_view command) const -> std::vector { REPERTORY_USES_FUNCTION_NAME(); @@ -304,17 +309,25 @@ auto handlers::read_process(provider_type prov, std::string_view name, break; default: - throw utils::error::create_exception( - function_name, { - fmt::format("`{}` is not supported", name), - }); + throw utils::error::create_exception(function_name, + { + "provider is not supported", + provider_type_to_string(prov), + name, + }); } - auto cmd_line = fmt::format("repertory {} {}", str_type, command); + auto cmd_line = + fmt::format(R"("{}" {} {})", repertory_binary_, str_type, command); auto *pipe = popen(cmd_line.c_str(), "r"); if (pipe == nullptr) { - return {}; + throw utils::error::create_exception(function_name, + { + "failed to execute command", + provider_type_to_string(prov), + name, + }); } std::string data;