From 281d3758e01d1128b8687d84cba6fc36450189f4 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 4 Apr 2025 10:55:01 -0500 Subject: [PATCH] [bug] Windows-to-Linux remote mount ignores CREATE_NEW #44 --- .../drives/fuse/remotefuse/remote_server.cpp | 4 +-- .../winfsp/remotewinfsp/remote_client.cpp | 27 ++++++++++--------- .../remotewinfsp/remote_winfsp_drive.cpp | 8 +++--- .../include/fixtures/winfsp_fixture.hpp | 1 + 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp index d90ea6f6..324309ea 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp @@ -1126,9 +1126,7 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options, utils::file::directory{file_path}.exists(); auto ret{static_cast(STATUS_SUCCESS)}; - if (exists) { - ret = static_cast(STATUS_OBJECT_NAME_COLLISION); - } else { + if (not exists) { if ((create_options & FILE_DIRECTORY_FILE) != 0U) { attributes |= FILE_ATTRIBUTE_DIRECTORY; } else { diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp index 1f14696c..00fc9520 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp @@ -188,20 +188,23 @@ auto remote_client::winfsp_create(PWSTR file_name, UINT32 create_options, DECODE_OR_IGNORE(&response, normalized_name); DECODE_OR_IGNORE(&response, exists); - *file_desc = reinterpret_cast(handle); - set_open_info(to_handle(*file_desc), open_info{ - "", - nullptr, - {}, - utils::string::to_utf8(file_name), - }); - } - + if (exists == 0U) { + *file_desc = reinterpret_cast(handle); + set_open_info(to_handle(*file_desc), + open_info{ + "", + nullptr, + {}, + utils::string::to_utf8(file_name), + }); + } #if defined(_WIN32) - if (ret == STATUS_OBJECT_NAME_COLLISION && exists != 0U) { - ::SetLastError(ERROR_ALREADY_EXISTS); - } + else { + ret = STATUS_OBJECT_NAME_COLLISION; + ::SetLastError(ERROR_FILE_EXISTS); + } #endif // defined(_WIN32) + } return ret; } 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 d459edee..4ff18dbb 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_winfsp_drive.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_winfsp_drive.cpp @@ -131,14 +131,14 @@ auto remote_winfsp_drive::Create(PWSTR file_name, UINT32 create_options, UINT64 allocation_size, PVOID * /*file_node*/, PVOID *file_desc, OpenFileInfo *ofi) -> NTSTATUS { - remote::file_info fi{}; + remote::file_info f_info{}; std::string normalized_name; - BOOLEAN exists = 0; + BOOLEAN exists{0}; auto ret = remote_instance_->winfsp_create( file_name, create_options, granted_access, attributes, allocation_size, - file_desc, &fi, normalized_name, exists); + file_desc, &f_info, normalized_name, exists); if (ret == STATUS_SUCCESS) { - set_file_info(ofi->FileInfo, fi); + set_file_info(ofi->FileInfo, f_info); auto file_path = utils::string::from_utf8(normalized_name); wcsncpy(ofi->NormalizedName, file_path.data(), wcslen(file_path.c_str())); ofi->NormalizedNameSize = diff --git a/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp b/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp index a286d9a9..ec40f417 100644 --- a/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp +++ b/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp @@ -263,6 +263,7 @@ protected: } static void execute_unmount(auto args, auto location) { + std::this_thread::sleep_for(10s); auto unmounted{false}; auto unmount_cmd =