refactor
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2024-07-26 17:11:48 -05:00
parent ce417ec7c8
commit 2a3a0aa689
2 changed files with 29 additions and 29 deletions

View File

@ -619,11 +619,11 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
if (utils::file::is_directory(file_path)) { if (utils::file::is_directory(file_path)) {
auto list = drive_.get_directory_items(utils::path::create_api_path(path)); auto list = drive_.get_directory_items(utils::path::create_api_path(path));
auto iterator = std::make_shared<directory_iterator>(std::move(list)); auto iter = std::make_shared<directory_iterator>(std::move(list));
directory_cache_.set_directory(path, iterator); directory_cache_.set_directory(path, iter);
handle = reinterpret_cast<remote::file_handle>(iterator.get()); handle = reinterpret_cast<remote::file_handle>(iter.get());
res = 0; res = 0;
errno = 0; errno = 0;
} }
@ -682,10 +682,10 @@ auto remote_server::fuse_readdir(const char *path,
errno = ERANGE; errno = ERANGE;
res = -1; res = -1;
} else { } else {
auto iterator = directory_cache_.get_directory( auto iter = directory_cache_.get_directory(
reinterpret_cast<directory_iterator *>(handle)); reinterpret_cast<directory_iterator *>(handle));
if (iterator != nullptr) { if (iter != nullptr) {
res = iterator->get(static_cast<std::size_t>(offset), item_path); res = iter->get(static_cast<std::size_t>(offset), item_path);
} else { } else {
res = -1; res = -1;
errno = EFAULT; errno = EFAULT;
@ -744,9 +744,9 @@ auto remote_server::fuse_rmdir(const char *path) -> packet::error_type {
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
const auto res = rmdir(file_path.c_str()); const auto res = rmdir(file_path.c_str());
if (res == 0) { if (res == 0) {
auto iterator = auto iter =
directory_cache_.remove_directory(utils::path::create_api_path(path)); directory_cache_.remove_directory(utils::path::create_api_path(path));
if (iterator == nullptr) { if (iter == nullptr) {
utils::error::raise_error( utils::error::raise_error(
function_name, function_name,
"unexpected nullptr for directory iterator|sp|" + file_path); "unexpected nullptr for directory iterator|sp|" + file_path);
@ -1568,13 +1568,13 @@ auto remote_server::json_create_directory_snapshot(
if (utils::file::is_directory(file_path)) { if (utils::file::is_directory(file_path)) {
auto list = drive_.get_directory_items(api_path); auto list = drive_.get_directory_items(api_path);
auto iterator = std::make_shared<directory_iterator>(std::move(list)); auto iter = std::make_shared<directory_iterator>(std::move(list));
directory_cache_.set_directory(api_path, iterator); directory_cache_.set_directory(api_path, iter);
json_data["handle"] = reinterpret_cast<remote::file_handle>(iterator.get()); json_data["handle"] = reinterpret_cast<remote::file_handle>(iter.get());
json_data["path"] = path; json_data["path"] = path;
json_data["page_count"] = utils::divide_with_ceiling( json_data["page_count"] = utils::divide_with_ceiling(
iterator->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE); iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE);
res = 0; res = 0;
errno = 0; errno = 0;
} }

View File

@ -531,12 +531,12 @@ auto remote_server::fuse_readdir(const char *path,
errno = ERANGE; errno = ERANGE;
res = -1; res = -1;
} else { } else {
auto *iterator = reinterpret_cast<directory_iterator *>(handle); auto *iter = reinterpret_cast<directory_iterator *>(handle);
if (iterator == nullptr) { if (iter == nullptr) {
res = -1; res = -1;
errno = EFAULT; errno = EFAULT;
} else { } else {
res = iterator->get(static_cast<std::size_t>(offset), item_path); res = iter->get(static_cast<std::size_t>(offset), item_path);
} }
} }
@ -817,12 +817,12 @@ auto remote_server::json_create_directory_snapshot(
if (utils::file::is_directory(file_path)) { if (utils::file::is_directory(file_path)) {
auto list = drive_.get_directory_items(utils::path::create_api_path(path)); auto list = drive_.get_directory_items(utils::path::create_api_path(path));
auto *iterator = new directory_iterator(std::move(list)); auto *iter = new directory_iterator(std::move(list));
json_data["path"] = path; json_data["path"] = path;
json_data["handle"] = static_cast<remote::file_handle>( json_data["handle"] = static_cast<remote::file_handle>(
reinterpret_cast<std::uintptr_t>(iterator)); reinterpret_cast<std::uintptr_t>(iter));
json_data["page_count"] = utils::divide_with_ceiling( json_data["page_count"] = utils::divide_with_ceiling(
iterator->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE); iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE);
res = 0; res = 0;
errno = 0; errno = 0;
} }
@ -838,22 +838,22 @@ auto remote_server::json_read_directory_snapshot(
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__); constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto *iterator = reinterpret_cast<directory_iterator *>(handle); auto *iter = reinterpret_cast<directory_iterator *>(handle);
std::size_t offset{}; std::size_t offset{};
int res{}; int res{};
json item_json; json item_json;
while ((json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) && while (
(res = iterator->get_json( (json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) &&
(page * REPERTORY_DIRECTORY_PAGE_SIZE) + offset++, item_json)) == (res = iter->get_json((page * REPERTORY_DIRECTORY_PAGE_SIZE) + offset++,
0) { item_json)) == 0) {
json_data["directory_list"].emplace_back(item_json); json_data["directory_list"].emplace_back(item_json);
} }
json_data["handle"] = static_cast<remote::file_handle>( json_data["handle"] =
reinterpret_cast<std::uintptr_t>(iterator)); static_cast<remote::file_handle>(reinterpret_cast<std::uintptr_t>(iter));
json_data["path"] = path; json_data["path"] = path;
json_data["page"] = page; json_data["page"] = page;
json_data["page_count"] = utils::divide_with_ceiling( json_data["page_count"] = utils::divide_with_ceiling(
iterator->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE); iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE);
const auto ret = ((res < 0) ? -errno : 0); const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret); RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret; return ret;
@ -1198,14 +1198,14 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
const auto api_path = const auto api_path =
utils::path::create_api_path(ofi.path.substr(mount_location_.size())); utils::path::create_api_path(ofi.path.substr(mount_location_.size()));
auto items = drive_.get_directory_items(api_path); auto items = drive_.get_directory_items(api_path);
directory_iterator iterator(std::move(items)); directory_iterator iter(std::move(items));
auto offset = marker == nullptr auto offset = marker == nullptr
? 0 ? 0
: iterator.get_next_directory_offset( : iter.get_next_directory_offset(
utils::path::create_api_path(utils::path::combine( utils::path::create_api_path(utils::path::combine(
api_path, {utils::string::to_utf8(marker)}))); api_path, {utils::string::to_utf8(marker)})));
json item; json item;
while (iterator.get_json(offset++, item) == 0) { while (iter.get_json(offset++, item) == 0) {
item_list.emplace_back(item); item_list.emplace_back(item);
} }
ret = STATUS_SUCCESS; ret = STATUS_SUCCESS;