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:
Scott E. Graves 2023-11-08 19:53:12 -06:00
parent a7209184c8
commit f2c1f64f02
30 changed files with 737 additions and 615 deletions

View File

@ -158,6 +158,8 @@ nmake
noappledouble
nocache
nocloseprocess
nolintbegin
nolintend
nopath
npubbytes
ntfs
@ -226,6 +228,7 @@ szlib_libpath
target_precompile_headers
teventsystem
tolower
tomykaira
toolset
ttmath
ularge
@ -256,6 +259,7 @@ woverloaded
wpedantic
wshadow
wsign
wunknown
wunused
wuseless
xattr

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,7 +140,9 @@ public:
#ifdef _WIN32
this->set_client_id(file_desc, client_id);
#else
this->set_client_id(reinterpret_cast<std::uintptr_t>(file_desc),
this->set_client_id(
static_cast<native_handle>(
reinterpret_cast<std::uintptr_t>(file_desc)),
client_id);
#endif
response.encode(file_desc);
@ -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,23 +264,25 @@ 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),
this->set_client_id(
static_cast<native_handle>(
reinterpret_cast<std::uintptr_t>(file_desc)),
client_id);
#endif
response.encode(file_desc);
@ -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

View File

@ -43,32 +43,36 @@ const curl_comm::write_callback curl_comm::write_headers =
auto &headers = *reinterpret_cast<http_headers *>(outstream);
const auto header = std::string(buffer, size * nitems);
const auto parts = utils::string::split(header, ':');
if (parts.size() > 1u) {
auto data = header.substr(parts[0u].size() + 1u);
if (parts.size() > 1U) {
auto data = header.substr(parts[0U].size() + 1U);
utils::string::left_trim(data);
utils::string::right_trim(data, '\r');
utils::string::right_trim(data, '\n');
utils::string::right_trim(data, '\r');
headers[utils::string::to_lower(parts[0u])] = data;
headers[utils::string::to_lower(parts[0U])] = data;
}
return size * nitems;
});
curl_comm::curl_comm(host_config hc)
: host_config_(std::move(hc)), s3_config_(std::nullopt) {}
curl_comm::curl_comm(host_config cfg)
: host_config_(std::move(cfg)), s3_config_(std::nullopt) {}
curl_comm::curl_comm(s3_config s3)
: host_config_(std::nullopt), s3_config_(std::move(s3)) {}
curl_comm::curl_comm(s3_config cfg)
: host_config_(std::nullopt), s3_config_(std::move(cfg)) {}
auto curl_comm::construct_url(CURL *curl, const std::string &relative_path,
const host_config &hc) -> std::string {
auto custom_port =
(((hc.protocol == "http") && (hc.api_port == 80U || hc.api_port == 0U)) ||
((hc.protocol == "https") && (hc.api_port == 443U || hc.api_port == 0U)))
const host_config &cfg) -> std::string {
static constexpr const auto http = 80U;
static constexpr const auto https = 443U;
auto custom_port = (((cfg.protocol == "http") &&
(cfg.api_port == http || cfg.api_port == 0U)) ||
((cfg.protocol == "https") &&
(cfg.api_port == https || cfg.api_port == 0U)))
? ""
: ":" + std::to_string(hc.api_port);
auto url = hc.protocol + "://" +
utils::string::trim_copy(hc.host_name_or_ip) + custom_port;
: ":" + std::to_string(cfg.api_port);
auto url = cfg.protocol + "://" +
utils::string::trim_copy(cfg.host_name_or_ip) + custom_port;
static const auto complete_url = [](const std::string &current_path,
const std::string &parent_path,
@ -80,40 +84,40 @@ auto curl_comm::construct_url(CURL *curl, const std::string &relative_path,
return final_url;
};
auto path = utils::path::combine("/", {hc.path});
auto path = utils::path::combine("/", {cfg.path});
return relative_path.empty()
? complete_url(path, hc.path, url)
? complete_url(path, cfg.path, url)
: complete_url(utils::path::combine(
path, {url_encode(curl, relative_path, true)}),
relative_path, url);
}
auto curl_comm::create_host_config(const s3_config &config,
bool use_s3_path_style) -> host_config {
host_config hc{};
hc.api_password = config.secret_key;
hc.api_user = config.access_key;
auto curl_comm::create_host_config(const s3_config &cfg, bool use_s3_path_style)
-> host_config {
host_config host_cfg{};
host_cfg.api_password = cfg.secret_key;
host_cfg.api_user = cfg.access_key;
auto pos = config.url.find(':');
hc.host_name_or_ip = config.url.substr(pos + 3U);
if (config.use_region_in_url && not config.region.empty()) {
auto parts = utils::string::split(hc.host_name_or_ip, '.', false);
auto pos = cfg.url.find(':');
host_cfg.host_name_or_ip = cfg.url.substr(pos + 3U);
if (cfg.use_region_in_url && not cfg.region.empty()) {
auto parts = utils::string::split(host_cfg.host_name_or_ip, '.', false);
if (parts.size() > 1U) {
parts.insert(parts.begin() + 1U, config.region);
hc.host_name_or_ip = utils::string::join(parts, '.');
parts.insert(parts.begin() + 1U, cfg.region);
host_cfg.host_name_or_ip = utils::string::join(parts, '.');
}
}
if (not use_s3_path_style) {
hc.host_name_or_ip = config.bucket + '.' + hc.host_name_or_ip;
host_cfg.host_name_or_ip = cfg.bucket + '.' + host_cfg.host_name_or_ip;
}
hc.protocol = config.url.substr(0U, pos);
host_cfg.protocol = cfg.url.substr(0U, pos);
if (use_s3_path_style) {
hc.path = '/' + config.bucket;
host_cfg.path = '/' + cfg.bucket;
}
return hc;
return host_cfg;
}
void curl_comm::enable_s3_path_style(bool enable) {
@ -126,7 +130,7 @@ auto curl_comm::make_request(const curl::requests::http_delete &del,
return make_request(
s3_config_.has_value()
? create_host_config(s3_config_.value(), use_s3_path_style_)
: host_config_.value(),
: host_config_.value_or(host_config{}),
del, response_code, stop_requested);
}
@ -136,7 +140,7 @@ auto curl_comm::make_request(const curl::requests::http_get &get,
return make_request(
s3_config_.has_value()
? create_host_config(s3_config_.value(), use_s3_path_style_)
: host_config_.value(),
: host_config_.value_or(host_config{}),
get, response_code, stop_requested);
}
@ -146,7 +150,7 @@ auto curl_comm::make_request(const curl::requests::http_head &head,
return make_request(
s3_config_.has_value()
? create_host_config(s3_config_.value(), use_s3_path_style_)
: host_config_.value(),
: host_config_.value_or(host_config{}),
head, response_code, stop_requested);
}
@ -156,7 +160,7 @@ auto curl_comm::make_request(const curl::requests::http_put_file &put_file,
return make_request(
s3_config_.has_value()
? create_host_config(s3_config_.value(), use_s3_path_style_)
: host_config_.value(),
: host_config_.value_or(host_config{}),
put_file, response_code, stop_requested);
}

View File

@ -38,6 +38,8 @@ multi_request::~multi_request() {
}
void multi_request::get_result(CURLcode &curl_code, long &http_code) {
static constexpr const auto timeout_ms = 100;
curl_code = CURLcode::CURLE_ABORTED_BY_CALLBACK;
http_code = -1;
@ -45,8 +47,8 @@ void multi_request::get_result(CURLcode &curl_code, long &http_code) {
int running_handles = 0;
curl_multi_perform(multi_handle_, &running_handles);
while (not error && (running_handles > 0) && not stop_requested_) {
int ignored;
curl_multi_wait(multi_handle_, nullptr, 0, 100, &ignored);
int ignored{};
curl_multi_wait(multi_handle_, nullptr, 0, timeout_ms, &ignored);
const auto ret = curl_multi_perform(multi_handle_, &running_handles);
error = (ret != CURLM_CALL_MULTI_PERFORM) && (ret != CURLM_OK);
@ -56,7 +58,7 @@ void multi_request::get_result(CURLcode &curl_code, long &http_code) {
int remaining_messages = 0;
auto *multi_result =
curl_multi_info_read(multi_handle_, &remaining_messages);
if (multi_result && (multi_result->msg == CURLMSG_DONE)) {
if ((multi_result != nullptr) && (multi_result->msg == CURLMSG_DONE)) {
curl_easy_getinfo(multi_result->easy_handle, CURLINFO_RESPONSE_CODE,
&http_code);
curl_code = multi_result->data.result;

View File

@ -30,23 +30,23 @@ void client_pool::pool::execute(
std::uint64_t thread_id, const worker_callback &worker,
const worker_complete_callback &worker_complete) {
const auto index = thread_id % pool_queues_.size();
auto wi = std::make_shared<work_item>(worker, worker_complete);
auto job = std::make_shared<work_item>(worker, worker_complete);
auto &pool_queue = pool_queues_[index];
unique_mutex_lock queue_lock(pool_queue->mutex);
pool_queue->queue.emplace_back(wi);
pool_queue->queue.emplace_back(job);
pool_queue->notify.notify_all();
queue_lock.unlock();
}
client_pool::pool::pool(std::uint8_t pool_size) {
event_system::instance().raise<service_started>("client_pool");
thread_index_ = 0u;
for (std::uint8_t i = 0u; i < pool_size; i++) {
for (std::uint8_t i = 0U; i < pool_size; i++) {
pool_queues_.emplace_back(std::make_unique<work_queue>());
}
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]() {
const auto thread_index = thread_index_++;
@ -88,12 +88,12 @@ client_pool::pool::pool(std::uint8_t pool_size) {
queue_lock.lock();
while (not queue.empty()) {
auto wi = queue.front();
auto job = queue.front();
queue.pop_front();
queue_notify.notify_all();
queue_lock.unlock();
wi->work_complete(utils::from_api_error(api_error::download_stopped));
job->work_complete(utils::from_api_error(api_error::download_stopped));
queue_lock.lock();
}
@ -108,7 +108,7 @@ void client_pool::pool::shutdown() {
shutdown_ = true;
for (auto &pool_queue : pool_queues_) {
unique_mutex_lock l(pool_queue->mutex);
mutex_lock lock(pool_queue->mutex);
pool_queue->notify.notify_all();
}
@ -148,8 +148,8 @@ void client_pool::shutdown() {
unique_mutex_lock pool_lock(pool_mutex_);
if (not shutdown_) {
shutdown_ = true;
for (auto &kv : pool_lookup_) {
kv.second->shutdown();
for (auto &pool : pool_lookup_) {
pool.second->shutdown();
}
pool_lookup_.clear();
}

View File

@ -46,6 +46,8 @@ s3_comm::s3_comm(const app_config &config)
// TODO make configurable
const auto enable_path_style =
utils::string::begins_with(s3_config_.url,
"https://gateway.storjshare.io") ||
utils::string::begins_with(s3_config_.url, "http://localhost") ||
utils::string::begins_with(s3_config_.url, "https://localhost") ||
utils::string::begins_with(s3_config_.url, "http://127.0.0.1") ||

View File

@ -37,6 +37,7 @@ get_object_list(i_http_comm &client, const s3_config &config,
std::optional<std::string> delimiter = std::nullopt,
std::optional<std::string> prefix = std::nullopt) -> bool {
curl::requests::http_get get{};
get.allow_timeout = true;
get.aws_service = "aws:amz:" + config.region + ":s3";
get.path = '/';
get.query["list-type"] = "2";
@ -62,6 +63,7 @@ auto create_directory_object_request_impl(i_http_comm &client,
long &response_code) -> bool {
try {
curl::requests::http_put_file put_file{};
put_file.allow_timeout = true;
put_file.aws_service = "aws:amz:" + config.region + ":s3";
put_file.file_name =
*(utils::string::split(object_name, '/', false).end() - 1U);
@ -86,11 +88,12 @@ auto delete_object_request_impl(i_http_comm &client, const s3_config &config,
return false;
}
if (response_code == 404) {
if (response_code == http_error_codes::not_found) {
return true;
}
curl::requests::http_delete del{};
del.allow_timeout = true;
del.aws_service = "aws:amz:" + config.region + ":s3";
del.path = '/' + object_name;
@ -109,6 +112,7 @@ auto head_object_request_impl(i_http_comm &client, const s3_config &config,
-> bool {
try {
curl::requests::http_head head{};
head.allow_timeout = true;
head.aws_service = "aws:amz:" + config.region + ":s3";
head.path = '/' + object_name;
head.response_headers = http_headers{};
@ -118,7 +122,7 @@ auto head_object_request_impl(i_http_comm &client, const s3_config &config,
return false;
}
if (response_code == 200) {
if (response_code == http_error_codes::ok) {
result.from_headers(head.response_headers.value());
}
@ -139,7 +143,7 @@ auto list_directories_request_impl(i_http_comm &client, const s3_config &config,
return false;
}
if (response_code != 200) {
if (response_code != http_error_codes::ok) {
return false;
}
@ -151,7 +155,7 @@ auto list_directories_request_impl(i_http_comm &client, const s3_config &config,
auto node_list = doc.select_nodes("/ListBucketResult/Contents");
for (const auto &node : node_list) {
auto object_name =
const auto *object_name =
node.node().select_node("Key").node().text().as_string();
if (utils::string::ends_with(object_name, "/")) {
api_file directory{};
@ -186,7 +190,7 @@ auto list_files_request_impl(
return false;
}
if (response_code != 200) {
if (response_code != http_error_codes::ok) {
return false;
}
@ -203,7 +207,7 @@ auto list_files_request_impl(
if (not utils::string::ends_with(object_name, "/")) {
api_file file{};
object_name = get_name(
*(utils::string::split(object_name, '/', false).end() - 1u),
*(utils::string::split(object_name, '/', false).end() - 1U),
object_name);
file.api_path = utils::path::create_api_path(object_name);
file.api_parent = utils::path::get_parent_api_path(file.api_path);
@ -242,7 +246,7 @@ auto list_objects_in_directory_request_impl(
return false;
}
if (response_code != 200) {
if (response_code != http_error_codes::ok) {
return false;
}
@ -255,14 +259,15 @@ auto list_objects_in_directory_request_impl(
const auto add_directory_item =
[&](bool directory, const std::string &name,
std::function<std::uint64_t(const directory_item &)> get_size) {
directory_item di{};
di.api_path =
directory_item dir_item{};
dir_item.api_path =
utils::path::create_api_path(utils::path::combine("/", {name}));
di.api_parent = utils::path::get_parent_api_path(di.api_path);
di.directory = directory;
di.size = get_size(di);
meta_provider(di);
result.emplace_back(std::move(di));
dir_item.api_parent =
utils::path::get_parent_api_path(dir_item.api_path);
dir_item.directory = directory;
dir_item.size = get_size(dir_item);
meta_provider(dir_item);
result.emplace_back(std::move(dir_item));
};
auto node_list =
@ -275,7 +280,7 @@ auto list_objects_in_directory_request_impl(
node_list = doc.select_nodes("/ListBucketResult/Contents");
for (const auto &node : node_list) {
auto child_object_name =
const auto *child_object_name =
node.node().select_node("Key").node().text().as_string();
if (child_object_name != prefix) {
auto size = node.node().select_node("Size").node().text().as_ullong();
@ -302,7 +307,7 @@ auto list_objects_request_impl(i_http_comm &client, const s3_config &config,
return false;
}
if (response_code != 200) {
if (response_code != http_error_codes::ok) {
return false;
}
@ -314,16 +319,16 @@ auto list_objects_request_impl(i_http_comm &client, const s3_config &config,
auto node_list = doc.select_nodes("/ListBucketResult/Contents");
for (const auto &node : node_list) {
auto object_name =
const auto *object_name =
node.node().select_node("Key").node().text().as_string();
auto size = node.node().select_node("Size").node().text().as_ullong();
directory_item di{};
di.api_path = utils::path::create_api_path(object_name);
di.api_parent = utils::path::get_parent_api_path(di.api_path);
di.directory = utils::string::ends_with(object_name, "/");
di.size = di.directory ? 0U : size;
di.resolved = false;
result.emplace_back(std::move(di));
directory_item dir_item{};
dir_item.api_path = utils::path::create_api_path(object_name);
dir_item.api_parent = utils::path::get_parent_api_path(dir_item.api_path);
dir_item.directory = utils::string::ends_with(object_name, "/");
dir_item.size = dir_item.directory ? 0U : size;
dir_item.resolved = false;
result.emplace_back(std::move(dir_item));
}
return true;

View File

@ -60,7 +60,8 @@ api_error fuse_drive::chflags_impl(std::string api_path, uint32_t flags) {
#if FUSE_USE_VERSION >= 30
auto fuse_drive::chmod_impl(std::string api_path, mode_t mode,
struct fuse_file_info * /*fi*/) -> api_error {
struct fuse_file_info * /*file_info*/)
-> api_error {
#else
auto fuse_drive::chmod_impl(std::string api_path, mode_t mode) -> api_error {
#endif
@ -71,7 +72,8 @@ auto fuse_drive::chmod_impl(std::string api_path, mode_t mode) -> api_error {
#if FUSE_USE_VERSION >= 30
auto fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid,
struct fuse_file_info * /*fi*/) -> api_error {
struct fuse_file_info * /*file_info*/)
-> api_error {
#else
auto fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid)
-> api_error {
@ -96,16 +98,18 @@ auto fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid)
}
auto fuse_drive::create_impl(std::string api_path, mode_t mode,
struct fuse_file_info *fi) -> api_error {
fi->fh = 0u;
struct fuse_file_info *file_info) -> api_error {
file_info->fh = 0U;
const auto is_directory_op = ((fi->flags & O_DIRECTORY) == O_DIRECTORY);
const auto is_create_op = ((fi->flags & O_CREAT) == O_CREAT);
const auto is_truncate_op =
((fi->flags & O_TRUNC) &&
((fi->flags & O_WRONLY) || (fi->flags & O_RDWR)));
const auto is_directory_op =
((file_info->flags & O_DIRECTORY) == O_DIRECTORY);
const auto is_create_op = ((file_info->flags & O_CREAT) == O_CREAT);
const auto is_truncate_op = (((file_info->flags & O_TRUNC) != 0) &&
(((file_info->flags & O_WRONLY) != 0) ||
((file_info->flags & O_RDWR) != 0)));
if ((fi->flags & O_WRONLY) || (fi->flags & O_RDWR)) {
if (((file_info->flags & O_WRONLY) != 0) ||
((file_info->flags & O_RDWR) != 0)) {
const auto res = provider_.is_file_writeable(api_path)
? api_error::success
: api_error::permission_denied;
@ -154,42 +158,42 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
}
}
std::uint64_t handle = 0u;
std::shared_ptr<i_open_file> f;
std::uint64_t handle{};
std::shared_ptr<i_open_file> open_file;
if (is_create_op) {
const auto now = utils::get_file_time_now();
#ifdef __APPLE__
const auto osx_flags = static_cast<std::uint32_t>(fi->flags);
const auto osx_flags = static_cast<std::uint32_t>(file_info->flags);
#else
const auto osx_flags = std::uint32_t(0u);
const auto osx_flags = 0U;
#endif
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now, now,
is_directory_op, "", get_effective_gid(), "", mode, now, 0u, osx_flags,
0u,
is_directory_op, "", get_effective_gid(), "", mode, now, 0U, osx_flags,
0U,
utils::path::combine(config_.get_cache_directory(),
{utils::create_uuid_string()}),
get_effective_uid(), now);
res = fm_->create(api_path, meta, fi->flags, handle, f);
res = fm_->create(api_path, meta, file_info->flags, handle, open_file);
if ((res != api_error::item_exists) && (res != api_error::success)) {
return res;
}
} else if (((res = fm_->open(api_path, is_directory_op, fi->flags, handle,
f)) != api_error::success)) {
} else if (((res = fm_->open(api_path, is_directory_op, file_info->flags,
handle, open_file)) != api_error::success)) {
return res;
}
fi->fh = handle;
file_info->fh = handle;
if (is_truncate_op) {
#if FUSE_USE_VERSION >= 30
if ((res = truncate_impl(api_path, 0, fi)) != api_error::success) {
if ((res = truncate_impl(api_path, 0, file_info)) != api_error::success) {
#else
if ((res = ftruncate_impl(api_path, 0, fi)) != api_error::success) {
if ((res = ftruncate_impl(api_path, 0, file_info)) != api_error::success) {
#endif
fm_->close(handle);
fi->fh = 0u;
file_info->fh = 0U;
errno = std::abs(utils::from_api_error(res));
return res;
}
@ -198,7 +202,7 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
return api_error::success;
}
void fuse_drive::destroy_impl(void *) {
void fuse_drive::destroy_impl(void * /* ptr */) {
event_system::instance().raise<drive_unmount_pending>(get_mount_location());
remote_server_.reset();
@ -240,21 +244,21 @@ void fuse_drive::destroy_impl(void *) {
auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
off_t offset, off_t length,
struct fuse_file_info *fi) -> api_error {
std::shared_ptr<i_open_file> f;
if (not fm_->get_open_file(fi->fh, true, f)) {
struct fuse_file_info *file_info) -> api_error {
std::shared_ptr<i_open_file> open_file;
if (not fm_->get_open_file(file_info->fh, true, open_file)) {
return api_error::invalid_handle;
}
auto res =
check_writeable(f->get_open_data(fi->fh), api_error::invalid_handle);
auto res = check_writeable(open_file->get_open_data(file_info->fh),
api_error::invalid_handle);
if (res != api_error::success) {
return res;
}
if ((res = check_open_flags(f->get_open_data(fi->fh), O_WRONLY | O_APPEND,
api_error::invalid_handle)) !=
api_error::success) {
if ((res = check_open_flags(
open_file->get_open_data(file_info->fh), O_WRONLY | O_APPEND,
api_error::invalid_handle)) != api_error::success) {
return res;
}
@ -294,13 +298,14 @@ auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
};
#endif // __APPLE__
return f->native_operation(offset + length, allocator);
return open_file->native_operation(
static_cast<std::uint64_t>(offset + length), allocator);
}
auto fuse_drive::fgetattr_impl(std::string api_path, struct stat *st,
struct fuse_file_info *fi) -> api_error {
std::shared_ptr<i_open_file> f;
if (not fm_->get_open_file(fi->fh, false, f)) {
struct fuse_file_info *file_info) -> api_error {
std::shared_ptr<i_open_file> open_file;
if (not fm_->get_open_file(file_info->fh, false, open_file)) {
return api_error::invalid_handle;
}
@ -315,17 +320,18 @@ auto fuse_drive::fgetattr_impl(std::string api_path, struct stat *st,
if (res != api_error::success) {
return res;
}
fuse_drive_base::populate_stat(api_path, f->get_file_size(), meta, directory,
provider_, st);
fuse_drive_base::populate_stat(api_path, open_file->get_file_size(), meta,
directory, provider_, st);
return api_error::success;
}
#ifdef __APPLE__
auto fuse_drive::fsetattr_x_impl(std::string api_path, struct setattr_x *attr,
struct fuse_file_info *fi) -> api_error {
struct fuse_file_info *file_info)
-> api_error {
std::shared_ptr<i_open_file> f;
if (not fm_->get_open_file(fi->fh, false, f)) {
if (not fm_->get_open_file(file_info->fh, false, f)) {
return api_error::invalid_handle;
}
@ -334,13 +340,13 @@ auto fuse_drive::fsetattr_x_impl(std::string api_path, struct setattr_x *attr,
#endif // __APPLE__
auto fuse_drive::fsync_impl(std::string /*api_path*/, int datasync,
struct fuse_file_info *fi) -> api_error {
std::shared_ptr<i_open_file> f;
if (not fm_->get_open_file(fi->fh, false, f)) {
struct fuse_file_info *file_info) -> api_error {
std::shared_ptr<i_open_file> open_file;
if (not fm_->get_open_file(file_info->fh, false, open_file)) {
return api_error::invalid_handle;
}
return f->native_operation([&datasync](int handle) -> api_error {
return open_file->native_operation([&datasync](int handle) -> api_error {
if (handle != REPERTORY_INVALID_HANDLE) {
#ifdef __APPLE__
if ((datasync ? fcntl(handle, F_FULLFSYNC) : fsync(handle)) == -1) {
@ -356,14 +362,14 @@ auto fuse_drive::fsync_impl(std::string /*api_path*/, int datasync,
#if FUSE_USE_VERSION < 30
api_error fuse_drive::ftruncate_impl(std::string /*api_path*/, off_t size,
struct fuse_file_info *fi) {
struct fuse_file_info *file_info) {
std::shared_ptr<i_open_file> f;
if (not fm_->get_open_file(fi->fh, true, f)) {
if (not fm_->get_open_file(file_info->fh, true, f)) {
return api_error::invalid_handle;
}
const auto res =
check_writeable(f->get_open_data(fi->fh), api_error::invalid_handle);
const auto res = check_writeable(f->get_open_data(file_info->fh),
api_error::invalid_handle);
if (res != api_error::success) {
return res;
}
@ -379,14 +385,14 @@ auto fuse_drive::get_directory_item_count(const std::string &api_path) const
auto fuse_drive::get_directory_items(const std::string &api_path) const
-> directory_item_list {
directory_item_list di{};
auto res = provider_.get_directory_items(api_path, di);
directory_item_list list{};
auto res = provider_.get_directory_items(api_path, list);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
"failed to get directory items");
}
return di;
return list;
}
auto fuse_drive::get_file_size(const std::string &api_path) const
@ -420,7 +426,8 @@ auto fuse_drive::get_item_meta(const std::string &api_path,
#if FUSE_USE_VERSION >= 30
auto fuse_drive::getattr_impl(std::string api_path, struct stat *st,
struct fuse_file_info * /*fi*/) -> api_error {
struct fuse_file_info * /*file_info*/)
-> api_error {
#else
auto fuse_drive::getattr_impl(std::string api_path, struct stat *st)
-> api_error {
@ -434,11 +441,11 @@ auto fuse_drive::getattr_impl(std::string api_path, struct stat *st)
auto found = false;
directory_cache_->execute_action(parent, [&](directory_iterator &iter) {
directory_item di{};
if ((found =
(iter.get_directory_item(api_path, di) == api_error::success))) {
fuse_drive_base::populate_stat(api_path, di.size, di.meta, di.directory,
provider_, st);
directory_item dir_item{};
if ((found = (iter.get_directory_item(api_path, dir_item) ==
api_error::success))) {
fuse_drive_base::populate_stat(api_path, dir_item.size, dir_item.meta,
dir_item.directory, provider_, st);
}
});
@ -584,7 +591,7 @@ auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
const auto now = utils::get_file_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_DIRECTORY, now, now, true, "", get_effective_gid(),
"", mode, now, 0u, 0u, 0u, "", get_effective_uid(), now);
"", mode, now, 0U, 0U, 0U, "", get_effective_uid(), now);
if ((res = provider_.create_directory(api_path, meta)) !=
api_error::success) {
return res;
@ -611,15 +618,16 @@ void fuse_drive::notify_fuse_main_exit(int &ret) {
}
}
auto fuse_drive::open_impl(std::string api_path, struct fuse_file_info *fi)
-> api_error {
fi->flags &= (~O_CREAT);
return create_impl(api_path, 0, fi);
auto fuse_drive::open_impl(std::string api_path,
struct fuse_file_info *file_info) -> api_error {
file_info->flags &= (~O_CREAT);
return create_impl(api_path, 0, file_info);
}
auto fuse_drive::opendir_impl(std::string api_path, struct fuse_file_info *fi)
-> api_error {
const auto mask = (O_RDONLY != (fi->flags & O_ACCMODE) ? W_OK : R_OK) | X_OK;
auto fuse_drive::opendir_impl(std::string api_path,
struct fuse_file_info *file_info) -> api_error {
const auto mask =
(O_RDONLY != (file_info->flags & O_ACCMODE) ? W_OK : R_OK) | X_OK;
auto res = check_access(api_path, mask);
if (res != api_error::success) {
return res;
@ -638,35 +646,36 @@ auto fuse_drive::opendir_impl(std::string api_path, struct fuse_file_info *fi)
return api_error::directory_not_found;
}
directory_item_list dl{};
if ((res = provider_.get_directory_items(api_path, dl)) !=
directory_item_list list{};
if ((res = provider_.get_directory_items(api_path, list)) !=
api_error::success) {
return res;
}
auto *iter = new directory_iterator(std::move(dl));
fi->fh = reinterpret_cast<std::uint64_t>(iter);
auto *iter = new directory_iterator(std::move(list));
file_info->fh = reinterpret_cast<std::uint64_t>(iter);
directory_cache_->set_directory(api_path, iter);
return api_error::success;
}
void fuse_drive::populate_stat(const directory_item &di,
void fuse_drive::populate_stat(const directory_item &dir_item,
struct stat &st) const {
fuse_drive_base::populate_stat(di.api_path, di.size, di.meta, di.directory,
provider_, &st);
fuse_drive_base::populate_stat(dir_item.api_path, dir_item.size,
dir_item.meta, dir_item.directory, provider_,
&st);
}
auto fuse_drive::read_impl(std::string api_path, char *buffer, size_t read_size,
off_t read_offset, struct fuse_file_info *fi,
off_t read_offset, struct fuse_file_info *file_info,
std::size_t &bytes_read) -> api_error {
std::shared_ptr<i_open_file> f;
if (not fm_->get_open_file(fi->fh, false, f)) {
std::shared_ptr<i_open_file> open_file;
if (not fm_->get_open_file(file_info->fh, false, open_file)) {
return api_error::item_not_found;
}
auto res =
check_readable(f->get_open_data(fi->fh), api_error::invalid_handle);
auto res = check_readable(open_file->get_open_data(file_info->fh),
api_error::invalid_handle);
if (res != api_error::success) {
return res;
}
@ -675,11 +684,12 @@ auto fuse_drive::read_impl(std::string api_path, char *buffer, size_t read_size,
// __FUNCTION__, api_path, std::to_string(read_size) + ':' +
// std::to_string(read_offset));
data_buffer data;
res = f->read(read_size, static_cast<std::uint64_t>(read_offset), data);
res =
open_file->read(read_size, static_cast<std::uint64_t>(read_offset), data);
// event_system::instance().raise<debug_log>(
// __FUNCTION__, api_path, std::to_string(bytes_read) + ':' +
// api_error_to_string(res));
if ((bytes_read = data.size())) {
if ((bytes_read = data.size()) != 0U) {
std::memcpy(buffer, data.data(), data.size());
data.clear();
update_accessed_time(api_path);
@ -691,20 +701,20 @@ auto fuse_drive::read_impl(std::string api_path, char *buffer, size_t read_size,
#if FUSE_USE_VERSION >= 30
auto fuse_drive::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 {
#else
auto fuse_drive::readdir_impl(std::string api_path, void *buf,
fuse_fill_dir_t fuse_fill_dir, off_t offset,
struct fuse_file_info *fi) -> api_error {
struct fuse_file_info *file_info) -> api_error {
#endif
auto res = check_access(api_path, X_OK);
if (res != api_error::success) {
return res;
}
auto *iter = reinterpret_cast<directory_iterator *>(fi->fh);
if (not iter) {
auto *iter = reinterpret_cast<directory_iterator *>(file_info->fh);
if (iter == nullptr) {
return api_error::invalid_handle;
}
@ -730,15 +740,16 @@ auto fuse_drive::readdir_impl(std::string api_path, void *buf,
}
auto fuse_drive::release_impl(std::string /*api_path*/,
struct fuse_file_info *fi) -> api_error {
fm_->close(fi->fh);
struct fuse_file_info *file_info) -> api_error {
fm_->close(file_info->fh);
return api_error::success;
}
auto fuse_drive::releasedir_impl(std::string /*api_path*/,
struct fuse_file_info *fi) -> api_error {
auto *iter = reinterpret_cast<directory_iterator *>(fi->fh);
if (not iter) {
struct fuse_file_info *file_info)
-> api_error {
auto *iter = reinterpret_cast<directory_iterator *>(file_info->fh);
if (iter == nullptr) {
return api_error::invalid_handle;
}
@ -808,9 +819,7 @@ auto fuse_drive::rmdir_impl(std::string api_path) -> api_error {
}
auto *iter = directory_cache_->remove_directory(api_path);
if (iter) {
delete iter;
}
return api_error::success;
}
@ -841,10 +850,10 @@ auto fuse_drive::getxattr_common(std::string api_path, const char *name,
directory_cache_->execute_action(
utils::path::get_parent_api_path(api_path),
[&](directory_iterator &iterator) {
directory_item di{};
if ((found = (iterator.get_directory_item(api_path, di) ==
directory_item dir_item{};
if ((found = (iterator.get_directory_item(api_path, dir_item) ==
api_error::success))) {
meta = di.meta;
meta = dir_item.meta;
}
});
@ -853,13 +862,13 @@ auto fuse_drive::getxattr_common(std::string api_path, const char *name,
res = api_error::xattr_not_found;
if (meta.find(attribute_name) != meta.end()) {
const auto data = macaron::Base64::Decode(meta[attribute_name]);
if (not position || (*position < data.size())) {
if ((position == nullptr) || (*position < data.size())) {
res = api_error::success;
attribute_size = static_cast<int>(data.size());
if (size) {
if (size != 0U) {
res = api_error::xattr_buffer_small;
if (size >= data.size()) {
memcpy(value, &data[0], data.size());
memcpy(value, data.data(), data.size());
return api_error::success;
}
}
@ -897,13 +906,13 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
api_meta_map meta;
if ((res = provider_.get_item_meta(api_path, meta)) == api_error::success) {
for (const auto &kv : meta) {
if (utils::collection_excludes(META_USED_NAMES, kv.first)) {
auto attribute_name = kv.first;
for (const auto &meta_item : meta) {
if (utils::collection_excludes(META_USED_NAMES, meta_item.first)) {
auto attribute_name = meta_item.first;
#ifdef __APPLE__
if (attribute_name != G_KAUTH_FILESEC_XATTR) {
#endif
const auto attribute_name_size = strlen(attribute_name.c_str()) + 1u;
const auto attribute_name_size = strlen(attribute_name.c_str()) + 1U;
if (size >= attribute_name_size) {
strncpy(&buffer[required_size], attribute_name.c_str(),
attribute_name_size);
@ -972,7 +981,7 @@ auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
const auto attribute_namespace =
utils::string::contains(attribute_name, ".")
? utils::string::split(attribute_name, '.', false)[0u]
? utils::string::split(attribute_name, '.', false)[0U]
: "";
if ((attribute_name.size() > XATTR_NAME_MAX) || (size > XATTR_SIZE_MAX)) {
return api_error::xattr_too_big;
@ -1192,7 +1201,7 @@ auto fuse_drive::statfs_x_impl(std::string /*api_path*/, struct statfs *stbuf)
#else // __APPLE__
auto fuse_drive::statfs_impl(std::string /*api_path*/, struct statvfs *stbuf)
-> api_error {
if (statvfs(&config_.get_cache_directory()[0], stbuf) != 0) {
if (statvfs(config_.get_cache_directory().data(), stbuf) != 0) {
return api_error::os_error;
}
@ -1204,7 +1213,7 @@ auto fuse_drive::statfs_impl(std::string /*api_path*/, struct statvfs *stbuf)
stbuf->f_blocks = utils::divide_with_ceiling(
total_bytes, static_cast<std::uint64_t>(stbuf->f_frsize));
stbuf->f_bavail = stbuf->f_bfree =
stbuf->f_blocks ? (stbuf->f_blocks - used_blocks) : 0;
stbuf->f_blocks == 0U ? 0 : (stbuf->f_blocks - used_blocks);
stbuf->f_ffree = stbuf->f_favail =
stbuf->f_files - provider_.get_total_item_count();
@ -1214,7 +1223,8 @@ auto fuse_drive::statfs_impl(std::string /*api_path*/, struct statvfs *stbuf)
#if FUSE_USE_VERSION >= 30
auto fuse_drive::truncate_impl(std::string api_path, off_t size,
struct fuse_file_info * /*fi*/) -> api_error {
struct fuse_file_info * /*file_info*/)
-> api_error {
#else
auto fuse_drive::truncate_impl(std::string api_path, off_t size) -> api_error {
#endif
@ -1234,9 +1244,9 @@ auto fuse_drive::truncate_impl(std::string api_path, off_t size) -> api_error {
}
open_file_data ofd = O_RDWR;
std::uint64_t handle = 0u;
std::shared_ptr<i_open_file> f;
if ((res = fm_->open(api_path, false, ofd, handle, f)) !=
std::uint64_t handle{};
std::shared_ptr<i_open_file> open_file;
if ((res = fm_->open(api_path, false, ofd, handle, open_file)) !=
api_error::success) {
return res;
}
@ -1246,7 +1256,7 @@ auto fuse_drive::truncate_impl(std::string api_path, off_t size) -> api_error {
return err;
};
return cleanup(f->resize(size));
return cleanup(open_file->resize(static_cast<std::uint64_t>(size)));
}
auto fuse_drive::unlink_impl(std::string api_path) -> api_error {
@ -1269,7 +1279,8 @@ auto fuse_drive::unlink_impl(std::string api_path) -> api_error {
#if FUSE_USE_VERSION >= 30
auto fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2],
struct fuse_file_info * /*fi*/) -> api_error {
struct fuse_file_info * /*file_info*/)
-> api_error {
#else
auto fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2])
-> api_error {
@ -1285,17 +1296,17 @@ auto fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2])
}
meta.clear();
if (not tv || (tv[0].tv_nsec == UTIME_NOW)) {
if ((tv == nullptr) || (tv[0U].tv_nsec == UTIME_NOW)) {
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
} else if (tv[0].tv_nsec != UTIME_OMIT) {
const auto val = tv[0].tv_nsec + (tv[0].tv_sec * NANOS_PER_SECOND);
} else if (tv[0U].tv_nsec != UTIME_OMIT) {
const auto val = tv[0U].tv_nsec + (tv[0U].tv_sec * NANOS_PER_SECOND);
meta[META_ACCESSED] = std::to_string(val);
}
if (not tv || (tv[1].tv_nsec == UTIME_NOW)) {
if ((tv == nullptr) || (tv[1U].tv_nsec == UTIME_NOW)) {
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
} else if (tv[1].tv_nsec != UTIME_OMIT) {
const auto val = tv[1].tv_nsec + (tv[1].tv_sec * NANOS_PER_SECOND);
} else if (tv[1U].tv_nsec != UTIME_OMIT) {
const auto val = tv[1U].tv_nsec + (tv[1U].tv_sec * NANOS_PER_SECOND);
meta[META_MODIFIED] = std::to_string(val);
}
@ -1309,28 +1320,29 @@ auto fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2])
auto fuse_drive::write_impl(std::string /*api_path*/
,
const char *buffer, size_t write_size,
off_t write_offset, struct fuse_file_info *fi,
off_t write_offset,
struct fuse_file_info *file_info,
std::size_t &bytes_written) -> api_error {
std::shared_ptr<i_open_file> f;
if (not fm_->get_open_file(fi->fh, true, f)) {
std::shared_ptr<i_open_file> open_file;
if (not fm_->get_open_file(file_info->fh, true, open_file)) {
return api_error::item_not_found;
}
auto res =
check_writeable(f->get_open_data(fi->fh), api_error::invalid_handle);
auto res = check_writeable(open_file->get_open_data(file_info->fh),
api_error::invalid_handle);
if (res != api_error::success) {
return res;
}
if (write_size > 0) {
if (f->get_open_data(fi->fh) & O_APPEND) {
write_offset = f->get_file_size();
if ((open_file->get_open_data(file_info->fh) & O_APPEND) != 0) {
write_offset = static_cast<off_t>(open_file->get_file_size());
}
data_buffer data(write_size);
std::memcpy(&data[0], buffer, write_size);
return f->write(static_cast<std::uint64_t>(write_offset), std::move(data),
bytes_written);
std::memcpy(data.data(), buffer, write_size);
return open_file->write(static_cast<std::uint64_t>(write_offset),
std::move(data), bytes_written);
}
return api_error::success;

View File

@ -602,18 +602,20 @@ auto remote_server::fuse_read(const char *path, char *buffer,
-> packet::error_type {
const auto file_path = construct_path(path);
auto &data = *reinterpret_cast<data_buffer *>(buffer);
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
if (res == 0) {
ssize_t bytes_read{has_open_info(static_cast<native_handle>(handle), EBADF)};
if (bytes_read == 0) {
data.resize(read_size);
res = pread64(static_cast<native_handle>(handle), data.data(), read_size,
static_cast<off_t>(read_offset));
bytes_read = pread64(static_cast<native_handle>(handle), data.data(),
read_size, static_cast<off_t>(read_offset));
}
auto ret = ((res < 0) ? -errno : res);
auto ret = ((bytes_read < 0) ? -errno : bytes_read);
if (ret < 0) {
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, file_path, ret);
}
return ret;
return static_cast<packet::error_type>(ret);
}
auto remote_server::fuse_rename(const char *from, const char *to)
@ -638,7 +640,7 @@ auto remote_server::fuse_readdir(const char *path,
res = -1;
} else {
auto *iterator = reinterpret_cast<directory_iterator *>(handle);
if (iterator) {
if (iterator != nullptr) {
res = iterator->get(static_cast<std::size_t>(offset), item_path);
} else {
res = -1;
@ -699,7 +701,7 @@ auto remote_server::fuse_rmdir(const char *path) -> packet::error_type {
const auto file_path = construct_path(path);
const auto res = rmdir(file_path.c_str());
if (res == 0) {
auto iterator =
auto *iterator =
directory_cache_.remove_directory(utils::path::create_api_path(path));
if (iterator == nullptr) {
utils::error::raise_error(
@ -892,17 +894,20 @@ auto remote_server::fuse_write(const char *path, const char *buffer,
const remote::file_handle &handle)
-> packet::error_type {
const auto file_path = construct_path(path);
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
if (res == 0) {
res = pwrite64(static_cast<native_handle>(handle), buffer, write_size,
static_cast<off_t>(write_offset));
ssize_t bytes_written{
has_open_info(static_cast<native_handle>(handle), EBADF)};
if (bytes_written == 0) {
bytes_written = pwrite64(static_cast<native_handle>(handle), buffer,
write_size, static_cast<off_t>(write_offset));
}
auto ret = ((res < 0) ? -errno : res);
auto ret = ((bytes_written < 0) ? -errno : bytes_written);
if (ret < 0) {
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, file_path, ret);
}
return ret;
return static_cast<packet::error_type>(ret);
}
auto remote_server::fuse_write_base64(
@ -1012,7 +1017,7 @@ auto remote_server::winfsp_close(PVOID file_desc) -> packet::error_type {
auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, UINT32 attributes,
UINT64 /*allocationSize*/, PVOID *file_desc,
UINT64 /*allocation_size*/, PVOID *file_desc,
remote::file_info *file_info,
std::string &normalized_name, BOOLEAN &exists)
-> packet::error_type {
@ -1098,8 +1103,8 @@ auto remote_server::winfsp_get_file_info(PVOID file_desc,
auto remote_server::winfsp_get_security_by_name(
PWSTR file_name, PUINT32 attributes,
std::uint64_t * /*securityDescriptorSize*/,
std::wstring & /*strDescriptor*/) -> packet::error_type {
std::uint64_t * /*security_descriptor_size*/,
std::wstring & /*str_descriptor*/) -> packet::error_type {
auto ret = STATUS_SUCCESS;
const auto file_path = construct_path(file_name);
if (utils::file::is_file(file_path) ||
@ -1173,7 +1178,7 @@ auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options,
auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
BOOLEAN replace_attributes,
UINT64 /*allocationSize*/,
UINT64 /*allocation_size*/,
remote::file_info *file_info)
-> packet::error_type {
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1234,7 +1239,8 @@ auto remote_server::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
auto ret =
has_open_info(static_cast<native_handle>(handle), STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) {
const auto res = pread64(handle, buffer, length, offset);
const auto res = pread64(static_cast<native_handle>(handle), buffer, length,
static_cast<off_t>(offset));
if (res >= 0) {
*bytes_transferred = static_cast<UINT32>(res);
} else {
@ -1434,7 +1440,8 @@ auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
if (should_write) {
if (length > 0) {
const auto res = pwrite64(handle, buffer, length, offset);
const auto res = pwrite64(static_cast<native_handle>(handle), buffer,
length, static_cast<off_t>(offset));
if (res >= 0) {
*bytes_transferred = static_cast<UINT32>(res);
ret = populate_file_info(construct_api_path(get_open_file_path(
@ -1486,8 +1493,8 @@ auto remote_server::json_read_directory_snapshot(
std::uint32_t page, json &json_data) -> packet::error_type {
const auto file_path = construct_path(path);
auto *iterator = reinterpret_cast<directory_iterator *>(handle);
std::size_t offset = 0u;
int res;
std::size_t offset{};
int res{};
json item_json;
while ((json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) &&
(res = iterator->get_json(

View File

@ -260,8 +260,8 @@ VOID winfsp_drive::Close(PVOID /*file_node*/, PVOID file_desc) {
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, 0);
}
auto winfsp_drive::Create(PWSTR fileName, UINT32 create_options,
UINT32 /*grantedAccess*/, UINT32 attributes,
auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
UINT32 /*granted_access*/, UINT32 attributes,
PSECURITY_DESCRIPTOR /*descriptor*/,
UINT64 /*allocation_size*/, PVOID * /*file_node*/,
PVOID *file_desc, OpenFileInfo *ofi) -> NTSTATUS {
@ -290,7 +290,7 @@ auto winfsp_drive::Create(PWSTR fileName, UINT32 create_options,
0U, now);
const auto api_path =
utils::path::create_api_path(utils::string::to_utf8(fileName));
utils::path::create_api_path(utils::string::to_utf8(file_name));
open_file_data ofd{};
std::uint64_t handle{};
@ -315,7 +315,7 @@ auto winfsp_drive::Create(PWSTR fileName, UINT32 create_options,
}
auto winfsp_drive::Flush(PVOID /*file_node*/, PVOID file_desc,
FileInfo *fileInfo) -> NTSTATUS {
FileInfo *file_info) -> NTSTATUS {
std::string api_path;
auto error = api_error::success;
auto handle =
@ -336,7 +336,7 @@ auto winfsp_drive::Flush(PVOID /*file_node*/, PVOID file_desc,
// Populate file information
api_meta_map meta;
if (provider_.get_item_meta(api_path, meta) == api_error::success) {
populate_file_info(f->get_file_size(), meta, *fileInfo);
populate_file_info(f->get_file_size(), meta, *file_info);
}
}
}
@ -363,7 +363,7 @@ auto winfsp_drive::get_directory_items(const std::string &api_path) const
}
auto winfsp_drive::GetFileInfo(PVOID /*file_node*/, PVOID file_desc,
FileInfo *fileInfo) -> NTSTATUS {
FileInfo *file_info) -> NTSTATUS {
std::string api_path;
auto error = api_error::invalid_handle;
auto handle =
@ -375,7 +375,7 @@ auto winfsp_drive::GetFileInfo(PVOID /*file_node*/, PVOID file_desc,
api_meta_map meta;
if ((error = provider_.get_item_meta(api_path, meta)) ==
api_error::success) {
populate_file_info(f->get_file_size(), meta, *fileInfo);
populate_file_info(f->get_file_size(), meta, *file_info);
}
}
}
@ -414,12 +414,12 @@ auto winfsp_drive::get_item_meta(const std::string &api_path,
return ret;
}
auto winfsp_drive::get_security_by_name(PWSTR fileName, PUINT32 attributes,
auto winfsp_drive::get_security_by_name(PWSTR file_name, PUINT32 attributes,
PSECURITY_DESCRIPTOR descriptor,
std::uint64_t *descriptor_size)
-> NTSTATUS {
const auto api_path =
utils::path::create_api_path(utils::string::to_utf8(fileName));
utils::path::create_api_path(utils::string::to_utf8(file_name));
api_meta_map meta{};
auto error = provider_.get_item_meta(api_path, meta);
@ -451,13 +451,13 @@ auto winfsp_drive::get_security_by_name(PWSTR fileName, PUINT32 attributes,
return utils::from_api_error(error);
}
auto winfsp_drive::GetSecurityByName(PWSTR fileName, PUINT32 attributes,
auto winfsp_drive::GetSecurityByName(PWSTR file_name, PUINT32 attributes,
PSECURITY_DESCRIPTOR descriptor,
SIZE_T *descriptor_size) -> NTSTATUS {
const auto api_path =
utils::path::create_api_path(utils::string::to_utf8(fileName));
utils::path::create_api_path(utils::string::to_utf8(file_name));
std::uint64_t sds = descriptor_size ? *descriptor_size : 0U;
auto ret = get_security_by_name(fileName, attributes, descriptor,
auto ret = get_security_by_name(file_name, attributes, descriptor,
sds > 0U ? &sds : nullptr);
if (sds) {
*descriptor_size = static_cast<SIZE_T>(sds);
@ -939,7 +939,7 @@ auto winfsp_drive::Rename(PVOID /*file_node*/, PVOID /*file_desc*/,
auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
UINT32 attributes, UINT64 creation_time,
UINT64 last_access_time, UINT64 last_write_time,
UINT64 change_time, FileInfo *fileInfo)
UINT64 change_time, FileInfo *file_info)
-> NTSTATUS {
std::string api_path;
auto error = api_error::invalid_handle;
@ -983,7 +983,7 @@ auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
// Populate file information
if (provider_.get_item_meta(api_path, meta) == api_error::success) {
populate_file_info(utils::string::to_uint64(meta[META_SIZE]), meta,
*fileInfo);
*file_info);
}
}
}

View File

@ -35,29 +35,30 @@ namespace repertory {
file_manager::open_file::open_file(std::uint64_t chunk_size,
std::uint8_t chunk_timeout,
filesystem_item fsi, i_provider &provider,
i_upload_manager &um)
i_upload_manager &mgr)
: open_file(chunk_size, chunk_timeout, fsi, {}, provider, std::nullopt,
um) {}
mgr) {}
file_manager::open_file::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_upload_manager &mgr)
: open_file(chunk_size, chunk_timeout, fsi, open_data, provider,
std::nullopt, um) {}
std::nullopt, mgr) {}
file_manager::open_file::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)
: open_file(chunk_size, chunk_timeout, fsi, {}, provider, read_state, um) {}
i_upload_manager &mgr)
: open_file(chunk_size, chunk_timeout, fsi, {}, provider, read_state, mgr) {
}
file_manager::open_file::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,
std::optional<boost::dynamic_bitset<>> read_state, i_upload_manager &um)
std::optional<boost::dynamic_bitset<>> read_state, i_upload_manager &mgr)
: open_file_base(chunk_size, chunk_timeout, fsi, open_data, provider),
um_(um) {
mgr_(mgr) {
if (fsi_.directory && read_state.has_value()) {
throw startup_exception("cannot resume a directory|" + fsi.api_path);
}
@ -68,9 +69,9 @@ file_manager::open_file::open_file(
if (get_api_error() == api_error::success) {
if (read_state.has_value()) {
modified_ = true;
um_.store_resume(*this);
mgr_.store_resume(*this);
read_state_ = read_state.value();
} else if (fsi_.size > 0u) {
} else if (fsi_.size > 0U) {
read_state_.resize(static_cast<std::size_t>(utils::divide_with_ceiling(
fsi_.size, chunk_size)),
false);
@ -78,7 +79,7 @@ file_manager::open_file::open_file(
std::uint64_t file_size{};
if (nf_->get_file_size(file_size)) {
if (provider_.is_direct_only() || file_size == fsi.size) {
read_state_.set(0u, read_state_.size(), true);
read_state_.set(0U, read_state_.size(), true);
} else if (not nf_->truncate(fsi.size)) {
set_api_error(api_error::os_error);
}
@ -119,8 +120,8 @@ void file_manager::open_file::download_chunk(std::size_t chunk,
const auto data_offset = chunk * chunk_size_;
const auto data_size =
(chunk == read_state_.size() - 1u) ? last_chunk_size_ : chunk_size_;
if (active_downloads_.empty() && (read_state_.count() == 0u)) {
(chunk == read_state_.size() - 1U) ? last_chunk_size_ : chunk_size_;
if (active_downloads_.empty() && (read_state_.count() == 0U)) {
event_system::instance().raise<download_begin>(fsi_.api_path,
fsi_.source_path);
}
@ -237,19 +238,19 @@ auto file_manager::open_file::is_complete() const -> bool {
}
auto file_manager::open_file::native_operation(
const i_open_file::native_operation_callback &operation) -> api_error {
const i_open_file::native_operation_callback &callback) -> api_error {
unique_recur_mutex_lock file_lock(file_mtx_);
if (stop_requested_) {
return api_error::download_stopped;
}
file_lock.unlock();
return do_io([&]() -> api_error { return operation(nf_->get_handle()); });
return do_io([&]() -> api_error { return callback(nf_->get_handle()); });
}
auto file_manager::open_file::native_operation(
std::uint64_t new_file_size,
const i_open_file::native_operation_callback &operation) -> api_error {
const i_open_file::native_operation_callback &callback) -> api_error {
if (fsi_.directory) {
return api_error::invalid_operation;
}
@ -260,17 +261,17 @@ auto file_manager::open_file::native_operation(
}
file_lock.unlock();
const auto is_empty_file = new_file_size == 0u;
const auto is_empty_file = new_file_size == 0U;
const auto last_chunk =
is_empty_file ? std::size_t(0u)
is_empty_file ? std::size_t(0U)
: static_cast<std::size_t>(utils::divide_with_ceiling(
new_file_size, chunk_size_)) -
1u;
1U;
file_lock.lock();
if (not is_empty_file && (last_chunk < read_state_.size())) {
file_lock.unlock();
update_background_reader(0u);
update_background_reader(0U);
download_chunk(last_chunk, false, true);
if (get_api_error() != api_error::success) {
@ -281,7 +282,7 @@ auto file_manager::open_file::native_operation(
const auto original_file_size = get_file_size();
auto res = do_io([&]() -> api_error { return operation(nf_->get_handle()); });
auto res = do_io([&]() -> api_error { return callback(nf_->get_handle()); });
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, get_api_path(),
utils::get_last_error_code(),
@ -308,8 +309,8 @@ auto file_manager::open_file::native_operation(
}
}
if (is_empty_file || (read_state_.size() != (last_chunk + 1u))) {
read_state_.resize(is_empty_file ? 0u : last_chunk + 1u);
if (is_empty_file || (read_state_.size() != (last_chunk + 1U))) {
read_state_.resize(is_empty_file ? 0U : last_chunk + 1U);
if (not is_empty_file) {
read_state_[last_chunk] = true;
@ -317,16 +318,16 @@ auto file_manager::open_file::native_operation(
last_chunk_size_ = static_cast<std::size_t>(
new_file_size <= chunk_size_ ? new_file_size
: new_file_size % chunk_size_ ? new_file_size % chunk_size_
: chunk_size_);
: (new_file_size % chunk_size_) == 0U ? chunk_size_
: new_file_size % chunk_size_);
}
if (original_file_size != new_file_size) {
if (not modified_) {
um_.store_resume(*this);
mgr_.store_resume(*this);
}
modified_ = true;
um_.remove_upload(get_api_path());
mgr_.remove_upload(get_api_path());
fsi_.size = new_file_size;
const auto now = std::to_string(utils::get_file_time_now());
@ -356,7 +357,7 @@ auto file_manager::open_file::read(std::size_t read_size,
read_size =
utils::calculate_read_size(get_file_size(), read_size, read_offset);
if (read_size == 0u) {
if (read_size == 0U) {
return api_error::success;
}
@ -405,7 +406,7 @@ void file_manager::open_file::remove(std::uint64_t handle) {
open_file_base::remove(handle);
if (modified_ && read_state_.all() &&
(get_api_error() == api_error::success)) {
um_.queue_upload(*this);
mgr_.queue_upload(*this);
modified_ = false;
}
}
@ -443,7 +444,7 @@ auto file_manager::open_file::close() -> bool {
err == api_error::download_stopped) {
if (modified_ && not read_state_.all()) {
set_api_error(api_error::download_incomplete);
} else if (not modified_ && (fsi_.size > 0u) &&
} else if (not modified_ && (fsi_.size > 0U) &&
not read_state_.all()) {
set_api_error(api_error::download_stopped);
}
@ -454,12 +455,12 @@ auto file_manager::open_file::close() -> bool {
nf_.reset();
if (modified_ && (get_api_error() == api_error::success)) {
um_.queue_upload(*this);
mgr_.queue_upload(*this);
} else if (modified_ &&
(get_api_error() == api_error::download_incomplete)) {
um_.store_resume(*this);
mgr_.store_resume(*this);
} else if (get_api_error() != api_error::success) {
um_.remove_resume(get_api_path(), get_source_path());
mgr_.remove_resume(get_api_path(), get_source_path());
if (not utils::file::retry_delete_file(fsi_.source_path)) {
utils::error::raise_api_path_error(
__FUNCTION__, get_api_path(), fsi_.source_path,
@ -494,7 +495,7 @@ void file_manager::open_file::update_background_reader(std::size_t read_chunk) {
std::size_t next_chunk{};
while (not stop_requested_) {
unique_recur_mutex_lock file_lock(file_mtx_);
if ((fsi_.size == 0u) || read_state_.all()) {
if ((fsi_.size == 0U) || read_state_.all()) {
file_lock.unlock();
unique_mutex_lock io_lock(io_thread_mtx_);
@ -506,10 +507,10 @@ void file_manager::open_file::update_background_reader(std::size_t read_chunk) {
} else {
do {
next_chunk = read_chunk_index_ =
((read_chunk_index_ + 1u) >= read_state_.size())
? 0u
: read_chunk_index_ + 1u;
} while ((next_chunk != 0u) && (active_downloads_.find(next_chunk) !=
((read_chunk_index_ + 1U) >= read_state_.size())
? 0U
: read_chunk_index_ + 1U;
} while ((next_chunk != 0U) && (active_downloads_.find(next_chunk) !=
active_downloads_.end()));
file_lock.unlock();
@ -523,7 +524,7 @@ void file_manager::open_file::update_background_reader(std::size_t read_chunk) {
auto file_manager::open_file::write(std::uint64_t write_offset,
const data_buffer &data,
std::size_t &bytes_written) -> api_error {
bytes_written = 0u;
bytes_written = 0U;
if (fsi_.directory || provider_.is_direct_only()) {
return api_error::invalid_operation;
@ -547,7 +548,7 @@ auto file_manager::open_file::write(std::uint64_t write_offset,
update_background_reader(start_chunk_index);
download_range(start_chunk_index,
std::min(read_state_.size() - 1u, end_chunk_index), true);
std::min(read_state_.size() - 1U, end_chunk_index), true);
if (get_api_error() != api_error::success) {
return get_api_error();
}
@ -586,10 +587,10 @@ auto file_manager::open_file::write(std::uint64_t write_offset,
}
if (not modified_) {
um_.store_resume(*this);
mgr_.store_resume(*this);
}
modified_ = true;
um_.remove_upload(get_api_path());
mgr_.remove_upload(get_api_path());
return api_error::success;
}

View File

@ -38,8 +38,8 @@ file_manager::open_file_base::open_file_base(
fsi_(std::move(fsi)),
last_chunk_size_(static_cast<std::size_t>(
fsi.size <= chunk_size ? fsi.size
: fsi.size % chunk_size ? fsi.size % chunk_size
: chunk_size)),
: (fsi.size % chunk_size) == 0U ? chunk_size
: fsi.size % chunk_size)),
open_data_(std::move(open_data)),
provider_(provider) {
if (not fsi.directory) {
@ -51,7 +51,7 @@ void file_manager::open_file_base::add(std::uint64_t handle,
open_file_data ofd) {
recur_mutex_lock file_lock(file_mtx_);
open_data_[handle] = ofd;
if (open_data_.size() == 1u) {
if (open_data_.size() == 1U) {
event_system::instance().raise<filesystem_item_opened>(
fsi_.api_path, fsi_.source_path, fsi_.directory);
}
@ -157,8 +157,8 @@ auto file_manager::open_file_base::get_handles() const
-> std::vector<std::uint64_t> {
recur_mutex_lock file_lock(file_mtx_);
std::vector<std::uint64_t> ret;
for (const auto &kv : open_data_) {
ret.emplace_back(kv.first);
for (const auto &item : open_data_) {
ret.emplace_back(item.first);
}
return ret;
@ -201,14 +201,14 @@ void file_manager::open_file_base::reset_timeout() {
last_access_ = std::chrono::system_clock::now();
}
auto file_manager::open_file_base::set_api_error(const api_error &e)
auto file_manager::open_file_base::set_api_error(const api_error &err)
-> api_error {
mutex_lock error_lock(error_mtx_);
if (error_ != e) {
if (error_ != err) {
return ((error_ = (error_ == api_error::success ||
error_ == api_error::download_incomplete ||
error_ == api_error::download_stopped
? e
? err
: error_)));
}

View File

@ -37,7 +37,7 @@ file_manager::ring_buffer_open_file::ring_buffer_open_file(
std::uint8_t chunk_timeout, filesystem_item fsi, i_provider &provider)
: ring_buffer_open_file(std::move(buffer_directory), chunk_size,
chunk_timeout, std::move(fsi), provider,
(1024ull * 1024ull * 1024ull) / chunk_size) {}
(1024ULL * 1024ULL * 1024ULL) / chunk_size) {}
file_manager::ring_buffer_open_file::ring_buffer_open_file(
std::string buffer_directory, std::uint64_t chunk_size,
@ -47,11 +47,11 @@ file_manager::ring_buffer_open_file::ring_buffer_open_file(
ring_state_(ring_size),
total_chunks_(static_cast<std::size_t>(
utils::divide_with_ceiling(fsi.size, chunk_size_))) {
if (ring_size % 2u) {
if ((ring_size % 2U) != 0U) {
throw std::runtime_error("ring size must be a multiple of 2");
}
if (ring_size < 4u) {
if (ring_size < 4U) {
throw std::runtime_error("ring size must be greater than or equal to 4");
}
@ -59,8 +59,8 @@ file_manager::ring_buffer_open_file::ring_buffer_open_file(
throw std::runtime_error("file size is less than ring buffer size");
}
last_chunk_ = ring_state_.size() - 1u;
ring_state_.set(0u, ring_state_.size(), true);
last_chunk_ = ring_state_.size() - 1U;
ring_state_.set(0U, ring_state_.size(), true);
buffer_directory = utils::path::absolute(buffer_directory);
if (not utils::file::create_full_directory_path(buffer_directory)) {
@ -113,7 +113,7 @@ auto file_manager::file_manager::ring_buffer_open_file::download_chunk(
chunk_notify_.notify_all();
chunk_lock.unlock();
data_buffer buffer((chunk == (total_chunks_ - 1u)) ? last_chunk_size_
data_buffer buffer((chunk == (total_chunks_ - 1U)) ? last_chunk_size_
: chunk_size_);
stop_type stop_requested = !!ring_state_[chunk % ring_state_.size()];
@ -149,8 +149,8 @@ auto file_manager::file_manager::ring_buffer_open_file::download_chunk(
void file_manager::ring_buffer_open_file::forward(std::size_t count) {
mutex_lock chunk_lock(chunk_mtx_);
if ((current_chunk_ + count) > (total_chunks_ - 1u)) {
count = (total_chunks_ - 1u) - current_chunk_;
if ((current_chunk_ + count) > (total_chunks_ - 1U)) {
count = (total_chunks_ - 1U) - current_chunk_;
}
if ((current_chunk_ + count) <= last_chunk_) {
@ -158,19 +158,19 @@ void file_manager::ring_buffer_open_file::forward(std::size_t count) {
} else {
const auto added = count - (last_chunk_ - current_chunk_);
if (added >= ring_state_.size()) {
ring_state_.set(0u, ring_state_.size(), true);
ring_state_.set(0U, ring_state_.size(), true);
current_chunk_ += count;
first_chunk_ += added;
last_chunk_ =
std::min(total_chunks_ - 1u, first_chunk_ + ring_state_.size() - 1u);
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
} else {
for (std::size_t i = 0u; i < added; i++) {
for (std::size_t i = 0U; i < added; i++) {
ring_state_[(first_chunk_ + i) % ring_state_.size()] = true;
}
first_chunk_ += added;
current_chunk_ += count;
last_chunk_ =
std::min(total_chunks_ - 1u, first_chunk_ + ring_state_.size() - 1u);
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
}
}
@ -195,8 +195,8 @@ auto file_manager::ring_buffer_open_file::is_download_complete() const -> bool {
}
auto file_manager::ring_buffer_open_file::native_operation(
const i_open_file::native_operation_callback &operation) -> api_error {
return do_io([&]() -> api_error { return operation(nf_->get_handle()); });
const i_open_file::native_operation_callback &callback) -> api_error {
return do_io([&]() -> api_error { return callback(nf_->get_handle()); });
}
void file_manager::ring_buffer_open_file::reverse(std::size_t count) {
@ -210,19 +210,19 @@ void file_manager::ring_buffer_open_file::reverse(std::size_t count) {
} else {
const auto removed = count - (current_chunk_ - first_chunk_);
if (removed >= ring_state_.size()) {
ring_state_.set(0u, ring_state_.size(), true);
ring_state_.set(0U, ring_state_.size(), true);
current_chunk_ -= count;
first_chunk_ = current_chunk_;
last_chunk_ =
std::min(total_chunks_ - 1u, first_chunk_ + ring_state_.size() - 1u);
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
} else {
for (std::size_t i = 0u; i < removed; i++) {
for (std::size_t i = 0U; i < removed; i++) {
ring_state_[(last_chunk_ - i) % ring_state_.size()] = true;
}
first_chunk_ -= removed;
current_chunk_ -= count;
last_chunk_ =
std::min(total_chunks_ - 1u, first_chunk_ + ring_state_.size() - 1u);
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
}
}
@ -239,7 +239,7 @@ auto file_manager::ring_buffer_open_file::read(std::size_t read_size,
reset_timeout();
read_size = utils::calculate_read_size(fsi_.size, read_size, read_offset);
if (read_size == 0u) {
if (read_size == 0U) {
return api_error::success;
}
@ -250,7 +250,7 @@ auto file_manager::ring_buffer_open_file::read(std::size_t read_size,
auto res = api_error::success;
for (std::size_t chunk = start_chunk_index;
(res == api_error::success) && (read_size > 0u); chunk++) {
(res == api_error::success) && (read_size > 0U); chunk++) {
if (chunk > current_chunk_) {
forward(chunk - current_chunk_);
} else if (chunk < current_chunk_) {
@ -277,7 +277,7 @@ auto file_manager::ring_buffer_open_file::read(std::size_t read_size,
return ret;
});
read_offset = 0u;
read_offset = 0U;
read_size -= to_read;
}
}
@ -294,7 +294,7 @@ void file_manager::ring_buffer_open_file::set(std::size_t first_chunk,
}
first_chunk_ = first_chunk;
last_chunk_ = first_chunk_ + ring_state_.size() - 1u;
last_chunk_ = first_chunk_ + ring_state_.size() - 1U;
if (current_chunk > last_chunk_) {
chunk_notify_.notify_all();
@ -303,7 +303,7 @@ void file_manager::ring_buffer_open_file::set(std::size_t first_chunk,
}
current_chunk_ = current_chunk;
ring_state_.set(0u, ring_state_.size(), false);
ring_state_.set(0U, ring_state_.size(), false);
chunk_notify_.notify_all();
}

View File

@ -51,11 +51,11 @@ public:
MOCK_METHOD(bool, is_directory, (), (const, override));
MOCK_METHOD(api_error, native_operation,
(const native_operation_callback &cb), (override));
(const native_operation_callback &callback), (override));
MOCK_METHOD(api_error, native_operation,
(std::uint64_t new_file_size,
const native_operation_callback &cb),
const native_operation_callback &callback),
(override));
MOCK_METHOD(api_error, read,

View File

@ -169,13 +169,13 @@ static void get_security_by_name_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
UINT32 attributes = 0u;
std::uint64_t securityDescriptorSize = 1024;
std::wstring strDescriptor;
std::uint64_t security_descriptor_size = 1024;
std::wstring str_descriptor;
ret = client.winfsp_get_security_by_name(
&api_path[0], &attributes, &securityDescriptorSize, strDescriptor);
&api_path[0], &attributes, &security_descriptor_size, str_descriptor);
EXPECT_EQ(STATUS_SUCCESS, ret);
EXPECT_EQ(static_cast<UINT32>(FILE_ATTRIBUTE_NORMAL), attributes);
EXPECT_FALSE(strDescriptor.empty());
EXPECT_FALSE(str_descriptor.empty());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
}