From bb85015733491f9f2a1d0c4fb0d9bc1b8d3ab95e Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 2 Apr 2025 13:40:15 -0500 Subject: [PATCH] [bug] Remote mount directory listing on Windows connected to Linux is failing #42 --- .../drives/fuse/remotefuse/remote_server.hpp | 3 +- .../drives/fuse/remotefuse/remote_server.cpp | 34 ++++++++++++++++--- .../remotewinfsp/remote_winfsp_drive.cpp | 10 ++---- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/repertory/librepertory/include/drives/fuse/remotefuse/remote_server.hpp b/repertory/librepertory/include/drives/fuse/remotefuse/remote_server.hpp index 7290d4bd..e7b0e675 100644 --- a/repertory/librepertory/include/drives/fuse/remotefuse/remote_server.hpp +++ b/repertory/librepertory/include/drives/fuse/remotefuse/remote_server.hpp @@ -59,7 +59,8 @@ private: static void populate_stat(const struct stat64 &unix_st, remote::stat &r_stat); - [[nodiscard]] auto update_to_windows_format(json &item) -> json &; + [[nodiscard]] auto update_to_windows_format(const std::string &root_api_path, + json &item) -> json &; public: // FUSE Layer diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp index 8fe26778..bbbc9cb6 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp @@ -1394,7 +1394,7 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/, auto ret = static_cast( has_open_info(static_cast(handle), STATUS_INVALID_HANDLE)); if (ret == STATUS_SUCCESS) { - const auto api_path = construct_api_path( + auto api_path = construct_api_path( get_open_file_path(static_cast(handle))); directory_iterator iterator(drive_.get_directory_items(api_path)); auto offset = marker == nullptr @@ -1405,7 +1405,7 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/, json item; while (iterator.get_json(offset++, item) == 0) { try { - item_list.emplace_back(update_to_windows_format(item)); + item_list.emplace_back(update_to_windows_format(api_path, item)); } catch (const std::exception &e) { utils::error::raise_error(function_name, e, "exception occurred"); } @@ -1679,10 +1679,34 @@ auto remote_server::json_release_directory_snapshot( return 0; } -auto remote_server::update_to_windows_format(json &item) -> json & { +auto remote_server::update_to_windows_format(const std::string &root_api_path, + json &item) -> json & { auto api_path = item[JSON_API_PATH].get(); - if (api_path == "." || api_path == "..") { - return item; + if (api_path == ".") { + api_path = root_api_path; + + api_meta_map meta; + auto res = drive_.get_item_meta(api_path, meta); + if (res != api_error::success) { + utils::error::raise_api_path_error(function_name, api_path, error, + "failed to get . meta"); + return item; + } + + item[JSON_META] = meta; + } else if (api_path == "..") { + // TODO handle '/' parent + api_path = utils::path::get_parent_api_path(root_api_path); + + api_meta_map meta; + auto res = drive_.get_item_meta(api_path, meta); + if (res != api_error::success) { + utils::error::raise_api_path_error(function_name, api_path, error, + "failed to get .. meta"); + return item; + } + + item[JSON_META] = meta; } item[JSON_META][META_ACCESSED] = std::to_string( diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_winfsp_drive.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_winfsp_drive.cpp index 6dc41b1e..d459edee 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_winfsp_drive.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_winfsp_drive.cpp @@ -361,11 +361,10 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc, &ret)) { auto item_found = false; for (const auto &item : item_list) { - auto item_path = item["path"].get(); + auto item_path = item[JSON_API_PATH].get(); auto display_name = utils::string::from_utf8( utils::path::strip_to_file_name(item_path)); if (not marker || (marker && item_found)) { - // if (not utils::path::is_ads_file_path(item_path)) { union { UINT8 B[FIELD_OFFSET(FSP_FSCTL_DIR_INFO, FileNameBuf) + ((repertory::max_path_length + 1U) * sizeof(WCHAR))]; @@ -380,10 +379,8 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc, display_name.size()) * sizeof(WCHAR))); - if (not item["meta"].empty() || - ((item_path != ".") && (item_path != ".."))) { - populate_file_info(item, directory_info->FileInfo); - } + populate_file_info(item, directory_info->FileInfo); + if (ret == STATUS_SUCCESS) { ::wcscpy_s(&directory_info->FileNameBuf[0], repertory::max_path_length, &display_name[0]); @@ -394,7 +391,6 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc, break; } } - // } } else { item_found = display_name == std::wstring(marker); }