25 Commits

Author SHA1 Message Date
2017897ad6 refactor
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
2024-12-16 15:14:19 -06:00
0d7e6284bc refactor 2024-12-16 15:13:35 -06:00
77d985a483 fix encrypt provider start 2024-12-16 14:56:41 -06:00
f68de677c6 fix encrypt provider start 2024-12-16 14:55:41 -06:00
9d00a87851 fix encrypt provider start 2024-12-16 14:54:59 -06:00
4aebc2502d refactor 2024-12-16 14:31:12 -06:00
f1ca91faf1 refactor 2024-12-16 14:25:16 -06:00
fd1ec1c853 refactor encrypt provider db 2024-12-16 14:24:04 -06:00
575dbcd7f1 refactor encrypt provider db 2024-12-16 13:54:24 -06:00
c420ff1c81 refactor encrypt provider db 2024-12-16 13:52:15 -06:00
9af77225f2 refactor 2024-12-16 10:34:30 -06:00
dbf4a58807 refactor 2024-12-16 10:33:25 -06:00
6b58a0e0f7 refactor 2024-12-16 10:31:46 -06:00
7f044442bc refactor 2024-12-16 10:31:10 -06:00
35e6993629 refactor 2024-12-16 10:30:09 -06:00
f82fbf9b55 refactor 2024-12-16 10:26:31 -06:00
5fcb182cb8 refactor 2024-12-16 10:24:05 -06:00
6fc0085292 refactor 2024-12-16 10:22:49 -06:00
3cee38bf92 refactor 2024-12-16 10:21:54 -06:00
f85d0bd333 refactor 2024-12-16 10:17:42 -06:00
bf66bff7b4 refactor 2024-12-16 09:56:46 -06:00
f5668c82a7 updated build system 2024-12-16 09:53:01 -06:00
595d638ee0 boost 1.87.0 changes 2024-12-16 09:50:34 -06:00
e3bf579fd3 updated build system 2024-12-16 09:05:21 -06:00
fd137cad90 fix 2024-12-16 08:14:10 -06:00
16 changed files with 253 additions and 252 deletions

View File

@ -1,5 +1,5 @@
set(BINUTILS_HASH ae9a5789e23459e59606e6714723f2d3ffc31c03174191ef0d015bdf06007450) set(BINUTILS_HASH ae9a5789e23459e59606e6714723f2d3ffc31c03174191ef0d015bdf06007450)
set(BOOST_HASH 2575e74ffc3ef1cd0babac2c1ee8bdb5782a0ee672b1912da40e5b4b591ca01f) set(BOOST_HASH f55c340aa49763b1925ccf02b2e83f35fdcf634c9d5164a2acb87540173c741d)
set(BOOST2_HASH 7bd7ddceec1a1dfdcbdb3e609b60d01739c38390a5f956385a12f3122049f0ca) set(BOOST2_HASH 7bd7ddceec1a1dfdcbdb3e609b60d01739c38390a5f956385a12f3122049f0ca)
set(CPP_HTTPLIB_HASH 405abd8170f2a446fc8612ac635d0db5947c0d2e156e32603403a4496255ff00) set(CPP_HTTPLIB_HASH 405abd8170f2a446fc8612ac635d0db5947c0d2e156e32603403a4496255ff00)
set(CURL_HASH 5a231145114589491fc52da118f9c7ef8abee885d1cb1ced99c7290e9a352f07) set(CURL_HASH 5a231145114589491fc52da118f9c7ef8abee885d1cb1ced99c7290e9a352f07)

View File

@ -31,4 +31,4 @@ if(PROJECT_ENABLE_ROCKSDB)
list(APPEND PROJECT_DEPENDENCIES rocksdb_project) list(APPEND PROJECT_DEPENDENCIES rocksdb_project)
endif() endif()
endif() endif()

View File

@ -1,6 +1,6 @@
set(BINUTILS_VERSION 2.41) set(BINUTILS_VERSION 2.41)
set(BOOST_MAJOR_VERSION 1) set(BOOST_MAJOR_VERSION 1)
set(BOOST_MINOR_VERSION 86) set(BOOST_MINOR_VERSION 87)
set(BOOST_PATCH_VERSION 0) set(BOOST_PATCH_VERSION 0)
set(BOOST2_MAJOR_VERSION 1) set(BOOST2_MAJOR_VERSION 1)
set(BOOST2_MINOR_VERSION 76) set(BOOST2_MINOR_VERSION 76)

View File

@ -52,23 +52,23 @@ public:
~packet() = default; ~packet() = default;
private: private:
data_buffer buffer_; data_buffer buffer_{};
std::size_t decode_offset_ = 0U; std::size_t decode_offset_{0U};
public: public:
[[nodiscard]] static auto decode_json(packet &response, [[nodiscard]] static auto decode_json(packet &response, json &json_data)
json &json_data) -> int; -> int;
public: public:
void clear(); void clear();
[[nodiscard]] auto current_pointer() -> unsigned char * { [[nodiscard]] auto current_pointer() -> unsigned char * {
return (decode_offset_ < buffer_.size()) ? &buffer_[decode_offset_] return (decode_offset_ < buffer_.size()) ? &buffer_.at(decode_offset_)
: nullptr; : nullptr;
} }
[[nodiscard]] auto current_pointer() const -> const unsigned char * { [[nodiscard]] auto current_pointer() const -> const unsigned char * {
return (decode_offset_ < buffer_.size()) ? &buffer_[decode_offset_] return (decode_offset_ < buffer_.size()) ? &buffer_.at(decode_offset_)
: nullptr; : nullptr;
} }
@ -206,7 +206,7 @@ public:
return static_cast<std::uint32_t>(buffer_.size()); return static_cast<std::uint32_t>(buffer_.size());
} }
void transfer_into(data_buffer &buffer); void to_buffer(data_buffer &buffer);
public: public:
auto operator=(const data_buffer &buffer) noexcept -> packet &; auto operator=(const data_buffer &buffer) noexcept -> packet &;
@ -226,8 +226,6 @@ public:
return buffer_.at(index); return buffer_.at(index);
} }
}; };
using packet = packet;
} // namespace repertory } // namespace repertory
#endif // REPERTORY_INCLUDE_COMM_PACKET_PACKET_HPP_ #endif // REPERTORY_INCLUDE_COMM_PACKET_PACKET_HPP_

View File

