Address compiler warnings #10
All checks were successful
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good

This commit is contained in:
2023-11-08 19:53:12 -06:00
parent a7209184c8
commit f2c1f64f02
30 changed files with 737 additions and 615 deletions

View File

@ -32,9 +32,9 @@ class curl_comm final : public i_http_comm {
public:
curl_comm() = delete;
explicit curl_comm(host_config hc);
explicit curl_comm(host_config cfg);
explicit curl_comm(s3_config s3);
explicit curl_comm(s3_config cfg);
private:
using write_callback = size_t (*)(char *, size_t, size_t, void *);
@ -57,9 +57,10 @@ private:
public:
[[nodiscard]] static auto construct_url(CURL *curl,
const std::string &relative_path,
const host_config &hc) -> std::string;
const host_config &cfg)
-> std::string;
[[nodiscard]] static auto create_host_config(const s3_config &config,
[[nodiscard]] static auto create_host_config(const s3_config &cfg,
bool use_s3_path_style)
-> host_config;
@ -68,7 +69,7 @@ public:
template <typename request_type>
[[nodiscard]] static auto
make_encrypted_request(const host_config &hc, const request_type &request,
make_encrypted_request(const host_config &cfg, const request_type &request,
long &response_code, stop_type &stop_requested)
-> bool {
response_code = 0;
@ -102,7 +103,7 @@ public:
};
encrypted_request.total_size = std::nullopt;
if (not make_request(hc, encrypted_request, response_code,
if (not make_request(cfg, encrypted_request, response_code,
stop_requested)) {
return api_error::comm_error;
}
@ -127,11 +128,12 @@ public:
template <typename request_type>
[[nodiscard]] static auto
make_request(const host_config &hc, const request_type &request,
make_request(const host_config &cfg, const request_type &request,
long &response_code, stop_type &stop_requested) -> bool {
if (request.decryption_token.has_value() &&
not request.decryption_token.value().empty()) {
return make_encrypted_request(hc, request, response_code, stop_requested);
return make_encrypted_request(cfg, request, response_code,
stop_requested);
}
response_code = 0;
@ -141,12 +143,12 @@ public:
return false;
}
if (not hc.agent_string.empty()) {
curl_easy_setopt(curl, CURLOPT_USERAGENT, hc.agent_string.c_str());
if (not cfg.agent_string.empty()) {
curl_easy_setopt(curl, CURLOPT_USERAGENT, cfg.agent_string.c_str());
}
if (request.allow_timeout && hc.timeout_ms) {
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, hc.timeout_ms);
if (request.allow_timeout && cfg.timeout_ms) {
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, cfg.timeout_ms);
}
std::string range_list{};
@ -169,16 +171,16 @@ public:
}
std::string parameters{};
for (const auto &kv : request.query) {
parameters += (parameters.empty() ? '?' : '&') + kv.first + '=' +
url_encode(curl, kv.second, false);
for (const auto &param : request.query) {
parameters += (parameters.empty() ? '?' : '&') + param.first + '=' +
url_encode(curl, param.second, false);
}
if (not hc.api_password.empty()) {
curl_easy_setopt(curl, CURLOPT_USERNAME, hc.api_user.c_str());
curl_easy_setopt(curl, CURLOPT_PASSWORD, hc.api_password.c_str());
} else if (not hc.api_user.empty()) {
curl_easy_setopt(curl, CURLOPT_USERNAME, hc.api_user.c_str());
if (not cfg.api_password.empty()) {
curl_easy_setopt(curl, CURLOPT_USERNAME, cfg.api_user.c_str());
curl_easy_setopt(curl, CURLOPT_PASSWORD, cfg.api_password.c_str());
} else if (not cfg.api_user.empty()) {
curl_easy_setopt(curl, CURLOPT_USERNAME, cfg.api_user.c_str());
}
if (request.aws_service.has_value()) {
@ -186,7 +188,7 @@ public:
request.aws_service.value().c_str());
}
auto url = construct_url(curl, request.get_path(), hc) + parameters;
auto url = construct_url(curl, request.get_path(), cfg) + parameters;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
multi_request curl_request(curl, stop_requested);

View File

@ -26,6 +26,11 @@
namespace repertory::curl::requests {
struct http_get final : http_request_base {
http_get() = default;
http_get(const http_get &) = default;
http_get(http_get &&) = default;
auto operator=(const http_get &) -> http_get & = default;
auto operator=(http_get &&) -> http_get & = default;
~http_get() override = default;
[[nodiscard]] auto set_method(CURL *curl,

View File

@ -39,17 +39,23 @@ struct read_file_info final {
inline const auto read_file_data = static_cast<read_callback>(
[](char *buffer, size_t size, size_t nitems, void *instream) -> size_t {
auto *rd = reinterpret_cast<read_file_info *>(instream);
auto *read_info = reinterpret_cast<read_file_info *>(instream);
std::size_t bytes_read{};
auto ret =
rd->nf->read_bytes(buffer, size * nitems, rd->offset, bytes_read);
auto ret = read_info->nf->read_bytes(buffer, size * nitems,
read_info->offset, bytes_read);
if (ret) {
rd->offset += bytes_read;
read_info->offset += bytes_read;
}
return ret && not rd->stop_requested ? bytes_read : CURL_READFUNC_ABORT;
return ret && not read_info->stop_requested ? bytes_read
: CURL_READFUNC_ABORT;
});
struct http_request_base {
http_request_base() = default;
http_request_base(const http_request_base &) = default;
http_request_base(http_request_base &&) = default;
auto operator=(const http_request_base &) -> http_request_base & = default;
auto operator=(http_request_base &&) -> http_request_base & = default;
virtual ~http_request_base() = default;
bool allow_timeout{};

View File

@ -56,11 +56,17 @@ private:
~pool() { shutdown(); }
public:
pool(const pool &) = delete;
pool(pool &&) = delete;
auto operator=(const pool &) -> pool & = delete;
auto operator=(pool &&) -> pool & = delete;
private:
std::vector<std::unique_ptr<work_queue>> pool_queues_;
std::vector<std::thread> pool_threads_;
bool shutdown_ = false;
std::atomic<std::uint8_t> thread_index_;
bool shutdown_{false};
std::atomic<std::uint8_t> thread_index_{};
public:
void execute(std::uint64_t thread_id, const worker_callback &worker,
@ -70,17 +76,26 @@ private:
};
public:
explicit client_pool(std::uint8_t pool_size = 10u)
: pool_size_(pool_size ? pool_size : 10u) {}
explicit client_pool(std::uint8_t pool_size = min_pool_size)
: pool_size_(pool_size == 0U ? min_pool_size : pool_size) {}
~client_pool() { shutdown(); }
public:
client_pool(const client_pool &) = delete;
client_pool(client_pool &&) = delete;
auto operator=(const client_pool &) -> client_pool & = delete;
auto operator=(client_pool &&) -> client_pool & = delete;
private:
const std::uint8_t pool_size_;
std::uint8_t pool_size_;
std::unordered_map<std::string, std::shared_ptr<pool>> pool_lookup_;
std::mutex pool_mutex_;
bool shutdown_ = false;
private:
static constexpr const auto min_pool_size = 10U;
public:
void execute(const std::string &client_id, std::uint64_t thread_id,
const worker_callback &worker,

View File

@ -45,6 +45,13 @@ public:
~fuse_drive() override = default;
public:
fuse_drive(const fuse_drive &) = delete;
fuse_drive(fuse_drive &&) = delete;
auto operator=(const fuse_drive &) -> fuse_drive & = delete;
auto operator=(fuse_drive &&) -> fuse_drive & = delete;
private:
lock_data &lock_data_;
i_provider &provider_;
@ -69,7 +76,7 @@ protected:
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto chmod_impl(std::string api_path, mode_t mode,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#else
[[nodiscard]] auto chmod_impl(std::string api_path, mode_t mode)
@ -78,7 +85,7 @@ protected:
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto chown_impl(std::string api_path, uid_t uid, gid_t gid,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#else
[[nodiscard]] auto chown_impl(std::string api_path, uid_t uid, gid_t gid)
@ -86,40 +93,40 @@ protected:
#endif
[[nodiscard]] auto create_impl(std::string api_path, mode_t mode,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
void destroy_impl(void *ptr) override;
[[nodiscard]] auto fallocate_impl(std::string api_path, int mode,
off_t offset, off_t length,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
[[nodiscard]] auto fgetattr_impl(std::string api_path, struct stat *st,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#ifdef __APPLE__
[[nodiscard]] auto fsetattr_x_impl(std::string api_path,
struct setattr_x *attr,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#endif // __APPLE__
[[nodiscard]] auto fsync_impl(std::string api_path, int datasync,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#if FUSE_USE_VERSION < 30
[[nodiscard]] auto ftruncate_impl(std::string api_path, off_t size,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#endif
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *st,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#else
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *st)
@ -145,37 +152,38 @@ protected:
void notify_fuse_main_exit(int &ret) override;
[[nodiscard]] auto open_impl(std::string api_path, struct fuse_file_info *fi)
[[nodiscard]] auto open_impl(std::string api_path,
struct fuse_file_info *file_info)
-> api_error override;
[[nodiscard]] auto opendir_impl(std::string api_path,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
[[nodiscard]] auto read_impl(std::string api_path, char *buffer,
size_t read_size, off_t read_offset,
struct fuse_file_info *fi,
struct fuse_file_info *file_info,
std::size_t &bytes_read) -> api_error override;
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto readdir_impl(std::string api_path, void *buf,
fuse_fill_dir_t fuse_fill_dir, off_t offset,
struct fuse_file_info *fi,
struct fuse_file_info *file_info,
fuse_readdir_flags flags)
-> api_error override;
#else
[[nodiscard]] auto readdir_impl(std::string api_path, void *buf,
fuse_fill_dir_t fuse_fill_dir, off_t offset,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#endif
[[nodiscard]] auto release_impl(std::string api_path,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
[[nodiscard]] auto releasedir_impl(std::string api_path,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#if FUSE_USE_VERSION >= 30
@ -251,7 +259,7 @@ protected:
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto truncate_impl(std::string api_path, off_t size,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#else
[[nodiscard]] auto truncate_impl(std::string api_path, off_t size)
@ -263,7 +271,7 @@ protected:
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto utimens_impl(std::string api_path,
const struct timespec tv[2],
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#else
[[nodiscard]] auto utimens_impl(std::string api_path,
@ -273,7 +281,7 @@ protected:
[[nodiscard]] auto write_impl(std::string api_path, const char *buffer,
size_t write_size, off_t write_offset,
struct fuse_file_info *fi,
struct fuse_file_info *file_info,
std::size_t &bytes_written)
-> api_error override;
@ -308,7 +316,8 @@ public:
[[nodiscard]] auto is_processing(const std::string &api_path) const
-> bool override;
void populate_stat(const directory_item &di, struct stat &st) const override;
void populate_stat(const directory_item &dir_item,
struct stat &st) const override;
[[nodiscard]] auto rename_directory(const std::string &from_api_path,
const std::string &to_api_path)

View File

@ -69,7 +69,7 @@ public:
[[nodiscard]] virtual auto is_processing(const std::string &api_path) const
-> bool = 0;
virtual void populate_stat(const directory_item &di,
virtual void populate_stat(const directory_item &dir_item,
struct stat &st) const = 0;
[[nodiscard]] virtual auto rename_directory(const std::string &from_api_path,

View File

@ -237,12 +237,12 @@ public:
}
[[nodiscard]] auto json_create_directory_snapshot(const std::string &path,
json &jsonData)
json &json_data)
-> packet::error_type override;
[[nodiscard]] auto json_read_directory_snapshot(
const std::string &path, const remote::file_handle &handle,
std::uint32_t page, json &jsonData) -> packet::error_type override;
std::uint32_t page, json &json_data) -> packet::error_type override;
[[nodiscard]] auto
json_release_directory_snapshot(const std::string &path,
@ -254,7 +254,7 @@ public:
-> packet::error_type override;
[[nodiscard]] auto winfsp_cleanup(PVOID file_desc, PWSTR file_name,
UINT32 flags, BOOLEAN &wasClosed)
UINT32 flags, BOOLEAN &was_closed)
-> packet::error_type override;
[[nodiscard]] auto winfsp_close(PVOID file_desc)
@ -275,8 +275,8 @@ public:
[[nodiscard]] auto
winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
std::uint64_t * /*securityDescriptorSize*/,
std::wstring & /*strDescriptor*/)
std::uint64_t * /*security_descriptor_size*/,
std::wstring & /*str_descriptor*/)
-> packet::error_type override;
[[nodiscard]] auto winfsp_get_volume_info(UINT64 &total_size,
@ -317,7 +317,7 @@ public:
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
remote::file_info *file_info) -> packet::error_type override;
[[nodiscard]] auto winfsp_set_file_size(PVOID file_desc, UINT64 newSize,
[[nodiscard]] auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
remote::file_info *file_info)
-> packet::error_type override;

View File

@ -44,9 +44,15 @@ class remote_server_base : public remote_open_file_table,
public virtual remote_winfsp::i_remote_instance,
public virtual remote_fuse::i_remote_instance {
public:
remote_server_base(app_config &config, drive &d, std::string mount_location)
remote_server_base(const remote_server_base &) = delete;
remote_server_base(remote_server_base &&) = delete;
auto operator=(const remote_server_base &) -> remote_server_base & = delete;
auto operator=(remote_server_base &&) -> remote_server_base & = delete;
public:
remote_server_base(app_config &config, drive &drv, std::string mount_location)
: config_(config),
drive_(d),
drive_(drv),
mount_location_(std::move(mount_location)),
client_pool_(config.get_remote_client_pool_size()) {
event_system::instance().raise<service_started>("remote_server_base");
@ -57,14 +63,13 @@ public:
packet &) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
std::wstring file_name;
DECODE_OR_RETURN(request, file_name);
ret = this->winfsp_can_delete(file_desc, &file_name[0]);
return ret;
return this->winfsp_can_delete(file_desc, file_name.data());
}});
handler_lookup_.insert(
{"::winfsp_cleanup",
@ -73,17 +78,17 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
std::wstring file_name;
DECODE_OR_RETURN(request, file_name);
UINT32 flags;
UINT32 flags{};
DECODE_OR_RETURN(request, flags);
BOOLEAN was_closed;
ret = this->winfsp_cleanup(file_desc, &file_name[0], flags,
BOOLEAN was_closed{};
ret = this->winfsp_cleanup(file_desc, file_name.data(), flags,
was_closed);
response.encode(was_closed);
@ -96,11 +101,10 @@ public:
packet &) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
ret = this->winfsp_close(file_desc);
return ret;
return this->winfsp_close(file_desc);
}});
handler_lookup_.insert(
{"::winfsp_create",
@ -112,23 +116,23 @@ public:
std::wstring file_name;
DECODE_OR_RETURN(request, file_name);
UINT32 create_options;
UINT32 create_options{};
DECODE_OR_RETURN(request, create_options);
UINT32 granted_access;
UINT32 granted_access{};
DECODE_OR_RETURN(request, granted_access);
UINT32 attributes;
UINT32 attributes{};
DECODE_OR_RETURN(request, attributes);
UINT64 allocation_size;
UINT64 allocation_size{};
DECODE_OR_RETURN(request, allocation_size);
BOOLEAN exists = 0;
BOOLEAN exists{0};
remote::file_info file_info{};
std::string normalized_name;
PVOID file_desc;
ret = this->winfsp_create(&file_name[0], create_options,
PVOID file_desc{};
ret = this->winfsp_create(file_name.data(), create_options,
granted_access, attributes,
allocation_size, &file_desc, &file_info,
normalized_name, exists);
@ -136,8 +140,10 @@ public:
#ifdef _WIN32
this->set_client_id(file_desc, client_id);
#else
this->set_client_id(reinterpret_cast<std::uintptr_t>(file_desc),
client_id);
this->set_client_id(
static_cast<native_handle>(
reinterpret_cast<std::uintptr_t>(file_desc)),
client_id);
#endif
response.encode(file_desc);
response.encode(file_info);
@ -154,7 +160,7 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
remote::file_info file_info{};
@ -172,7 +178,7 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
remote::file_info file_info{};
@ -192,21 +198,22 @@ public:
std::wstring file_name;
DECODE_OR_RETURN(request, file_name);
std::uint64_t descriptor_size;
std::uint64_t descriptor_size{};
DECODE_OR_RETURN(request, descriptor_size);
std::uint8_t get_attributes;
std::uint8_t get_attributes{};
DECODE_OR_RETURN(request, get_attributes);
UINT32 attributes;
auto *attrPtr = get_attributes ? &attributes : nullptr;
UINT32 attributes{};
auto *attr_ptr = get_attributes == 0U ? nullptr : &attributes;
std::wstring string_descriptor;
ret = this->winfsp_get_security_by_name(
&file_name[0], attrPtr,
descriptor_size ? &descriptor_size : nullptr, string_descriptor);
file_name.data(), attr_ptr,
descriptor_size == 0U ? nullptr : &descriptor_size,
string_descriptor);
if (ret == STATUS_SUCCESS) {
response.encode(string_descriptor);
if (get_attributes) {
if (get_attributes != 0U) {
response.encode(attributes);
}
}
@ -219,8 +226,8 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
UINT64 total_size = 0u;
UINT64 free_size = 0u;
UINT64 total_size{};
UINT64 free_size{};
std::string volume_label;
if ((ret = this->winfsp_get_volume_info(
total_size, free_size, volume_label)) ==
@ -257,24 +264,26 @@ public:
std::wstring file_name;
DECODE_OR_RETURN(request, file_name);
UINT32 create_options;
UINT32 create_options{};
DECODE_OR_RETURN(request, create_options);
UINT32 granted_access;
UINT32 granted_access{};
DECODE_OR_RETURN(request, granted_access);
remote::file_info file_info{};
std::string normalized_name;
PVOID file_desc;
ret =
this->winfsp_open(&file_name[0], create_options, granted_access,
&file_desc, &file_info, normalized_name);
PVOID file_desc{};
ret = this->winfsp_open(file_name.data(), create_options,
granted_access, &file_desc, &file_info,
normalized_name);
if (ret == STATUS_SUCCESS) {
#ifdef _WIN32
this->set_client_id(file_desc, client_id);
#else
this->set_client_id(reinterpret_cast<std::uintptr_t>(file_desc),
client_id);
this->set_client_id(
static_cast<native_handle>(
reinterpret_cast<std::uintptr_t>(file_desc)),
client_id);
#endif
response.encode(file_desc);
response.encode(file_info);
@ -290,16 +299,16 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
UINT32 attributes;
UINT32 attributes{};
DECODE_OR_RETURN(request, attributes);
BOOLEAN replace_attributes;
BOOLEAN replace_attributes{};
DECODE_OR_RETURN(request, replace_attributes);
UINT64 allocation_size;
UINT64 allocation_size{};
DECODE_OR_RETURN(request, allocation_size);
remote::file_info file_info{};
@ -318,23 +327,23 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
UINT64 offset;
UINT64 offset{};
DECODE_OR_RETURN(request, offset);
UINT32 length;
UINT32 length{};
DECODE_OR_RETURN(request, length);
data_buffer buffer(length);
UINT32 bytes_transferred = 0;
ret = this->winfsp_read(file_desc, &buffer[0], offset, length,
ret = this->winfsp_read(file_desc, buffer.data(), offset, length,
&bytes_transferred);
if (ret == STATUS_SUCCESS) {
response.encode(static_cast<UINT32>(bytes_transferred));
if (bytes_transferred) {
response.encode(&buffer[0], bytes_transferred);
if (bytes_transferred != 0U) {
response.encode(buffer.data(), bytes_transferred);
}
}
return ret;
@ -346,7 +355,7 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
std::wstring pattern;
@ -355,13 +364,14 @@ public:
std::wstring marker;
DECODE_OR_IGNORE(request, marker);
json itemList;
json item_list;
ret = this->winfsp_read_directory(
file_desc, &pattern[0],
wcsnlen(&marker[0], marker.size()) ? &marker[0] : nullptr,
itemList);
file_desc, pattern.data(),
wcsnlen(marker.data(), marker.size()) == 0U ? nullptr
: marker.data(),
item_list);
if (ret == STATUS_SUCCESS) {
response.encode(itemList.dump(0));
response.encode(item_list.dump(0));
}
return ret;
}});
@ -372,7 +382,7 @@ public:
packet &) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
std::wstring file_name;
@ -381,11 +391,11 @@ public:
std::wstring new_file_name;
DECODE_OR_RETURN(request, new_file_name);
BOOLEAN replace_if_exists;
BOOLEAN replace_if_exists{};
DECODE_OR_RETURN(request, replace_if_exists);
ret = this->winfsp_rename(file_desc, &file_name[0],
&new_file_name[0], replace_if_exists);
ret = this->winfsp_rename(file_desc, file_name.data(),
new_file_name.data(), replace_if_exists);
return ret;
}});
handler_lookup_.insert(
@ -395,22 +405,22 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
UINT32 attributes;
UINT32 attributes{};
DECODE_OR_RETURN(request, attributes);
UINT64 creation_time;
UINT64 creation_time{};
DECODE_OR_RETURN(request, creation_time);
UINT64 last_access_time;
UINT64 last_access_time{};
DECODE_OR_RETURN(request, last_access_time);
UINT64 last_write_time;
UINT64 last_write_time{};
DECODE_OR_RETURN(request, last_write_time);
UINT64 change_time;
UINT64 change_time{};
DECODE_OR_RETURN(request, change_time);
remote::file_info file_info{};
@ -429,13 +439,13 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
UINT64 new_size;
UINT64 new_size{};
DECODE_OR_RETURN(request, new_size);
BOOLEAN set_allocation_size;
BOOLEAN set_allocation_size{};
DECODE_OR_RETURN(request, set_allocation_size);
remote::file_info file_info{};
@ -456,8 +466,7 @@ public:
std::wstring location;
DECODE_OR_RETURN(request, location);
ret = this->winfsp_unmounted(location);
return ret;
return this->winfsp_unmounted(location);
}});
handler_lookup_.insert(
{"::winfsp_write",
@ -466,19 +475,19 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
UINT32 length;
UINT32 length{};
DECODE_OR_RETURN(request, length);
UINT64 offset;
UINT64 offset{};
DECODE_OR_RETURN(request, offset);
BOOLEAN write_to_end;
BOOLEAN write_to_end{};
DECODE_OR_RETURN(request, write_to_end);
BOOLEAN constrained_io;
BOOLEAN constrained_io{};
DECODE_OR_RETURN(request, constrained_io);
auto *buffer = request->current_pointer();
@ -504,10 +513,10 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
std::int32_t mask;
std::int32_t mask{};
DECODE_OR_RETURN(request, mask);
return this->fuse_access(&path[0], mask);
return this->fuse_access(path.data(), mask);
}});
handler_lookup_.insert(
{"::fuse_chflags",
@ -519,10 +528,10 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
std::uint32_t flags;
std::uint32_t flags{};
DECODE_OR_RETURN(request, flags);
return this->fuse_chflags(&path[0], flags);
return this->fuse_chflags(path.data(), flags);
}});
handler_lookup_.insert(
{"::fuse_chmod",
@ -549,10 +558,10 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
remote::user_id uid;
remote::user_id uid{};
DECODE_OR_RETURN(request, uid);
remote::group_id gid;
remote::group_id gid{};
DECODE_OR_RETURN(request, gid);
return this->fuse_chown(&path[0], uid, gid);
@ -567,18 +576,19 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_mode mode;
remote::file_mode mode{};
DECODE_OR_RETURN(request, mode);
remote::open_flags flags;
remote::open_flags flags{};
DECODE_OR_RETURN(request, flags);
remote::file_handle handle;
if ((ret = this->fuse_create(&path[0], mode, flags, handle)) >= 0) {
remote::file_handle handle{};
if ((ret = this->fuse_create(path.data(), mode, flags, handle)) >=
0) {
#ifdef _WIN32
this->set_compat_client_id(handle, client_id);
#else
this->set_client_id(handle, client_id);
this->set_client_id(static_cast<native_handle>(handle), client_id);
#endif
response.encode(handle);
}
@ -623,18 +633,18 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
remote::user_id uid;
remote::user_id uid{};
DECODE_OR_RETURN(request, uid);
remote::group_id gid;
remote::group_id gid{};
DECODE_OR_RETURN(request, gid);
remote::stat st{};
bool directory = false;
ret = this->fuse_fgetattr(&path[0], st, directory, handle);
ret = this->fuse_fgetattr(path.data(), st, directory, handle);
if (ret == 0) {
st.st_uid = uid;
st.st_gid = gid;
@ -657,10 +667,10 @@ public:
remote::setattr_x attr{};
DECODE_OR_RETURN(request, attr);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
return this->fuse_fsetattr_x(&path[0], attr, handle);
return this->fuse_fsetattr_x(path.data(), attr, handle);
}});
handler_lookup_.insert(
{"::fuse_fsync",
@ -965,7 +975,7 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string from;
DECODE_OR_RETURN(request, from);
@ -973,26 +983,26 @@ public:
std::string to;
DECODE_OR_RETURN(request, to);
return this->fuse_rename(&from[0], &to[0]);
return this->fuse_rename(from.data(), to.data());
}});
handler_lookup_.insert(
{"::fuse_rmdir",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string path;
DECODE_OR_RETURN(request, path);
return this->fuse_rmdir(&path[0]);
return this->fuse_rmdir(path.data());
}});
handler_lookup_.insert(
{"::fuse_setattr_x",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string path;
DECODE_OR_RETURN(request, path);
@ -1000,64 +1010,64 @@ public:
remote::setattr_x attr{};
DECODE_OR_RETURN(request, attr);
return this->fuse_setattr_x(&path[0], attr);
return this->fuse_setattr_x(path.data(), attr);
}});
handler_lookup_.insert(
{"::fuse_setbkuptime",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_time bkuptime;
remote::file_time bkuptime{};
DECODE_OR_RETURN(request, bkuptime);
return this->fuse_setbkuptime(&path[0], bkuptime);
return this->fuse_setbkuptime(path.data(), bkuptime);
}});
handler_lookup_.insert(
{"::fuse_setchgtime",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_time chgtime;
remote::file_time chgtime{};
DECODE_OR_RETURN(request, chgtime);
return this->fuse_setchgtime(&path[0], chgtime);
return this->fuse_setchgtime(path.data(), chgtime);
}});
handler_lookup_.insert(
{"::fuse_setcrtime",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_time crtime;
remote::file_time crtime{};
DECODE_OR_RETURN(request, crtime);
return this->fuse_setcrtime(&path[0], crtime);
return this->fuse_setcrtime(path.data(), crtime);
}});
handler_lookup_.insert(
{"::fuse_setvolname",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string name;
DECODE_OR_RETURN(request, name);
return this->fuse_setvolname(&name[0]);
return this->fuse_setvolname(name.data());
}});
/*handlerLookup_.insert({"::fuse_setxattr",
[this](std::uint32_t serviceFlags, const std::string
@ -1125,16 +1135,16 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &response) -> packet::error_type {
auto ret = -1;
std::int32_t ret{-1};
std::string path;
DECODE_OR_RETURN(request, path);
std::uint64_t frsize;
std::uint64_t frsize{};
DECODE_OR_RETURN(request, frsize);
remote::statfs st{};
ret = this->fuse_statfs(&path[0], frsize, st);
ret = this->fuse_statfs(path.data(), frsize, st);
if (ret == 0) {
response.encode(st);
}
@ -1145,16 +1155,16 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &response) -> packet::error_type {
auto ret = -1;
std::int32_t ret{-1};
std::string path;
DECODE_OR_RETURN(request, path);
std::uint64_t bsize;
std::uint64_t bsize{};
DECODE_OR_RETURN(request, bsize);
remote::statfs_x st{};
ret = this->fuse_statfs_x(&path[0], bsize, st);
ret = this->fuse_statfs_x(path.data(), bsize, st);
if (ret == 0) {
response.encode(st);
}
@ -1165,34 +1175,34 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_offset size;
remote::file_offset size{};
DECODE_OR_IGNORE(request, size);
return this->fuse_truncate(&path[0], size);
return this->fuse_truncate(path.data(), size);
}});
handler_lookup_.insert(
{"::fuse_unlink",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
return this->fuse_unlink(&path[0]);
return this->fuse_unlink(path.data());
}});
handler_lookup_.insert(
{"::fuse_utimens",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
@ -1200,13 +1210,13 @@ public:
remote::file_time tv[2] = {0};
if ((ret = request->decode(&tv[0], sizeof(remote::file_time) * 2)) ==
0) {
std::uint64_t op0;
std::uint64_t op0{};
DECODE_OR_RETURN(request, op0);
std::uint64_t op1;
std::uint64_t op1{};
DECODE_OR_RETURN(request, op1);
ret = this->fuse_utimens(&path[0], tv, op0, op1);
ret = this->fuse_utimens(path.data(), tv, op0, op1);
}
return ret;
}});
@ -1215,27 +1225,27 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
std::int32_t ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_size writeSize;
DECODE_OR_RETURN(request, writeSize);
remote::file_size write_size{};
DECODE_OR_RETURN(request, write_size);
if (writeSize > std::numeric_limits<std::size_t>::max()) {
if (write_size > std::numeric_limits<std::size_t>::max()) {
return -ERANGE;
}
data_buffer buffer(static_cast<std::size_t>(writeSize));
if ((ret = request->decode(&buffer[0], buffer.size())) == 0) {
remote::file_offset write_offset;
data_buffer buffer(static_cast<std::size_t>(write_size));
if ((ret = request->decode(buffer.data(), buffer.size())) == 0) {
remote::file_offset write_offset{};
DECODE_OR_RETURN(request, write_offset);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
ret = this->fuse_write(&path[0], &buffer[0], writeSize,
ret = this->fuse_write(path.data(), buffer.data(), write_size,
write_offset, handle);
}
return ret;
@ -1245,12 +1255,12 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
std::int32_t ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_size write_size;
remote::file_size write_size{};
DECODE_OR_RETURN(request, write_size);
if (write_size > std::numeric_limits<std::size_t>::max()) {
@ -1258,18 +1268,18 @@ public:
}
data_buffer buffer(static_cast<std::size_t>(write_size));
if ((ret = request->decode(&buffer[0], buffer.size())) == 0) {
if ((ret = request->decode(buffer.data(), buffer.size())) == 0) {
buffer = macaron::Base64::Decode(
std::string(buffer.begin(), buffer.end()));
write_size = buffer.size();
remote::file_offset write_offset;
remote::file_offset write_offset{};
DECODE_OR_RETURN(request, write_offset);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
ret = this->fuse_write(&path[0], &buffer[0], write_size,
ret = this->fuse_write(path.data(), buffer.data(), write_size,
write_offset, handle);
}
return ret;
@ -1279,7 +1289,7 @@ public:
[this](std::uint32_t, const std::string &client_id, std::uint64_t,
const std::string &, packet *request,
packet &response) -> packet::error_type {
std::int32_t ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
@ -1288,7 +1298,7 @@ public:
json_data["handle"] = -1;
json_data["page_count"] = 0;
json_data["path"] = path;
if ((ret = this->json_create_directory_snapshot(&path[0],
if ((ret = this->json_create_directory_snapshot(path.data(),
json_data)) == 0) {
this->add_directory(client_id,
reinterpret_cast<void *>(
@ -1307,10 +1317,10 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
std::uint32_t page;
std::uint32_t page{};
DECODE_OR_RETURN(request, page);
ret = -EBADF;
@ -1338,10 +1348,10 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
ret = this->json_release_directory_snapshot(&path[0], handle);
ret = this->json_release_directory_snapshot(path.data(), handle);
if (this->remove_directory(client_id,
reinterpret_cast<void *>(handle))) {
return ret;
@ -1380,7 +1390,7 @@ public:
protected:
app_config &config_;
drive &drive_;
const std::string mount_location_;
std::string mount_location_;
private:
client_pool client_pool_;
@ -1422,7 +1432,7 @@ protected:
}
void delete_open_directory(void *dir) override {
if (dir) {
if (dir != nullptr) {
delete reinterpret_cast<directory_iterator *>(dir);
}
}

View File

@ -29,84 +29,84 @@ class i_remote_instance : public virtual i_remote_json {
INTERFACE_SETUP(i_remote_instance);
public:
virtual auto winfsp_can_delete(PVOID fileDesc, PWSTR fileName)
virtual auto winfsp_can_delete(PVOID file_desc, PWSTR file_name)
-> packet::error_type = 0;
virtual auto winfsp_cleanup(PVOID fileDesc, PWSTR fileName, UINT32 flags,
BOOLEAN &wasClosed) -> packet::error_type = 0;
virtual auto winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
BOOLEAN &was_closed) -> packet::error_type = 0;
virtual auto winfsp_close(PVOID fileDesc) -> packet::error_type = 0;
virtual auto winfsp_close(PVOID file_desc) -> packet::error_type = 0;
virtual auto winfsp_create(PWSTR fileName, UINT32 createOptions,
UINT32 grantedAccess, UINT32 fileAttributes,
UINT64 allocationSize, PVOID *fileDesc,
remote::file_info *fileInfo,
std::string &normalizedName, BOOLEAN &exists)
virtual auto winfsp_create(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, UINT32 file_attributes,
UINT64 allocation_size, PVOID *file_desc,
remote::file_info *file_info,
std::string &normalized_name, BOOLEAN &exists)
-> packet::error_type = 0;
virtual auto winfsp_flush(PVOID fileDesc, remote::file_info *fileInfo)
virtual auto winfsp_flush(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto winfsp_get_dir_buffer(PVOID fileDesc, PVOID *&ptr)
virtual auto winfsp_get_dir_buffer(PVOID file_desc, PVOID *&ptr)
-> packet::error_type = 0;
virtual auto winfsp_get_file_info(PVOID fileDesc, remote::file_info *fileInfo)
virtual auto winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto
winfsp_get_security_by_name(PWSTR fileName, PUINT32 fileAttributes,
std::uint64_t *securityDescriptorSize,
std::wstring &strDescriptor)
winfsp_get_security_by_name(PWSTR file_name, PUINT32 file_attributes,
std::uint64_t *security_descriptor_size,
std::wstring &str_descriptor)
-> packet::error_type = 0;
virtual auto winfsp_get_volume_info(UINT64 &totalSize, UINT64 &freeSize,
std::string &volumeLabel)
virtual auto winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label)
-> packet::error_type = 0;
virtual auto winfsp_mounted(const std::wstring &location)
-> packet::error_type = 0;
virtual auto winfsp_open(PWSTR fileName, UINT32 createOptions,
UINT32 grantedAccess, PVOID *fileDesc,
remote::file_info *fileInfo,
std::string &normalizedName)
virtual auto winfsp_open(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, PVOID *file_desc,
remote::file_info *file_info,
std::string &normalized_name)
-> packet::error_type = 0;
virtual auto winfsp_overwrite(PVOID fileDesc, UINT32 fileAttributes,
BOOLEAN replaceFileAttributes,
UINT64 allocationSize,
remote::file_info *fileInfo)
virtual auto winfsp_overwrite(PVOID file_desc, UINT32 file_attributes,
BOOLEAN replace_file_attributes,
UINT64 allocation_size,
remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto winfsp_read(PVOID fileDesc, PVOID buffer, UINT64 offset,
UINT32 length, PUINT32 bytesTransferred)
virtual auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
UINT32 length, PUINT32 bytes_transferred)
-> packet::error_type = 0;
virtual auto winfsp_read_directory(PVOID fileDesc, PWSTR pattern,
virtual auto winfsp_read_directory(PVOID file_desc, PWSTR pattern,
PWSTR marker, json &itemList)
-> packet::error_type = 0;
virtual auto winfsp_rename(PVOID fileDesc, PWSTR fileName, PWSTR newFileName,
BOOLEAN replaceIfExists) -> packet::error_type = 0;
virtual auto winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name,
BOOLEAN replace_if_exists) -> packet::error_type = 0;
virtual auto winfsp_set_basic_info(PVOID fileDesc, UINT32 fileAttributes,
UINT64 creationTime, UINT64 lastAccessTime,
UINT64 lastWriteTime, UINT64 changeTime,
remote::file_info *fileInfo)
virtual auto winfsp_set_basic_info(PVOID file_desc, UINT32 file_attributes,
UINT64 creation_time, UINT64 last_access_time,
UINT64 last_write_time, UINT64 change_time,
remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto winfsp_set_file_size(PVOID fileDesc, UINT64 newSize,
BOOLEAN setAllocationSize,
remote::file_info *fileInfo)
virtual auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto winfsp_unmounted(const std::wstring &location)
-> packet::error_type = 0;
virtual auto winfsp_write(PVOID fileDesc, PVOID buffer, UINT64 offset,
UINT32 length, BOOLEAN writeToEndOfFile,
BOOLEAN constrainedIo, PUINT32 bytesTransferred,
remote::file_info *fileInfo)
virtual auto winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
UINT32 length, BOOLEAN write_to_end,
BOOLEAN constrained_io, PUINT32 bytes_transferred,
remote::file_info *file_info)
-> packet::error_type = 0;
};

View File

@ -266,7 +266,7 @@ public:
remote::file_info *file_info)
-> packet::error_type override;
auto winfsp_set_file_size(PVOID file_desc, UINT64 newSize,
auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
remote::file_info *file_info)
-> packet::error_type override;

View File

@ -172,7 +172,7 @@ public:
PULONG bytes_transferred) -> NTSTATUS override;
auto Rename(PVOID file_node, PVOID file_desc, PWSTR file_name,
PWSTR newFileName, BOOLEAN replace_if_exists)
PWSTR new_file_name, BOOLEAN replace_if_exists)
-> NTSTATUS override;
auto SetBasicInfo(PVOID file_node, PVOID file_desc, UINT32 attributes,

View File

@ -54,6 +54,12 @@ public:
~event_consumer() { t_event_system::instance().release(this); }
public:
event_consumer(const event_consumer &) = delete;
event_consumer(event_consumer &&) = delete;
auto operator=(const event_consumer &) -> event_consumer & = delete;
auto operator=(event_consumer &&) -> event_consumer & = delete;
private:
std::function<void(const event &)> callback_;
@ -82,9 +88,9 @@ private:
void process_events() {
std::vector<std::shared_ptr<event_type>> events;
{
unique_mutex_lock l(event_mutex_);
unique_mutex_lock lock(event_mutex_);
if (not stop_requested_ && event_list_.empty()) {
event_notify_.wait_for(l, 1s);
event_notify_.wait_for(lock, 1s);
}
if (not event_list_.empty()) {
@ -96,15 +102,16 @@ private:
const auto notify_events = [this](const std::string &name,
const event_type &event) {
std::deque<std::future<void>> futures;
recur_mutex_lock l(consumer_mutex_);
recur_mutex_lock lock(consumer_mutex_);
if (event_consumers_.find(name) != event_consumers_.end()) {
for (auto *ec : event_consumers_[name]) {
for (auto *consumer : event_consumers_[name]) {
if (event.get_allow_async()) {
futures.emplace_back(std::async(std::launch::async, [ec, &event]() {
ec->notify_event(event);
}));
futures.emplace_back(
std::async(std::launch::async, [consumer, &event]() {
consumer->notify_event(event);
}));
} else {
ec->notify_event(event);
consumer->notify_event(event);
}
}
}
@ -115,48 +122,48 @@ private:
}
};
for (const auto &e : events) {
notify_events("", *e.get());
notify_events(e->get_name(), *e.get());
for (const auto &evt : events) {
notify_events("", *evt.get());
notify_events(evt->get_name(), *evt.get());
}
}
void queue_event(event_type *e) {
mutex_lock l(event_mutex_);
event_list_.emplace_back(std::shared_ptr<event_type>(e));
void queue_event(std::shared_ptr<event_type> evt) {
mutex_lock lock(event_mutex_);
event_list_.push_back(std::move(evt));
event_notify_.notify_all();
}
public:
void attach(event_consumer *ec) {
recur_mutex_lock l(consumer_mutex_);
event_consumers_[""].push_back(ec);
void attach(event_consumer *consumer) {
recur_mutex_lock lock(consumer_mutex_);
event_consumers_[""].push_back(consumer);
}
void attach(const std::string &event_name, event_consumer *ec) {
recur_mutex_lock l(consumer_mutex_);
event_consumers_[event_name].push_back(ec);
void attach(const std::string &event_name, event_consumer *consumer) {
recur_mutex_lock lock(consumer_mutex_);
event_consumers_[event_name].push_back(consumer);
}
template <typename t, typename... args> void raise(args &&...a) {
queue_event(new t(std::forward<args>(a)...));
template <typename event_t, typename... arg_t> void raise(arg_t &&...args) {
queue_event(std::make_shared<event_t>(std::forward<arg_t>(args)...));
}
void release(event_consumer *ec) {
recur_mutex_lock l(consumer_mutex_);
auto it = std::find_if(event_consumers_.begin(), event_consumers_.end(),
[&](const auto &kv) -> bool {
return utils::collection_includes(kv.second, ec);
});
void release(event_consumer *consumer) {
recur_mutex_lock lock(consumer_mutex_);
auto iter =
std::find_if(event_consumers_.begin(), event_consumers_.end(),
[&](const auto &item) -> bool {
return utils::collection_includes(item.second, consumer);
});
if (it != event_consumers_.end()) {
auto &q = (*it).second;
utils::remove_element_from(q, ec);
if (iter != event_consumers_.end()) {
utils::remove_element_from((*iter).second, consumer);
}
}
void start() {
mutex_lock l(run_mutex_);
mutex_lock lock(run_mutex_);
if (not event_thread_) {
stop_requested_ = false;
event_thread_ = std::make_unique<std::thread>([this]() {
@ -168,7 +175,7 @@ public:
}
void stop() {
mutex_lock l(run_mutex_);
mutex_lock lock(run_mutex_);
if (event_thread_) {
stop_requested_ = true;
event_notify_.notify_all();

View File

@ -72,13 +72,13 @@ public:
auto operator=(const download &) noexcept -> download & = delete;
private:
bool complete_ = false;
api_error error_ = api_error::success;
bool complete_{false};
api_error error_{api_error::success};
std::mutex mtx_;
std::condition_variable notify_;
public:
void notify(const api_error &e);
void notify(const api_error &err);
auto wait() -> api_error;
};
@ -194,17 +194,17 @@ public:
class open_file final : public open_file_base {
public:
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
filesystem_item fsi, i_provider &provider, i_upload_manager &um);
filesystem_item fsi, i_provider &provider, i_upload_manager &mgr);
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
filesystem_item fsi,
std::map<std::uint64_t, open_file_data> open_data,
i_provider &provider, i_upload_manager &um);
i_provider &provider, i_upload_manager &mgr);
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
filesystem_item fsi, i_provider &provider,
std::optional<boost::dynamic_bitset<>> read_state,
i_upload_manager &um);
i_upload_manager &mgr);
private:
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
@ -212,7 +212,7 @@ public:
std::map<std::uint64_t, open_file_data> open_data,
i_provider &provider,
std::optional<boost::dynamic_bitset<>> read_state,
i_upload_manager &um);
i_upload_manager &mgr);
public:
open_file() = delete;
@ -225,11 +225,11 @@ public:
~open_file() override;
private:
i_upload_manager &um_;
i_upload_manager &mgr_;
private:
bool notified_ = false;
std::size_t read_chunk_index_ = 0u;
std::size_t read_chunk_index_{};
boost::dynamic_bitset<> read_state_;
std::unique_ptr<std::thread> reader_thread_;
std::unique_ptr<std::thread> download_thread_;
@ -262,11 +262,13 @@ public:
auto is_write_supported() const -> bool override { return true; }
[[nodiscard]] auto native_operation(const native_operation_callback &cb)
[[nodiscard]] auto
native_operation(const native_operation_callback &callback)
-> api_error override;
[[nodiscard]] auto native_operation(std::uint64_t new_file_size,
const native_operation_callback &cb)
[[nodiscard]] auto
native_operation(std::uint64_t new_file_size,
const native_operation_callback &callback)
-> api_error override;
void remove(std::uint64_t handle) override;
@ -313,8 +315,8 @@ public:
std::unique_ptr<std::thread> chunk_reverse_thread_;
std::condition_variable chunk_notify_;
mutable std::mutex chunk_mtx_;
std::size_t current_chunk_ = 0u;
std::size_t first_chunk_ = 0u;
std::size_t current_chunk_{};
std::size_t first_chunk_{};
std::size_t last_chunk_;
private:
@ -355,7 +357,8 @@ public:
auto is_write_supported() const -> bool override { return false; }
[[nodiscard]] auto native_operation(const native_operation_callback &cb)
[[nodiscard]] auto
native_operation(const native_operation_callback &callback)
-> api_error override;
[[nodiscard]] auto native_operation(std::uint64_t,

View File

@ -56,11 +56,11 @@ public:
[[nodiscard]] virtual auto is_directory() const -> bool = 0;
[[nodiscard]] virtual auto
native_operation(const native_operation_callback &cb) -> api_error = 0;
native_operation(const native_operation_callback &callback) -> api_error = 0;
[[nodiscard]] virtual auto
native_operation(std::uint64_t new_file_size,
const native_operation_callback &cb) -> api_error = 0;
const native_operation_callback &callback) -> api_error = 0;
[[nodiscard]] virtual auto read(std::size_t read_size,
std::uint64_t read_offset, data_buffer &data)

View File

@ -139,6 +139,11 @@ enum class exit_code : std::int32_t {
init_failed = -18,
};
enum http_error_codes : std::int32_t {
ok = 200,
not_found = 404,
};
enum class lock_result {
success,
locked,

View File

@ -1,3 +1,4 @@
// NOLINTBEGIN
#ifndef _MACARON_BASE64_H_
#define _MACARON_BASE64_H_
@ -25,6 +26,18 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wold-style-cast"
#pragma GCC diagnostic ignored "-Wuseless-cast"
#endif
#include <string>
#include <vector>
@ -136,4 +149,14 @@ static std::string Encode(const char *data, const size_t &len) {
}
} // namespace macaron::Base64
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif /* _MACARON_BASE64_H_ */
// NOLINTEND