From a2b8998f4a311997401accc237ed52288407be5b Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 15 Apr 2025 09:27:00 -0500 Subject: [PATCH] [bug] Windows-to-Linux remote mount is allowing directory rename when directory is not empty #47 --- .../drives/fuse/remotefuse/remote_server.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp index 21b0a2d2..5c17c06d 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp @@ -1448,15 +1448,22 @@ auto remote_server::winfsp_rename(PVOID /*file_desc*/, PWSTR file_name, ret = ((res < 0) ? static_cast( utils::unix_error_to_windows(errno)) : 0); - } else if (utils::file::directory(file_path).exists()) { - res = drive_.rename_directory(construct_api_path(file_path), - construct_api_path(new_file_path)); - ret = - ((res < 0) ? errno == EISDIR + } else { + auto dir{utils::file::directory(file_path)}; + if (dir.exists()) { + if (dir.count(false) == 0U) { + res = drive_.rename_directory(construct_api_path(file_path), + construct_api_path(new_file_path)); + ret = ((res < 0) + ? errno == EISDIR ? static_cast(STATUS_ACCESS_DENIED) : static_cast( utils::unix_error_to_windows(errno)) : 0); + } else { + ret = static_cast(STATUS_DIRECTORY_NOT_EMPTY); + } + } } RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path + "|" + new_file_path,