From 2f8f38b6a2174792ee14584adf4fcd4ab986fb99 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Thu, 31 Oct 2024 12:14:09 -0500 Subject: [PATCH] winfsp unit tests and fixes --- .../src/drives/winfsp/winfsp_drive.cpp | 28 ++++++++++++++++--- support/include/utils/path.hpp | 14 +++++----- support/src/utils/path.cpp | 4 +++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp index 9d4c3fb3..548e0631 100644 --- a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp +++ b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp @@ -882,7 +882,7 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc, REPERTORY_USES_FUNCTION_NAME(); std::string api_path; - auto error = api_error::invalid_handle; + auto error{api_error::invalid_handle}; auto handle = static_cast(reinterpret_cast(file_desc)); if (handle != 0U) { @@ -912,15 +912,35 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc, api_path, {utils::string::to_utf8(marker)}))); while ((error = iterator.get_directory_item( offset++, dir_item)) == api_error::success) { - if (dir_item.api_path == "." || dir_item.api_path == "..") { - continue; + if (dir_item.api_path == ".") { + auto res = provider_.get_item_meta(api_path, dir_item.meta); + if (res != api_error::success) { + error = res; + utils::error::raise_api_path_error(function_name, + dir_item.api_path, error, + "failed to get . meta"); + break; + } + } else if (dir_item.api_path == "..") { + // TODO handle '/' parent + auto res = provider_.get_item_meta( + utils::path::get_parent_api_path(api_path), + dir_item.meta); + if (res != api_error::success) { + error = res; + utils::error::raise_api_path_error(function_name, + dir_item.api_path, error, + "failed to get .. meta"); + break; + } } if (dir_item.meta.empty()) { + error = api_error::error; utils::error::raise_api_path_error( function_name, dir_item.api_path, api_error::error, "item meta is empty"); - continue; + break; } auto display_name = utils::string::from_utf8( diff --git a/support/include/utils/path.hpp b/support/include/utils/path.hpp index fcb21b02..f05e4a1e 100644 --- a/support/include/utils/path.hpp +++ b/support/include/utils/path.hpp @@ -484,25 +484,25 @@ template std::basic_string_view path) -> string_t { auto slash_t = get_slash(); - string_t ret; if (path == slash_t) { - return ret; + return string_t{path}; } - ret = path.substr(0, path.rfind(slash_t) + 1); - if (ret == slash_t) { - return ret; + auto sub_path = path.substr(0, path.rfind(slash_t) + 1); + if (sub_path == slash_t) { + return string_t{sub_path}; } + string_t ret{sub_path}; return utils::string::right_trim(ret, slash_t.at(0U)); } inline auto get_parent_api_path(std::string_view path) -> std::string { - return get_parent_api_path_t(path); + return create_api_path(get_parent_api_path_t(path)); } inline auto get_parent_api_path(std::wstring_view path) -> std::wstring { - return get_parent_api_path_t(path); + return create_api_path(get_parent_api_path_t(path)); } template diff --git a/support/src/utils/path.cpp b/support/src/utils/path.cpp index 3cd7d3c7..a7726130 100644 --- a/support/src/utils/path.cpp +++ b/support/src/utils/path.cpp @@ -257,6 +257,10 @@ auto make_file_uri(std::wstring_view path) -> std::wstring { } auto strip_to_file_name(std::string path) -> std::string { + if (path == "." || path == "..") { + return path; + } + #if defined(_WIN32) return ::PathFindFileNameA(path.c_str()); #else // !defined(_WIN32)