@ -52,8 +52,8 @@ public:
private: private:
struct connection { struct connection {
connection(boost::asio::io_service &io_service, tcp::acceptor &acceptor_) connection(io_context &ctx, tcp::acceptor &acceptor_)
: socket(io_service), acceptor(acceptor_) {} : socket(ctx), acceptor(acceptor_) {}
tcp::socket socket; tcp::socket socket;
tcp::acceptor &acceptor; tcp::acceptor &acceptor;
@ -68,7 +68,7 @@ private:
std::string encryption_token_; std::string encryption_token_;
closed_callback closed_; closed_callback closed_;
message_handler_callback message_handler_; message_handler_callback message_handler_;
boost::asio::io_context io_context_; io_context io_context_;
std::unique_ptr<std::thread> server_thread_; std::unique_ptr<std::thread> server_thread_;
std::vector<std::thread> service_threads_; std::vector<std::thread> service_threads_;
std::recursive_mutex connection_mutex_; std::recursive_mutex connection_mutex_;

View File

@ -35,7 +35,7 @@ public:
public: public:
explicit encrypt_provider(app_config &config); explicit encrypt_provider(app_config &config);
~encrypt_provider() override; ~encrypt_provider() override = default;
public: public:
encrypt_provider(const encrypt_provider &) = delete; encrypt_provider(const encrypt_provider &) = delete;

View File

@ -30,7 +30,7 @@ namespace repertory {
void client_pool::pool::execute( void client_pool::pool::execute(
std::uint64_t thread_id, const worker_callback &worker, std::uint64_t thread_id, const worker_callback &worker,
const worker_complete_callback &worker_complete) { const worker_complete_callback &worker_complete) {
const auto index = thread_id % pool_queues_.size(); auto index = thread_id % pool_queues_.size();
auto job = std::make_shared<work_item>(worker, worker_complete); auto job = std::make_shared<work_item>(worker, worker_complete);
auto &pool_queue = pool_queues_[index]; auto &pool_queue = pool_queues_[index];
@ -51,7 +51,7 @@ client_pool::pool::pool(std::uint8_t pool_size) {
for (std::size_t i = 0U; i < pool_queues_.size(); i++) { for (std::size_t i = 0U; i < pool_queues_.size(); i++) {
pool_threads_.emplace_back([this]() { pool_threads_.emplace_back([this]() {
const auto thread_index = thread_index_++; auto thread_index = thread_index_++;
auto &pool_queue = pool_queues_[thread_index]; auto &pool_queue = pool_queues_[thread_index];
auto &queue = pool_queue->queue; auto &queue = pool_queue->queue;
@ -74,7 +74,7 @@ client_pool::pool::pool(std::uint8_t pool_size) {
queue_lock.unlock(); queue_lock.unlock();
try { try {
const auto result = item->work(); auto result = item->work();
item->work_complete(result); item->work_complete(result);
} catch (const std::exception &e) { } catch (const std::exception &e) {
item->work_complete(utils::from_api_error(api_error::error)); item->work_complete(utils::from_api_error(api_error::error));

View File

@ -36,8 +36,8 @@ void packet::clear() {
} }
auto packet::decode(std::string &data) -> packet::error_type { auto packet::decode(std::string &data) -> packet::error_type {
const auto *str = reinterpret_cast<const char *>(&buffer_[decode_offset_]); const auto *str = reinterpret_cast<const char *>(&buffer_.at(decode_offset_));
const auto length = strnlen(str, buffer_.size() - decode_offset_); auto length = strnlen(str, buffer_.size() - decode_offset_);
data = std::string(str, length); data = std::string(str, length);
decode_offset_ += (length + 1); decode_offset_ += (length + 1);
@ -46,7 +46,7 @@ auto packet::decode(std::string &data) -> packet::error_type {
auto packet::decode(std::wstring &data) -> packet::error_type { auto packet::decode(std::wstring &data) -> packet::error_type {
std::string utf8_string; std::string utf8_string;
const auto ret = decode(utf8_string); auto ret = decode(utf8_string);
if (ret == 0) { if (ret == 0) {
data = utils::string::from_utf8(utf8_string); data = utils::string::from_utf8(utf8_string);
} }
@ -60,7 +60,7 @@ auto packet::decode(void *&ptr) -> packet::error_type {
auto packet::decode(void *buffer, std::size_t size) -> packet::error_type { auto packet::decode(void *buffer, std::size_t size) -> packet::error_type {
if (size != 0U) { if (size != 0U) {
const auto read_size = auto read_size =
utils::calculate_read_size(buffer_.size(), size, decode_offset_); utils::calculate_read_size(buffer_.size(), size, decode_offset_);
if (read_size == size) { if (read_size == size) {
memcpy(buffer, &buffer_[decode_offset_], size); memcpy(buffer, &buffer_[decode_offset_], size);
@ -76,7 +76,7 @@ auto packet::decode(void *buffer, std::size_t size) -> packet::error_type {
} }
auto packet::decode(std::int8_t &val) -> packet::error_type { auto packet::decode(std::int8_t &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val); boost::endian::big_to_native_inplace(val);
} }
@ -84,7 +84,7 @@ auto packet::decode(std::int8_t &val) -> packet::error_type {
} }
auto packet::decode(std::uint8_t &val) -> packet::error_type { auto packet::decode(std::uint8_t &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val); boost::endian::big_to_native_inplace(val);
} }
@ -92,7 +92,7 @@ auto packet::decode(std::uint8_t &val) -> packet::error_type {
} }
auto packet::decode(std::int16_t &val) -> packet::error_type { auto packet::decode(std::int16_t &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val); boost::endian::big_to_native_inplace(val);
} }
@ -100,7 +100,7 @@ auto packet::decode(std::int16_t &val) -> packet::error_type {
} }
auto packet::decode(std::uint16_t &val) -> packet::error_type { auto packet::decode(std::uint16_t &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val); boost::endian::big_to_native_inplace(val);
} }
@ -108,7 +108,7 @@ auto packet::decode(std::uint16_t &val) -> packet::error_type {
} }
auto packet::decode(std::int32_t &val) -> packet::error_type { auto packet::decode(std::int32_t &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val); boost::endian::big_to_native_inplace(val);
} }
@ -116,7 +116,7 @@ auto packet::decode(std::int32_t &val) -> packet::error_type {
} }
auto packet::decode(std::uint32_t &val) -> packet::error_type { auto packet::decode(std::uint32_t &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val); boost::endian::big_to_native_inplace(val);
} }
@ -124,7 +124,7 @@ auto packet::decode(std::uint32_t &val) -> packet::error_type {
} }
auto packet::decode(std::int64_t &val) -> packet::error_type { auto packet::decode(std::int64_t &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val); boost::endian::big_to_native_inplace(val);
} }
@ -132,7 +132,7 @@ auto packet::decode(std::int64_t &val) -> packet::error_type {
} }
auto packet::decode(std::uint64_t &val) -> packet::error_type { auto packet::decode(std::uint64_t &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val); boost::endian::big_to_native_inplace(val);
} }
@ -140,7 +140,7 @@ auto packet::decode(std::uint64_t &val) -> packet::error_type {
} }
auto packet::decode(remote::setattr_x &val) -> packet::error_type { auto packet::decode(remote::setattr_x &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val.acctime); boost::endian::big_to_native_inplace(val.acctime);
boost::endian::big_to_native_inplace(val.bkuptime); boost::endian::big_to_native_inplace(val.bkuptime);
@ -159,7 +159,7 @@ auto packet::decode(remote::setattr_x &val) -> packet::error_type {
} }
auto packet::decode(remote::stat &val) -> packet::error_type { auto packet::decode(remote::stat &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val.st_mode); boost::endian::big_to_native_inplace(val.st_mode);
boost::endian::big_to_native_inplace(val.st_nlink); boost::endian::big_to_native_inplace(val.st_nlink);
@ -179,7 +179,7 @@ auto packet::decode(remote::stat &val) -> packet::error_type {
} }
auto packet::decode(remote::statfs &val) -> packet::error_type { auto packet::decode(remote::statfs &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val.f_bavail); boost::endian::big_to_native_inplace(val.f_bavail);
boost::endian::big_to_native_inplace(val.f_bfree); boost::endian::big_to_native_inplace(val.f_bfree);
@ -200,7 +200,7 @@ auto packet::decode(remote::statfs_x &val) -> packet::error_type {
} }
auto packet::decode(remote::file_info &val) -> packet::error_type { auto packet::decode(remote::file_info &val) -> packet::error_type {
const auto ret = decode(&val, sizeof(val)); auto ret = decode(&val, sizeof(val));
if (ret == 0) { if (ret == 0) {
boost::endian::big_to_native_inplace(val.AllocationSize); boost::endian::big_to_native_inplace(val.AllocationSize);
boost::endian::big_to_native_inplace(val.ChangeTime); boost::endian::big_to_native_inplace(val.ChangeTime);
@ -268,7 +268,7 @@ void packet::encode(const void *buffer, std::size_t size, bool should_reserve) {
} }
void packet::encode(std::string_view str) { void packet::encode(std::string_view str) {
const auto len = str.size(); auto len = str.size();
buffer_.reserve(len + 1 + buffer_.size()); buffer_.reserve(len + 1 + buffer_.size());
encode(str.data(), len, false); encode(str.data(), len, false);
buffer_.emplace_back(0); buffer_.emplace_back(0);
@ -401,7 +401,7 @@ void packet::encode_top(const void *buffer, std::size_t size,
} }
void packet::encode_top(std::string_view str) { void packet::encode_top(std::string_view str) {
const auto len = str.size(); auto len = str.size();
buffer_.reserve(len + 1U + buffer_.size()); buffer_.reserve(len + 1U + buffer_.size());
encode_top(str.data(), len, false); encode_top(str.data(), len, false);
buffer_.insert(buffer_.begin() + static_cast<std::int32_t>(len), 0); buffer_.insert(buffer_.begin() + static_cast<std::int32_t>(len), 0);
@ -531,7 +531,7 @@ void packet::encrypt(std::string_view token) {
} }
} }
void packet::transfer_into(data_buffer &buffer) { void packet::to_buffer(data_buffer &buffer) {
buffer = std::move(buffer_); buffer = std::move(buffer_);
buffer_ = data_buffer(); buffer_ = data_buffer();
decode_offset_ = 0; decode_offset_ = 0;

View File

@ -85,7 +85,7 @@ void packet_client::connect(client &cli) {
cli.socket.set_option(boost::asio::socket_base::linger(false, 0)); cli.socket.set_option(boost::asio::socket_base::linger(false, 0));
packet response; packet response;
const auto res = read_packet(cli, response); auto res = read_packet(cli, response);
if (res != 0) { if (res != 0) {
throw std::runtime_error(std::to_string(res)); throw std::runtime_error(std::to_string(res));
} }
@ -95,22 +95,22 @@ void packet_client::connect(client &cli) {
} }
auto packet_client::get_client() -> std::shared_ptr<packet_client::client> { auto packet_client::get_client() -> std::shared_ptr<packet_client::client> {
std::shared_ptr<client> ret;
unique_mutex_lock clients_lock(clients_mutex_); unique_mutex_lock clients_lock(clients_mutex_);
if (allow_connections_) { if (not allow_connections_) {
if (clients_.empty()) { return nullptr;
clients_lock.unlock();
ret = std::make_shared<client>(io_context_);
connect(*ret);
} else {
ret = clients_[0U];
utils::collection::remove_element(clients_, ret);
clients_lock.unlock();
}
} }
return ret; if (clients_.empty()) {
clients_lock.unlock();
auto cli = std::make_shared<client>(io_context_);
connect(*cli);
return cli;
}
auto cli = clients_.at(0U);
utils::collection::remove_element(clients_, cli);
return cli;
} }
void packet_client::put_client(std::shared_ptr<client> &cli) { void packet_client::put_client(std::shared_ptr<client> &cli) {
@ -126,7 +126,7 @@ auto packet_client::read_packet(client &cli, packet &response)
const auto read_buffer = [&]() { const auto read_buffer = [&]() {
std::uint32_t offset{}; std::uint32_t offset{};
while (offset < buffer.size()) { while (offset < buffer.size()) {
const auto bytes_read = boost::asio::read( auto bytes_read = boost::asio::read(
cli.socket, cli.socket,
boost::asio::buffer(&buffer[offset], buffer.size() - offset)); boost::asio::buffer(&buffer[offset], buffer.size() - offset));
if (bytes_read <= 0) { if (bytes_read <= 0) {
@ -137,7 +137,7 @@ auto packet_client::read_packet(client &cli, packet &response)
}; };
read_buffer(); read_buffer();
const auto size = boost::endian::big_to_native( auto size = boost::endian::big_to_native(
*reinterpret_cast<std::uint32_t *>(buffer.data())); *reinterpret_cast<std::uint32_t *>(buffer.data()));
buffer.resize(size); buffer.resize(size);
@ -153,10 +153,12 @@ auto packet_client::read_packet(client &cli, packet &response)
} }
void packet_client::resolve() { void packet_client::resolve() {
if (resolve_results_.empty()) { if (not resolve_results_.empty()) {
resolve_results_ = tcp::resolver(io_context_) return;
.resolve({host_name_or_ip_, std::to_string(port_)});
} }
resolve_results_ = tcp::resolver(io_context_)
.resolve(host_name_or_ip_, std::to_string(port_));
} }
auto packet_client::send(std::string_view method, std::uint32_t &service_flags) auto packet_client::send(std::string_view method, std::uint32_t &service_flags)
@ -184,7 +186,7 @@ auto packet_client::send(std::string_view method, packet &request,
request.encode_top(PACKET_SERVICE_FLAGS); request.encode_top(PACKET_SERVICE_FLAGS);
request.encode_top(std::string{project_get_version()}); request.encode_top(std::string{project_get_version()});
static const std::uint8_t max_attempts{5U}; static constexpr const std::uint8_t max_attempts{5U};
for (std::uint8_t i = 1U; for (std::uint8_t i = 1U;
allow_connections_ && not success && (i <= max_attempts); i++) { allow_connections_ && not success && (i <= max_attempts); i++) {
auto current_client = get_client(); auto current_client = get_client();
@ -203,7 +205,7 @@ auto packet_client::send(std::string_view method, packet &request,
std::uint32_t offset{}; std::uint32_t offset{};
while (offset < request.get_size()) { while (offset < request.get_size()) {
const auto bytes_written = boost::asio::write( auto bytes_written = boost::asio::write(
current_client->socket, current_client->socket,
boost::asio::buffer(&request[offset], boost::asio::buffer(&request[offset],
request.get_size() - offset)); request.get_size() - offset));

View File

@ -72,7 +72,7 @@ void packet_server::initialize(const uint16_t &port, uint8_t pool_size) {
server_thread_ = std::make_unique<std::thread>([this, port, pool_size]() { server_thread_ = std::make_unique<std::thread>([this, port, pool_size]() {
tcp::acceptor acceptor(io_context_); tcp::acceptor acceptor(io_context_);
try { try {
const auto endpoint = tcp::endpoint(tcp::v4(), port); auto endpoint = tcp::endpoint(tcp::v4(), port);
acceptor.open(endpoint.protocol()); acceptor.open(endpoint.protocol());
acceptor.set_option(socket_base::reuse_address(true)); acceptor.set_option(socket_base::reuse_address(true));
acceptor.bind(endpoint); acceptor.bind(endpoint);
@ -148,7 +148,7 @@ void packet_server::read_packet(std::shared_ptr<connection> conn,
const auto read_buffer = [&]() { const auto read_buffer = [&]() {
std::uint32_t offset{}; std::uint32_t offset{};
while (offset < conn->buffer.size()) { while (offset < conn->buffer.size()) {
const auto bytes_read = boost::asio::read( auto bytes_read = boost::asio::read(
conn->socket, boost::asio::buffer(&conn->buffer[offset], conn->socket, boost::asio::buffer(&conn->buffer[offset],
conn->buffer.size() - offset)); conn->buffer.size() - offset));
if (bytes_read <= 0) { if (bytes_read <= 0) {
@ -244,7 +244,7 @@ void packet_server::send_response(std::shared_ptr<connection> conn,
response.encode_top(PACKET_SERVICE_FLAGS); response.encode_top(PACKET_SERVICE_FLAGS);
response.encode_top(conn->nonce); response.encode_top(conn->nonce);
response.encrypt(encryption_token_); response.encrypt(encryption_token_);
response.transfer_into(conn->buffer); response.to_buffer(conn->buffer);
boost::asio::async_write( boost::asio::async_write(
conn->socket, boost::asio::buffer(conn->buffer), conn->socket, boost::asio::buffer(conn->buffer),

View File

@ -24,6 +24,7 @@
#include "events/event_system.hpp" #include "events/event_system.hpp"
#include "events/events.hpp" #include "events/events.hpp"
#include "types/repertory.hpp" #include "types/repertory.hpp"
#include "types/startup_exception.hpp"
#include "utils/collection.hpp" #include "utils/collection.hpp"
#include "utils/db/sqlite/db_common.hpp" #include "utils/db/sqlite/db_common.hpp"
#include "utils/db/sqlite/db_delete.hpp" #include "utils/db/sqlite/db_delete.hpp"
@ -36,42 +37,28 @@
#include "utils/polling.hpp" #include "utils/polling.hpp"
namespace { namespace {
const std::string directory_table = "directory";
const std::string file_table = "file"; const std::string file_table = "file";
const std::string source_table = "source";
const std::map<std::string, std::string> sql_create_tables = { const std::map<std::string, std::string> sql_create_tables = {
{
{directory_table},
{"CREATE TABLE IF NOT EXISTS " + directory_table +
"("
"source_path TEXT PRIMARY KEY ASC, "
"api_path TEXT"
");"},
},
{ {
{file_table}, {file_table},
{"CREATE TABLE IF NOT EXISTS " + file_table + {"CREATE TABLE IF NOT EXISTS " + file_table +
"(" "("
"source_path TEXT PRIMARY KEY ASC, " "source_path TEXT PRIMARY KEY ASC, "
"data TEXT" "api_path TEXT NOT NULL, "
"data TEXT, "
"directory INTEGER NOT NULL"
");"}, ");"},
}, },
{ };
{source_table},
{"CREATE TABLE IF NOT EXISTS " + source_table +
"("
"api_path TEXT PRIMARY KEY ASC, "
"source_path TEXT"
");"},
}};
} // namespace } // namespace
namespace repertory { namespace repertory {
encrypt_provider::encrypt_provider(app_config &config) : config_(config) {} encrypt_provider::encrypt_provider(app_config &config) : config_(config) {}
auto encrypt_provider::create_api_file( auto encrypt_provider::create_api_file(const std::string &api_path,
const std::string &api_path, bool directory, bool directory,
const std::string &source_path) -> api_file { const std::string &source_path)
-> api_file {
auto times = utils::file::get_times(source_path); auto times = utils::file::get_times(source_path);
if (not times.has_value()) { if (not times.has_value()) {
throw std::runtime_error("failed to get file times"); throw std::runtime_error("failed to get file times");
@ -97,10 +84,10 @@ auto encrypt_provider::create_api_file(
void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory, void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory,
const api_file &file) { const api_file &file) {
#if defined(_WIN32) #if defined(_WIN32)
struct _stat64 buf {}; struct _stat64 buf{};
_stat64(file.source_path.c_str(), &buf); _stat64(file.source_path.c_str(), &buf);
#else // !defined(_WIN32) #else // !defined(_WIN32)
struct stat buf {}; struct stat buf{};
stat(file.source_path.c_str(), &buf); stat(file.source_path.c_str(), &buf);
#endif // defined(_WIN32) #endif // defined(_WIN32)
@ -159,11 +146,7 @@ auto encrypt_provider::do_fs_operation(
: api_error::item_not_found; : api_error::item_not_found;
} }
auto exists = auto exists = utils::file::file{source_path}.exists();
utils::file::file{
source_path,
}
.exists();
if (exists && directory) { if (exists && directory) {
return api_error::item_exists; return api_error::item_exists;
} }
@ -171,11 +154,7 @@ auto encrypt_provider::do_fs_operation(
return api_error::item_not_found; return api_error::item_not_found;
} }
exists = exists = utils::file::directory{source_path}.exists();
utils::file::directory{
source_path,
}
.exists();
if (exists && not directory) { if (exists && not directory) {
return api_error::item_exists; return api_error::item_exists;
} }
@ -187,38 +166,24 @@ auto encrypt_provider::do_fs_operation(
return callback(cfg, source_path); return callback(cfg, source_path);
} }
auto encrypt_provider::get_api_path_from_source( auto encrypt_provider::get_api_path_from_source(const std::string &source_path,
const std::string &source_path, std::string &api_path) const -> api_error { std::string &api_path) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
auto result = utils::db::sqlite::db_select{*db_, file_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("data") .column("api_path")
.where("source_path") .where("source_path")
.equals(source_path) .equals(source_path)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (result.get_row(row) && row.has_value()) {
api_path = row->get_column("data")
.get_value_as_json()
.at("api_path")
.get<std::string>();
return api_error::success;
}
result = utils::db::sqlite::db_select{*db_, directory_table}
.column("api_path")
.where("source_path")
.equals(source_path)
.go();
row.reset();
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
api_path = row->get_column("api_path").get_value<std::string>(); api_path = row->get_column("api_path").get_value<std::string>();
return api_error::success; return api_error::success;
} }
return api_error::item_not_found; return api_error::item_not_found;
} catch (const std::exception &ex) { } catch (const std::exception &ex) {
utils::error::raise_error(function_name, ex, source_path, utils::error::raise_error(function_name, ex, source_path,
"failed to get api path from source path"); "failed to get api path from source path");
@ -253,8 +218,9 @@ auto encrypt_provider::get_directory_item_count(
return count; return count;
} }
auto encrypt_provider::get_directory_items( auto encrypt_provider::get_directory_items(const std::string &api_path,
const std::string &api_path, directory_item_list &list) const -> api_error { directory_item_list &list) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
return do_fs_operation( return do_fs_operation(
@ -262,17 +228,19 @@ auto encrypt_provider::get_directory_items(
[this, &list](const encrypt_config &cfg, [this, &list](const encrypt_config &cfg,
const std::string &source_path) -> api_error { const std::string &source_path) -> api_error {
try { try {
for (auto &&dir_entry : for (const auto &dir_entry :
utils::file::directory{source_path}.get_items()) { utils::file::directory{source_path}.get_items()) {
try { try {
std::string current_api_path{}; std::string current_api_path{};
if (dir_entry->is_directory_item()) { if (dir_entry->is_directory_item()) {
auto result = auto result = utils::db::sqlite::db_select{*db_, file_table}
utils::db::sqlite::db_select{*db_, directory_table} .column("api_path")
.column("api_path") .where("source_path")
.where("source_path") .equals(dir_entry->get_path())
.equals(dir_entry->get_path()) .and_()
.go(); .where("directory")
.equals(1)
.go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
current_api_path = current_api_path =
@ -282,10 +250,13 @@ auto encrypt_provider::get_directory_items(
process_directory_entry(*dir_entry.get(), cfg, process_directory_entry(*dir_entry.get(), cfg,
current_api_path); current_api_path);
result = utils::db::sqlite::db_select{*db_, directory_table} result = utils::db::sqlite::db_select{*db_, file_table}
.column("api_path") .column("api_path")
.where("source_path") .where("source_path")
.equals(dir_entry->get_path()) .equals(dir_entry->get_path())
.and_()
.where("directory")
.equals(1)
.go(); .go();
row.reset(); row.reset();
if (not(result.get_row(row) && row.has_value())) { if (not(result.get_row(row) && row.has_value())) {
@ -298,25 +269,26 @@ auto encrypt_provider::get_directory_items(
} else { } else {
std::string api_path_data{}; std::string api_path_data{};
auto result = utils::db::sqlite::db_select{*db_, file_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("api_path")
.column("data") .column("data")
.where("source_path") .where("source_path")
.equals(dir_entry->get_path()) .equals(dir_entry->get_path())
.and_()
.where("directory")
.equals(0)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
api_path_data = api_path_data =
row->get_column("data").get_value<std::string>(); row->get_column("data").get_value<std::string>();
current_api_path =
row->get_column("api_path").get_value<std::string>();
} }
if (api_path_data.empty()) { if (api_path_data.empty() &&
if (not process_directory_entry(*dir_entry.get(), cfg, not process_directory_entry(*dir_entry.get(), cfg,
current_api_path)) { current_api_path)) {
continue; continue;
}
} else {
current_api_path = json::parse(api_path_data)
.at("api_path")
.get<std::string>();
} }
} }
@ -356,11 +328,15 @@ auto encrypt_provider::get_directory_items(
"..", "..",
"", "",
true, true,
0U,
{},
}); });
list.insert(list.begin(), directory_item{ list.insert(list.begin(), directory_item{
".", ".",
"", "",
true, true,
0U,
{},
}); });
return api_error::success; return api_error::success;
}); });
@ -380,10 +356,13 @@ auto encrypt_provider::get_file(const std::string &api_path,
return api_error::directory_exists; return api_error::directory_exists;
} }
auto result = utils::db::sqlite::db_select{*db_, source_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("source_path") .column("source_path")
.where("api_path") .where("api_path")
.equals(api_path) .equals(api_path)
.and_()
.where("directory")
.equals(0)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (not(result.get_row(row) && row.has_value())) { if (not(result.get_row(row) && row.has_value())) {
@ -402,14 +381,15 @@ auto encrypt_provider::get_file(const std::string &api_path,
return api_error::error; return api_error::error;
} }
auto encrypt_provider::get_file_list( auto encrypt_provider::get_file_list(api_file_list &list,
api_file_list &list, std::string & /* marker */) const -> api_error { std::string & /* marker */) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto cfg = config_.get_encrypt_config(); auto cfg = config_.get_encrypt_config();
try { try {
for (auto &&dir_entry : utils::file::directory{cfg.path}.get_items()) { for (const auto &dir_entry : utils::file::directory{cfg.path}.get_items()) {
std::string api_path{}; std::string api_path{};
if (process_directory_entry(*dir_entry.get(), cfg, api_path)) { if (process_directory_entry(*dir_entry.get(), cfg, api_path)) {
list.emplace_back(create_api_file( list.emplace_back(create_api_file(
@ -426,15 +406,19 @@ auto encrypt_provider::get_file_list(
return api_error::error; return api_error::error;
} }
auto encrypt_provider::get_file_size( auto encrypt_provider::get_file_size(const std::string &api_path,
const std::string &api_path, std::uint64_t &file_size) const -> api_error { std::uint64_t &file_size) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
auto result = utils::db::sqlite::db_select{*db_, source_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("source_path") .column("source_path")
.where("api_path") .where("api_path")
.equals(api_path) .equals(api_path)
.and_()
.where("directory")
.equals(0)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (not(result.get_row(row) && row.has_value())) { if (not(result.get_row(row) && row.has_value())) {
@ -453,26 +437,34 @@ auto encrypt_provider::get_file_size(
return api_error::error; return api_error::error;
} }
auto encrypt_provider::get_filesystem_item( auto encrypt_provider::get_filesystem_item(const std::string &api_path,
const std::string &api_path, bool directory, bool directory,
filesystem_item &fsi) const -> api_error { filesystem_item &fsi) const
auto result = utils::db::sqlite::db_select{*db_, source_table} -> api_error {
auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("source_path") .column("source_path")
.where("api_path") .where("api_path")
.equals(api_path) .equals(api_path)
.and_()
.where("directory")
.equals(directory ? 1 : 0)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (not(result.get_row(row) && row.has_value())) { if (not(result.get_row(row) && row.has_value())) {
return api_error::item_not_found; return directory ? api_error::directory_not_found
: api_error::item_not_found;
} }
auto source_path = row->get_column("source_path").get_value<std::string>(); auto source_path = row->get_column("source_path").get_value<std::string>();
if (directory) { if (directory) {
result = utils::db::sqlite::db_select{*db_, directory_table} result = utils::db::sqlite::db_select{*db_, file_table}
.column("api_path") .column("api_path")
.where("source_path") .where("source_path")
.equals(source_path) .equals(source_path)
.and_()
.where("directory")
.equals(1)
.go(); .go();
row.reset(); row.reset();
if (not(result.get_row(row) && row.has_value())) { if (not(result.get_row(row) && row.has_value())) {
@ -489,19 +481,20 @@ auto encrypt_provider::get_filesystem_item(
} }
result = utils::db::sqlite::db_select{*db_, file_table} result = utils::db::sqlite::db_select{*db_, file_table}
.column("api_path")
.column("data") .column("data")
.where("source_path") .where("source_path")
.equals(source_path) .equals(source_path)
.and_()
.where("directory")
.equals(0)
.go(); .go();
row.reset(); row.reset();
if (not(result.get_row(row) && row.has_value())) { if (not(result.get_row(row) && row.has_value())) {
return api_error::item_not_found; return api_error::item_not_found;
} }
fsi.api_path = row->get_column("data") fsi.api_path = row->get_column("api_path").get_value<std::string>();
.get_value_as_json()
.at("api_path")
.get<std::string>();
fsi.api_parent = utils::path::get_parent_api_path(fsi.api_path); fsi.api_parent = utils::path::get_parent_api_path(fsi.api_path);
fsi.directory = false; fsi.directory = false;
fsi.size = utils::encryption::encrypting_reader::calculate_encrypted_size( fsi.size = utils::encryption::encrypting_reader::calculate_encrypted_size(
@ -531,9 +524,10 @@ auto encrypt_provider::get_filesystem_item_from_source_path(
return get_filesystem_item(api_path, false, fsi); return get_filesystem_item(api_path, false, fsi);
} }
auto encrypt_provider::get_filesystem_item_and_file( auto encrypt_provider::get_filesystem_item_and_file(const std::string &api_path,
const std::string &api_path, api_file &file, api_file &file,
filesystem_item &fsi) const -> api_error { filesystem_item &fsi) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -570,7 +564,7 @@ auto encrypt_provider::get_item_meta(const std::string &api_path,
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
auto result = utils::db::sqlite::db_select{*db_, source_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("source_path") .column("source_path")
.where("api_path") .where("api_path")
.equals(api_path) .equals(api_path)
@ -619,7 +613,7 @@ auto encrypt_provider::get_total_drive_space() const -> std::uint64_t {
} }
auto encrypt_provider::get_total_item_count() const -> std::uint64_t { auto encrypt_provider::get_total_item_count() const -> std::uint64_t {
auto result = utils::db::sqlite::db_select{*db_, source_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.count("api_path", "count") .count("api_path", "count")
.go(); .go();
@ -641,10 +635,13 @@ auto encrypt_provider::get_used_drive_space() const -> std::uint64_t {
auto encrypt_provider::is_directory(const std::string &api_path, auto encrypt_provider::is_directory(const std::string &api_path,
bool &exists) const -> api_error { bool &exists) const -> api_error {
auto result = utils::db::sqlite::db_select{*db_, source_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("source_path") .column("source_path")
.where("api_path") .where("api_path")
.equals(api_path) .equals(api_path)
.and_()
.where("directory")
.equals(1)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (not(result.get_row(row) && row.has_value())) { if (not(result.get_row(row) && row.has_value())) {
@ -660,12 +657,15 @@ auto encrypt_provider::is_directory(const std::string &api_path,
return api_error::success; return api_error::success;
} }
auto encrypt_provider::is_file(const std::string &api_path, auto encrypt_provider::is_file(const std::string &api_path, bool &exists) const
bool &exists) const -> api_error { -> api_error {
auto result = utils::db::sqlite::db_select{*db_, source_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("source_path") .column("source_path")
.where("api_path") .where("api_path")
.equals(api_path) .equals(api_path)
.and_()
.where("directory")
.equals(0)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (not(result.get_row(row) && row.has_value())) { if (not(result.get_row(row) && row.has_value())) {
@ -718,14 +718,17 @@ auto encrypt_provider::process_directory_entry(
std::size_t current_idx{1U}; std::size_t current_idx{1U};
std::string current_encrypted_path{}; std::string current_encrypted_path{};
auto current_source_path{cfg.path}; auto current_source_path{cfg.path};
for (auto &&part : utils::path::get_parts(dir_path)) { for (const auto &part : utils::path::get_parts(dir_path)) {
current_source_path = utils::path::combine(current_source_path, {part}); current_source_path = utils::path::combine(current_source_path, {part});
std::string current_api_path{}; std::string current_api_path{};
auto result = utils::db::sqlite::db_select{*db_, directory_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("api_path") .column("api_path")
.where("source_path") .where("source_path")
.equals(current_source_path) .equals(current_source_path)
.and_()
.where("directory")
.equals(1)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
@ -736,16 +739,13 @@ auto encrypt_provider::process_directory_entry(
current_api_path = utils::path::create_api_path( current_api_path = utils::path::create_api_path(
current_encrypted_path + '/' + encrypted_parts.at(current_idx)); current_encrypted_path + '/' + encrypted_parts.at(current_idx));
auto ins_res = utils::db::sqlite::db_insert{*db_, directory_table} // TODO handle error
.column_value("source_path", current_source_path) auto ins_res = utils::db::sqlite::db_insert{*db_, file_table}
.column_value("api_path", current_api_path) .column_value("api_path", current_api_path)
.column_value("data", "")
.column_value("directory", 1)
.column_value("source_path", current_source_path)
.go(); .go();
// TODO handle error
ins_res = utils::db::sqlite::db_insert{*db_, source_table}
.column_value("api_path", current_api_path)
.column_value("source_path", current_source_path)
.go();
// TODO handle error
event_system::instance().raise<filesystem_item_added>( event_system::instance().raise<filesystem_item_added>(
current_api_path, current_api_path,
utils::path::get_parent_api_path(current_api_path), true); utils::path::get_parent_api_path(current_api_path), true);
@ -773,20 +773,28 @@ auto encrypt_provider::process_directory_entry(
std::string api_path_data{}; std::string api_path_data{};
auto result = utils::db::sqlite::db_select{*db_, file_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("api_path")
.column("data") .column("data")
.where("source_path") .where("source_path")
.equals(dir_entry.get_path()) .equals(dir_entry.get_path())
.and_()
.where("directory")
.equals(0)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
api_path_data = row->get_column("data").get_value<std::string>(); api_path_data = row->get_column("data").get_value<std::string>();
api_path = row->get_column("api_path").get_value<std::string>();
} }
std::string api_parent{}; std::string api_parent{};
result = utils::db::sqlite::db_select{*db_, directory_table} result = utils::db::sqlite::db_select{*db_, file_table}
.column("api_path") .column("api_path")
.where("source_path") .where("source_path")
.equals(utils::path::get_parent_path(dir_entry.get_path())) .equals(utils::path::get_parent_path(dir_entry.get_path()))
.and_()
.where("directory")
.equals(1)
.go(); .go();
row.reset(); row.reset();
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
@ -797,7 +805,7 @@ auto encrypt_provider::process_directory_entry(
api_parent = add_directory(utils::path::get_parent_path(relative_path)); api_parent = add_directory(utils::path::get_parent_path(relative_path));
} }
if (api_path_data.empty()) { if (api_path.empty()) {
stop_type stop_requested = false; stop_type stop_requested = false;
utils::encryption::encrypting_reader reader( utils::encryption::encrypting_reader reader(
utils::path::strip_to_file_name(relative_path), dir_entry.get_path(), utils::path::strip_to_file_name(relative_path), dir_entry.get_path(),
@ -808,7 +816,6 @@ auto encrypt_provider::process_directory_entry(
auto iv_list = reader.get_iv_list(); auto iv_list = reader.get_iv_list();
json data = { json data = {
{"api_path", api_path},
{"iv_list", iv_list}, {"iv_list", iv_list},
{ {
"original_file_size", "original_file_size",
@ -817,21 +824,17 @@ auto encrypt_provider::process_directory_entry(
.value_or(0U)), .value_or(0U)),
}, },
}; };
auto ins_res = utils::db::sqlite::db_insert{*db_, file_table}
.column_value("source_path", dir_entry.get_path())
.column_value("data", data.dump())
.go();
// TODO handle error
ins_res = utils::db::sqlite::db_insert{*db_, source_table}
.column_value("api_path", api_path)
.column_value("source_path", dir_entry.get_path())
.go();
// TODO handle error // TODO handle error
auto ins_res = utils::db::sqlite::db_insert{*db_, file_table}
.column_value("api_path", api_path)
.column_value("data", data.dump())
.column_value("directory", 0)
.column_value("source_path", dir_entry.get_path())
.go();
event_system::instance().raise<filesystem_item_added>(api_path, event_system::instance().raise<filesystem_item_added>(api_path,
api_parent, false); api_parent, false);
} else {
api_path = json::parse(api_path_data)["api_path"].get<std::string>();
} }
return true; return true;
@ -846,10 +849,14 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
stop_type &stop_requested) -> api_error { stop_type &stop_requested) -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto result = utils::db::sqlite::db_select{*db_, source_table} auto result = utils::db::sqlite::db_select{*db_, file_table}
.column("data")
.column("source_path") .column("source_path")
.where("api_path") .where("api_path")
.equals(api_path) .equals(api_path)
.and_()
.where("directory")
.equals(0)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (not(result.get_row(row) && row.has_value())) { if (not(result.get_row(row) && row.has_value())) {
@ -861,16 +868,6 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
return api_error::item_not_found; return api_error::item_not_found;
} }
result = utils::db::sqlite::db_select{*db_, file_table}
.column("data")
.where("source_path")
.equals(source_path)
.go();
row.reset();
if (not(result.get_row(row) && row.has_value())) {
return api_error::item_not_found;
}
auto file_data = row->get_column("data").get_value_as_json(); auto file_data = row->get_column("data").get_value_as_json();
auto opt_size = utils::file::file{source_path}.size(); auto opt_size = utils::file::file{source_path}.size();
@ -884,7 +881,7 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>> std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
iv_list{}; iv_list{};
const auto cfg = config_.get_encrypt_config(); auto cfg = config_.get_encrypt_config();
unique_recur_mutex_lock reader_lookup_lock(reader_lookup_mtx_); unique_recur_mutex_lock reader_lookup_lock(reader_lookup_mtx_);
@ -902,8 +899,8 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
file_data["iv_list"] = iv_list; file_data["iv_list"] = iv_list;
auto ins_res = utils::db::sqlite::db_insert{*db_, file_table} auto ins_res = utils::db::sqlite::db_insert{*db_, file_table}
.or_replace() .or_replace()
.column_value("source_path", source_path)
.column_value("data", file_data.dump()) .column_value("data", file_data.dump())
.column_value("source_path", source_path)
.go(); .go();
if (not ins_res.ok()) { if (not ins_res.ok()) {
utils::error::raise_error(function_name, ins_res.get_error(), source_path, utils::error::raise_error(function_name, ins_res.get_error(), source_path,
@ -937,7 +934,7 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
info->reader->set_read_position(offset); info->reader->set_read_position(offset);
data.resize(size); data.resize(size);
const auto res = auto res =
info->reader->reader_function(reinterpret_cast<char *>(data.data()), 1U, info->reader->reader_function(reinterpret_cast<char *>(data.data()), 1U,
data.size(), info->reader.get()); data.size(), info->reader.get());
if (res == 0) { if (res == 0) {
@ -957,7 +954,7 @@ void encrypt_provider::remove_deleted_files(const stop_type &stop_requested) {
std::vector<removed_item> removed_list{}; std::vector<removed_item> removed_list{};
std::vector<utils::db::sqlite::db_result::row> row_list{}; std::vector<utils::db::sqlite::db_result::row> row_list{};
auto result = utils::db::sqlite::db_select{*db_, source_table}.go(); auto result = utils::db::sqlite::db_select{*db_, file_table}.go();
while (result.has_row()) { while (result.has_row()) {
if (stop_requested) { if (stop_requested) {
return; return;
@ -969,7 +966,7 @@ void encrypt_provider::remove_deleted_files(const stop_type &stop_requested) {
} }
} }
for (auto &&row : row_list) { for (const auto &row : row_list) {
if (stop_requested) { if (stop_requested) {
return; return;
} }
@ -982,12 +979,15 @@ void encrypt_provider::remove_deleted_files(const stop_type &stop_requested) {
.where("source_path") .where("source_path")
.equals(source_path) .equals(source_path)
.go(); .go();
removed_list.emplace_back( removed_list.emplace_back(removed_item{
removed_item{api_path, not result.has_row(), source_path}); api_path,
row.get_column("directory").get_value<std::int64_t>() == 1,
source_path,
});
} }
} }
for (auto &&item : removed_list) { for (const auto &item : removed_list) {
if (stop_requested) { if (stop_requested) {
return; return;
} }
@ -996,21 +996,19 @@ void encrypt_provider::remove_deleted_files(const stop_type &stop_requested) {
continue; continue;
} }
auto del_res = utils::db::sqlite::db_delete{*db_, source_table} // TODO handle error
.where("api_path") auto del_res = utils::db::sqlite::db_delete{*db_, file_table}
.equals(item.api_path) .where("source_path")
.equals(item.source_path)
.and_()
.where("directory")
.equals(0)
.go(); .go();
// TODO handle error
del_res = utils::db::sqlite::db_delete{*db_, file_table}
.where("source_path")
.equals(item.source_path)
.go();
// TODO handle error
event_system::instance().raise<file_removed_externally>(item.api_path, event_system::instance().raise<file_removed_externally>(item.api_path,
item.source_path); item.source_path);
} }
for (auto &&item : removed_list) { for (const auto &item : removed_list) {
if (stop_requested) { if (stop_requested) {
return; return;
} }
@ -1018,17 +1016,15 @@ void encrypt_provider::remove_deleted_files(const stop_type &stop_requested) {
if (not item.directory) { if (not item.directory) {
continue; continue;
} }
auto del_res = utils::db::sqlite::db_delete{*db_, source_table}
.where("api_path") // TODO handle error
.equals(item.api_path) auto del_res = utils::db::sqlite::db_delete{*db_, file_table}
.where("source_path")
.equals(item.source_path)
.and_()
.where("directory")
.equals(1)
.go(); .go();
// TODO handle error
del_res = utils::db::sqlite::db_delete{*db_, directory_table}
.where("source_path")
.equals(item.source_path)
.go();
// TODO handle error
event_system::instance().raise<directory_removed_externally>( event_system::instance().raise<directory_removed_externally>(
item.api_path, item.source_path); item.api_path, item.source_path);
} }
@ -1043,40 +1039,45 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
} }
db_ = utils::db::sqlite::create_db( db_ = utils::db::sqlite::create_db(
utils::path::combine(config_.get_data_directory(), {"meta.db"}), utils::path::combine(config_.get_data_directory(), {"provider_meta.db"}),
sql_create_tables); sql_create_tables);
const auto cfg = config_.get_encrypt_config(); auto cfg = config_.get_encrypt_config();
auto cfg_path = utils::path::absolute(cfg.path);
std::string source_path; auto result = utils::db::sqlite::db_select{*db_, file_table}
auto result = utils::db::sqlite::db_select{*db_, source_table}
.column("source_path") .column("source_path")
.where("api_path") .where("source_path")
.equals("/") .equals(cfg_path)
.and_()
.where("directory")
.equals(1)
.go(); .go();
std::optional<utils::db::sqlite::db_result::row> row; std::optional<utils::db::sqlite::db_result::row> row;
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
source_path = row->get_column("source_path").get_value<std::string>(); auto cur_path = utils::path::absolute(
row->get_column("source_path").get_value<std::string>());
#if defined(_WIN32)
if (utils::string::to_lower(cur_path) !=
utils::string::to_lower(cfg_path)) {
#else //! defined(_WIN32)
if (cur_path != cfg_path) {
#endif // defined(_WIN32)
throw startup_exception(fmt::format(
"source path has changed|cur|{}|cfg|{}", cur_path, cfg.path));
}
} else { } else {
auto ins_res = utils::db::sqlite::db_insert{*db_, source_table} auto ins_res = utils::db::sqlite::db_insert{*db_, file_table}
.column_value("api_path", "/") .column_value("api_path", "/")
.column_value("source_path", cfg.path) .column_value("data", "")
.column_value("directory", 1)
.column_value("source_path", cfg_path)
.go(); .go();
// TODO error handling if (not ins_res.ok()) {
source_path = cfg.path; throw startup_exception(fmt::format("failed to create root|{}|{}",
} ins_res.get_error(),
ins_res.get_error_str()));
result = utils::db::sqlite::db_select{*db_, directory_table} }
.column("api_path")
.where("source_path")
.equals(source_path)
.go();
if (not result.has_row()) {
auto ins_res = utils::db::sqlite::db_insert{*db_, directory_table}
.column_value("source_path", source_path)
.column_value("api_path", "/")
.go();
// TODO error handling
} }
polling::instance().set_callback({ polling::instance().set_callback({

View File

@ -6,7 +6,7 @@ PROJECT_VERSIONS[BOOST2_MAJOR]="1"
PROJECT_VERSIONS[BOOST2_MINOR]="76" PROJECT_VERSIONS[BOOST2_MINOR]="76"
PROJECT_VERSIONS[BOOST2_PATCH]="0" PROJECT_VERSIONS[BOOST2_PATCH]="0"
PROJECT_VERSIONS[BOOST_MAJOR]="1" PROJECT_VERSIONS[BOOST_MAJOR]="1"
PROJECT_VERSIONS[BOOST_MINOR]="86" PROJECT_VERSIONS[BOOST_MINOR]="87"
PROJECT_VERSIONS[BOOST_PATCH]="0" PROJECT_VERSIONS[BOOST_PATCH]="0"
PROJECT_VERSIONS[CPP_HTTPLIB]="0.18.1" PROJECT_VERSIONS[CPP_HTTPLIB]="0.18.1"
PROJECT_VERSIONS[CURL]="8.11.0" PROJECT_VERSIONS[CURL]="8.11.0"

View File

@ -1 +0,0 @@
2575e74ffc3ef1cd0babac2c1ee8bdb5782a0ee672b1912da40e5b4b591ca01f *boost_1_86_0.tar.gz

View File

@ -0,0 +1 @@
f55c340aa49763b1925ccf02b2e83f35fdcf634c9d5164a2acb87540173c741d *boost_1_87_0.tar.gz

View File

@ -25,8 +25,8 @@
#include "utils/string.hpp" #include "utils/string.hpp"
namespace repertory::utils { namespace repertory::utils {
auto compare_version_strings(std::string version1, auto compare_version_strings(std::string version1, std::string version2)
std::string version2) -> std::int32_t { -> std::int32_t {
if (utils::string::contains(version1, "-")) { if (utils::string::contains(version1, "-")) {
version1 = utils::string::split(version1, '-', true)[0U]; version1 = utils::string::split(version1, '-', true)[0U];
@ -132,8 +132,8 @@ auto get_next_available_port(std::uint16_t first_port,
boost::system::error_code error_code{}; boost::system::error_code error_code{};
while (first_port != 0U) { while (first_port != 0U) {
io_service svc{}; io_context ctx{};
tcp::acceptor acceptor(svc); tcp::acceptor acceptor(ctx);
acceptor.open(tcp::v4(), error_code) || acceptor.open(tcp::v4(), error_code) ||
acceptor.bind({tcp::v4(), first_port}, error_code); acceptor.bind({tcp::v4(), first_port}, error_code);
if (not error_code) { if (not error_code) {