Compare commits

..

No commits in common. "bf11906434ec9fe9c7d30f0a149a53435458fd8b" and "eaa95cf9d162a8947ccaedb4a66e5d7832203b5c" have entirely different histories.

2 changed files with 8 additions and 32 deletions

View File

@ -315,8 +315,6 @@ auto handlers::data_directory_exists(provider_type prov,
void handlers::generate_config(provider_type prov, std::string_view name,
const json &cfg,
std::optional<std::string> data_dir) const {
REPERTORY_USES_FUNCTION_NAME();
std::map<std::string, std::string> values{};
for (const auto &[key, value] : cfg.items()) {
if (value.is_object()) {
@ -344,13 +342,7 @@ void handlers::generate_config(provider_type prov, std::string_view name,
}
if (data_dir.has_value()) {
if (not utils::file::directory{data_dir.value()}.create_directory()) {
throw utils::error::create_exception(function_name,
{
"failed to create data diretory",
data_dir.value(),
});
}
utils::file::directory{data_dir.value()}.create_directory();
launch_process(prov, name, {"-dd", data_dir.value(), "-gc"});
} else {
launch_process(prov, name, {"-gc"});
@ -529,8 +521,6 @@ void handlers::handle_get_settings(httplib::Response &res) const {
void handlers::handle_get_test(const httplib::Request &req,
httplib::Response &res) const {
REPERTORY_USES_FUNCTION_NAME();
unique_mutex_lock lock(test_mtx_);
auto name = req.get_param_value("name");
@ -540,24 +530,13 @@ void handlers::handle_get_test(const httplib::Request &req,
auto data_dir = utils::path::combine(
utils::directory::temp(), {utils::file::create_temp_name("repertory")});
try {
generate_config(prov, name, cfg, data_dir);
generate_config(prov, name, cfg, data_dir);
auto lines = launch_process(prov, name, {"-dd", data_dir, "-test"});
res.status = lines.at(0U) == "0" ? http_error_codes::ok
: http_error_codes::internal_error;
} catch (const std::exception &e) {
utils::error::raise_error(function_name, e, "test provider config failed");
res.status = http_error_codes::internal_error;
}
auto lines = launch_process(prov, name, {"-dd", data_dir, "-test"});
res.status = lines.at(0U) == "0" ? http_error_codes::ok
: http_error_codes::internal_error;
if (utils::file::directory{data_dir}.remove_recursively()) {
return;
}
utils::error::raise_error(
function_name, e,
fmt::format("failed to remove data directory|{}", data_dir));
utils::file::directory{data_dir}.remove_recursively();
}
void handlers::handle_post_add_mount(const httplib::Request &req,
@ -572,6 +551,7 @@ void handlers::handle_post_add_mount(const httplib::Request &req,
auto cfg = nlohmann::json::parse(req.get_param_value("config"));
generate_config(prov, name, cfg);
launch_process(prov, name, {"-test"});
res.status = http_error_codes::ok;
}

View File

@ -285,15 +285,11 @@ class Mount with ChangeNotifier {
Future<bool> test() async {
try {
final map = await convertAllToString(
jsonDecode(jsonEncode(mountConfig.settings)),
_auth.key,
);
final auth = await _auth.createAuth();
final response = await http.get(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/test?auth=$auth&name=$name&type=$type&config=${jsonEncode(map)}',
'${getBaseUri()}/api/v1/test?auth=$auth&name=$name&type=$type&config=${jsonEncode(mountConfig.settings)}',
),
),
);