winfsp unit tests and fixes

This commit is contained in:
Scott E. Graves 2024-10-31 12:14:09 -05:00
parent 0303dcf16a
commit 2f8f38b6a2
3 changed files with 35 additions and 11 deletions

View File

@ -882,7 +882,7 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
std::string api_path; std::string api_path;
auto error = api_error::invalid_handle; auto error{api_error::invalid_handle};
auto handle = auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc)); static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
if (handle != 0U) { if (handle != 0U) {
@ -912,15 +912,35 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
api_path, {utils::string::to_utf8(marker)}))); api_path, {utils::string::to_utf8(marker)})));
while ((error = iterator.get_directory_item( while ((error = iterator.get_directory_item(
offset++, dir_item)) == api_error::success) { offset++, dir_item)) == api_error::success) {
if (dir_item.api_path == "." || dir_item.api_path == "..") { if (dir_item.api_path == ".") {
continue; 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()) { if (dir_item.meta.empty()) {
error = api_error::error;
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, dir_item.api_path, api_error::error, function_name, dir_item.api_path, api_error::error,
"item meta is empty"); "item meta is empty");
continue; break;
} }
auto display_name = utils::string::from_utf8( auto display_name = utils::string::from_utf8(

View File

@ -484,25 +484,25 @@ template <typename string_t>
std::basic_string_view<typename string_t::value_type> path) -> string_t { std::basic_string_view<typename string_t::value_type> path) -> string_t {
auto slash_t = get_slash<typename string_t::value_type>(); auto slash_t = get_slash<typename string_t::value_type>();
string_t ret;
if (path == slash_t) { if (path == slash_t) {
return ret; return string_t{path};
} }
ret = path.substr(0, path.rfind(slash_t) + 1); auto sub_path = path.substr(0, path.rfind(slash_t) + 1);
if (ret == slash_t) { if (sub_path == slash_t) {
return ret; return string_t{sub_path};
} }
string_t ret{sub_path};
return utils::string::right_trim(ret, slash_t.at(0U)); return utils::string::right_trim(ret, slash_t.at(0U));
} }
inline auto get_parent_api_path(std::string_view path) -> std::string { inline auto get_parent_api_path(std::string_view path) -> std::string {
return get_parent_api_path_t<std::string>(path); return create_api_path(get_parent_api_path_t<std::string>(path));
} }
inline auto get_parent_api_path(std::wstring_view path) -> std::wstring { inline auto get_parent_api_path(std::wstring_view path) -> std::wstring {
return get_parent_api_path_t<std::wstring>(path); return create_api_path(get_parent_api_path_t<std::wstring>(path));
} }
template <typename string_t> template <typename string_t>

View File

@ -257,6 +257,10 @@ auto make_file_uri(std::wstring_view path) -> std::wstring {
} }
auto strip_to_file_name(std::string path) -> std::string { auto strip_to_file_name(std::string path) -> std::string {
if (path == "." || path == "..") {
return path;
}
#if defined(_WIN32) #if defined(_WIN32)
return ::PathFindFileNameA(path.c_str()); return ::PathFindFileNameA(path.c_str());
#else // !defined(_WIN32) #else // !defined(_WIN32)