extract common behavior
This commit is contained in:
parent
edb1297c4a
commit
80f6e3c272
@ -95,6 +95,9 @@ protected:
|
|||||||
return fm_;
|
return fm_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] virtual auto get_used_drive_space_impl() const
|
||||||
|
-> std::uint64_t = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual auto remove_directory_impl(const std::string &api_path)
|
[[nodiscard]] virtual auto remove_directory_impl(const std::string &api_path)
|
||||||
-> api_error = 0;
|
-> api_error = 0;
|
||||||
|
|
||||||
@ -159,6 +162,8 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override;
|
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override;
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override;
|
||||||
|
|
||||||
[[nodiscard]] auto is_file_writeable(const std::string &api_path) const
|
[[nodiscard]] auto is_file_writeable(const std::string &api_path) const
|
||||||
-> bool override;
|
-> bool override;
|
||||||
|
|
||||||
|
@ -80,6 +80,9 @@ protected:
|
|||||||
directory_item_list &list) const
|
directory_item_list &list) const
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_used_drive_space_impl() const
|
||||||
|
-> std::uint64_t override;
|
||||||
|
|
||||||
[[nodiscard]] auto remove_directory_impl(const std::string &api_path)
|
[[nodiscard]] auto remove_directory_impl(const std::string &api_path)
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
|
||||||
@ -107,8 +110,6 @@ public:
|
|||||||
return provider_type::s3;
|
return provider_type::s3;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override;
|
|
||||||
|
|
||||||
[[nodiscard]] auto is_direct_only() const -> bool override { return false; }
|
[[nodiscard]] auto is_direct_only() const -> bool override { return false; }
|
||||||
|
|
||||||
[[nodiscard]] auto is_directory(const std::string &api_path,
|
[[nodiscard]] auto is_directory(const std::string &api_path,
|
||||||
|
@ -58,6 +58,9 @@ protected:
|
|||||||
directory_item_list &list) const
|
directory_item_list &list) const
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_used_drive_space_impl() const
|
||||||
|
-> std::uint64_t override;
|
||||||
|
|
||||||
[[nodiscard]] auto remove_directory_impl(const std::string &api_path)
|
[[nodiscard]] auto remove_directory_impl(const std::string &api_path)
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
|
||||||
@ -85,8 +88,6 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override;
|
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override;
|
|
||||||
|
|
||||||
[[nodiscard]] auto is_direct_only() const -> bool override { return false; }
|
[[nodiscard]] auto is_direct_only() const -> bool override { return false; }
|
||||||
|
|
||||||
[[nodiscard]] auto is_directory(const std::string &api_path,
|
[[nodiscard]] auto is_directory(const std::string &api_path,
|
||||||
|
@ -460,6 +460,19 @@ auto base_provider::get_total_item_count() const -> std::uint64_t {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto base_provider::get_used_drive_space() const -> std::uint64_t {
|
||||||
|
try {
|
||||||
|
auto used_space = get_used_drive_space_impl();
|
||||||
|
get_file_mgr()->update_used_space(used_space);
|
||||||
|
return used_space;
|
||||||
|
} catch (const std::exception &ex) {
|
||||||
|
utils::error::raise_error(__FUNCTION__, ex,
|
||||||
|
"failed to get used drive space");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
|
||||||
auto base_provider::is_file_writeable(const std::string &api_path) const
|
auto base_provider::is_file_writeable(const std::string &api_path) const
|
||||||
-> bool {
|
-> bool {
|
||||||
bool exists{};
|
bool exists{};
|
||||||
|
@ -539,7 +539,7 @@ auto s3_provider::get_total_drive_space() const -> std::uint64_t {
|
|||||||
return std::numeric_limits<std::int64_t>::max() / std::int64_t(2);
|
return std::numeric_limits<std::int64_t>::max() / std::int64_t(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto s3_provider::get_used_drive_space() const -> std::uint64_t {
|
auto s3_provider::get_used_drive_space_impl() const -> std::uint64_t {
|
||||||
std::string response_data;
|
std::string response_data;
|
||||||
long response_code{};
|
long response_code{};
|
||||||
if (not get_object_list(response_data, response_code)) {
|
if (not get_object_list(response_data, response_code)) {
|
||||||
|
@ -351,42 +351,32 @@ auto sia_provider::get_total_drive_space() const -> std::uint64_t {
|
|||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sia_provider::get_used_drive_space() const -> std::uint64_t {
|
auto sia_provider::get_used_drive_space_impl() const -> std::uint64_t {
|
||||||
// TODO adjust size based on open files
|
curl::requests::http_get get{};
|
||||||
try {
|
get.allow_timeout = true;
|
||||||
curl::requests::http_get get{};
|
get.path = "/api/bus/stats/objects";
|
||||||
get.allow_timeout = true;
|
|
||||||
get.path = "/api/bus/stats/objects";
|
|
||||||
|
|
||||||
json object_data{};
|
json object_data{};
|
||||||
get.response_handler = [&object_data](const data_buffer &data,
|
get.response_handler = [&object_data](const data_buffer &data,
|
||||||
long response_code) {
|
long response_code) {
|
||||||
if (response_code == http_error_codes::ok) {
|
if (response_code == http_error_codes::ok) {
|
||||||
object_data = nlohmann::json::parse(data.begin(), data.end());
|
object_data = nlohmann::json::parse(data.begin(), data.end());
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
long response_code{};
|
|
||||||
stop_type stop_requested{};
|
|
||||||
if (not get_comm().make_request(get, response_code, stop_requested)) {
|
|
||||||
return 0U;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (response_code != http_error_codes::ok) {
|
long response_code{};
|
||||||
utils::error::raise_error(__FUNCTION__, response_code,
|
stop_type stop_requested{};
|
||||||
"failed to get used drive space");
|
if (not get_comm().make_request(get, response_code, stop_requested)) {
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
|
||||||
|
|
||||||
auto used_space = object_data["totalObjectsSize"].get<std::uint64_t>();
|
|
||||||
get_file_mgr()->update_used_space(used_space);
|
|
||||||
return used_space;
|
|
||||||
} catch (const std::exception &ex) {
|
|
||||||
utils::error::raise_error(__FUNCTION__, ex,
|
|
||||||
"failed to get used drive space");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0U;
|
if (response_code != http_error_codes::ok) {
|
||||||
|
utils::error::raise_error(__FUNCTION__, response_code,
|
||||||
|
"failed to get used drive space");
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
return object_data["totalObjectsSize"].get<std::uint64_t>();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
|
auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user