Address compiler warnings #10
This commit is contained in:
@@ -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)))
|
||||
? ""
|
||||
: ":" + std::to_string(hc.api_port);
|
||||
auto url = hc.protocol + "://" +
|
||||
utils::string::trim_copy(hc.host_name_or_ip) + custom_port;
|
||||
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(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 ¤t_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);
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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") ||
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
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;
|
||||
|
@@ -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(
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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,25 +309,25 @@ 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;
|
||||
}
|
||||
|
||||
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_ ? new_file_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;
|
||||
}
|
||||
|
@@ -37,9 +37,9 @@ file_manager::open_file_base::open_file_base(
|
||||
chunk_timeout_(chunk_timeout),
|
||||
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 ? fsi.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_)));
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user