Compare commits
2 Commits
69c574b906
...
7605be809c
Author | SHA1 | Date | |
---|---|---|---|
7605be809c | |||
d0f2f78698 |
@ -23,6 +23,7 @@
|
|||||||
#define REPERTORY_INCLUDE_UI_HANDLERS_HPP_
|
#define REPERTORY_INCLUDE_UI_HANDLERS_HPP_
|
||||||
|
|
||||||
#include "events/consumers/console_consumer.hpp"
|
#include "events/consumers/console_consumer.hpp"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace repertory::ui {
|
namespace repertory::ui {
|
||||||
class mgmt_app_config;
|
class mgmt_app_config;
|
||||||
@ -48,11 +49,11 @@ private:
|
|||||||
private:
|
private:
|
||||||
console_consumer console;
|
console_consumer console;
|
||||||
mutable std::mutex mtx_;
|
mutable std::mutex mtx_;
|
||||||
|
mutable std::unordered_map<std::string, std::recursive_mutex> mtx_lookup_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] static auto data_directory_exists(provider_type prov,
|
[[nodiscard]] auto data_directory_exists(provider_type prov,
|
||||||
std::string_view name)
|
std::string_view name) const -> bool;
|
||||||
-> bool;
|
|
||||||
|
|
||||||
void handle_get_mount(auto &&req, auto &&res) const;
|
void handle_get_mount(auto &&req, auto &&res) const;
|
||||||
|
|
||||||
|
@ -150,14 +150,23 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
|||||||
|
|
||||||
handlers::~handlers() { event_system::instance().stop(); }
|
handlers::~handlers() { event_system::instance().stop(); }
|
||||||
|
|
||||||
auto handlers::data_directory_exists(provider_type prov, std::string_view name)
|
auto handlers::data_directory_exists(provider_type prov,
|
||||||
-> bool {
|
std::string_view name) const -> bool {
|
||||||
auto data_dir = utils::path::combine(app_config::get_root_data_directory(),
|
auto data_dir = utils::path::combine(app_config::get_root_data_directory(),
|
||||||
{
|
{
|
||||||
app_config::get_provider_name(prov),
|
app_config::get_provider_name(prov),
|
||||||
name,
|
name,
|
||||||
});
|
});
|
||||||
return utils::file::directory{data_dir}.exists();
|
auto ret = utils::file::directory{data_dir}.exists();
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
unique_mutex_lock lock(mtx_);
|
||||||
|
mtx_lookup_.erase(
|
||||||
|
fmt::format("{}-{}", name, app_config::get_provider_name(prov)));
|
||||||
|
lock.unlock();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handlers::handle_get_mount(auto &&req, auto &&res) const {
|
void handlers::handle_get_mount(auto &&req, auto &&res) const {
|
||||||
@ -323,6 +332,10 @@ void handlers::handle_post_mount(auto &&req, auto &&res) const {
|
|||||||
if (unmount) {
|
if (unmount) {
|
||||||
launch_process(prov, name, "-unmount");
|
launch_process(prov, name, "-unmount");
|
||||||
} else {
|
} else {
|
||||||
|
if (not utils::file::directory{location}.exists()) {
|
||||||
|
res.status = http_error_codes::internal_error;
|
||||||
|
}
|
||||||
|
|
||||||
launch_process(prov, name, fmt::format(R"("{}")", location), true);
|
launch_process(prov, name, fmt::format(R"("{}")", location), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +401,12 @@ auto handlers::launch_process(provider_type prov, std::string_view name,
|
|||||||
|
|
||||||
auto cmd_line = fmt::format(R"({} {} {})", repertory_binary_, str_type, args);
|
auto cmd_line = fmt::format(R"({} {} {})", repertory_binary_, str_type, args);
|
||||||
|
|
||||||
mutex_lock lock(mtx_);
|
unique_mutex_lock lock(mtx_);
|
||||||
|
auto &inst_mtx = mtx_lookup_[fmt::format(
|
||||||
|
"{}-{}", name, app_config::get_provider_name(prov))];
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
|
recur_mutex_lock inst_lock(inst_mtx);
|
||||||
if (background) {
|
if (background) {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
system(fmt::format(R"(start "" /b {})", cmd_line).c_str());
|
system(fmt::format(R"(start "" /b {})", cmd_line).c_str());
|
||||||
|
@ -127,6 +127,8 @@ List<Validator> getSettingValidators(String settingPath) {
|
|||||||
return createHostNameOrIpValidators();
|
return createHostNameOrIpValidators();
|
||||||
case 'HostConfig.Protocol':
|
case 'HostConfig.Protocol':
|
||||||
return [(value) => constants.protocolTypeList.contains(value)];
|
return [(value) => constants.protocolTypeList.contains(value)];
|
||||||
|
case 'Path':
|
||||||
|
return [trimNotEmptyValidator];
|
||||||
case 'RemoteConfig.ApiPort':
|
case 'RemoteConfig.ApiPort':
|
||||||
return [notEmptyValidator, portIsValid];
|
return [notEmptyValidator, portIsValid];
|
||||||
case 'RemoteConfig.EncryptionToken':
|
case 'RemoteConfig.EncryptionToken':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user