Compare commits

...

2 Commits

Author SHA1 Message Date
7605be809c per-instance locking
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
2025-03-15 18:25:03 -05:00
d0f2f78698 handle mount location not found 2025-03-15 18:14:21 -05:00
3 changed files with 28 additions and 7 deletions

View File

@ -23,6 +23,7 @@
#define REPERTORY_INCLUDE_UI_HANDLERS_HPP_
#include "events/consumers/console_consumer.hpp"
#include <unordered_map>
namespace repertory::ui {
class mgmt_app_config;
@ -48,11 +49,11 @@ private:
private:
console_consumer console;
mutable std::mutex mtx_;
mutable std::unordered_map<std::string, std::recursive_mutex> mtx_lookup_;
private:
[[nodiscard]] static auto data_directory_exists(provider_type prov,
std::string_view name)
-> bool;
[[nodiscard]] auto data_directory_exists(provider_type prov,
std::string_view name) const -> bool;
void handle_get_mount(auto &&req, auto &&res) const;

View File

@ -150,14 +150,23 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
handlers::~handlers() { event_system::instance().stop(); }
auto handlers::data_directory_exists(provider_type prov, std::string_view name)
-> bool {
auto handlers::data_directory_exists(provider_type prov,
std::string_view name) const -> bool {
auto data_dir = utils::path::combine(app_config::get_root_data_directory(),
{
app_config::get_provider_name(prov),
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 {
@ -323,6 +332,10 @@ void handlers::handle_post_mount(auto &&req, auto &&res) const {
if (unmount) {
launch_process(prov, name, "-unmount");
} else {
if (not utils::file::directory{location}.exists()) {
res.status = http_error_codes::internal_error;
}
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);
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 defined(_WIN32)
system(fmt::format(R"(start "" /b {})", cmd_line).c_str());

View File

@ -127,6 +127,8 @@ List<Validator> getSettingValidators(String settingPath) {
return createHostNameOrIpValidators();
case 'HostConfig.Protocol':
return [(value) => constants.protocolTypeList.contains(value)];
case 'Path':
return [trimNotEmptyValidator];
case 'RemoteConfig.ApiPort':
return [notEmptyValidator, portIsValid];
case 'RemoteConfig.EncryptionToken':