[bug] Windows-to-Linux remote mount is allowing directory rename when directory is not empty #47
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2025-04-16 14:36:12 -05:00
parent 1153598c62
commit 6945a16f78
3 changed files with 2 additions and 19 deletions

View File

@ -28,7 +28,6 @@
#include "drives/directory_iterator.hpp" #include "drives/directory_iterator.hpp"
#include "drives/remote/remote_open_file_table.hpp" #include "drives/remote/remote_open_file_table.hpp"
#include "events/event_system.hpp" #include "events/event_system.hpp"
#include "events/types/debug_log.hpp"
#include "events/types/remote_server_event.hpp" #include "events/types/remote_server_event.hpp"
#include "platform/platform.hpp" #include "platform/platform.hpp"
#include "types/remote.hpp" #include "types/remote.hpp"
@ -89,9 +88,6 @@ auto remote_server::populate_file_info(const std::string &api_path,
auto directory = utils::file::directory(construct_path(api_path)).exists(); auto directory = utils::file::directory(construct_path(api_path)).exists();
auto res = drive_.get_item_meta(api_path, META_ATTRIBUTES, meta_attributes); auto res = drive_.get_item_meta(api_path, META_ATTRIBUTES, meta_attributes);
event_system::instance().raise<debug_log>(
function_name, fmt::format("{}|attributes|{}|res|", api_path,
meta_attributes, api_error_to_string(res)));
if (res == api_error::success) { if (res == api_error::success) {
if (meta_attributes.empty()) { if (meta_attributes.empty()) {
meta_attributes = directory ? std::to_string(FILE_ATTRIBUTE_DIRECTORY) meta_attributes = directory ? std::to_string(FILE_ATTRIBUTE_DIRECTORY)
@ -116,10 +112,6 @@ void remote_server::populate_file_info(const std::string &api_path,
api_meta_map meta{}; api_meta_map meta{};
auto res = drive_.get_item_meta(api_path, meta); auto res = drive_.get_item_meta(api_path, meta);
event_system::instance().raise<debug_log>(
function_name,
fmt::format("{}|attributes|{}|res|", api_path, meta[META_ATTRIBUTES],
api_error_to_string(res)));
if (res != api_error::success) { if (res != api_error::success) {
utils::error::raise_api_path_error(function_name, api_path, res, utils::error::raise_api_path_error(function_name, api_path, res,
"get item meta failed"); "get item meta failed");
@ -1459,19 +1451,11 @@ auto remote_server::winfsp_rename(PVOID /*file_desc*/, PWSTR file_name,
: 0); : 0);
} else { } else {
auto dir{utils::file::directory(file_path)}; auto dir{utils::file::directory(file_path)};
event_system::instance().raise<debug_log>(
function_name,
fmt::format("path|{}|exists|{}", file_path, dir.exists()));
if (dir.exists()) { if (dir.exists()) {
auto count{dir.count(false)}; auto count{dir.count(false)};
event_system::instance().raise<debug_log>(
function_name, fmt::format("path|{}|count|{}", file_path, count));
if (count == 0U) { if (count == 0U) {
res = drive_.rename_directory(construct_api_path(file_path), res = drive_.rename_directory(construct_api_path(file_path),
construct_api_path(new_file_path)); construct_api_path(new_file_path));
event_system::instance().raise<debug_log>(
function_name,
fmt::format("path|{}|res|{}|errno|{}", file_path, res, errno));
ret = ((res < 0) ret = ((res < 0)
? errno == EISDIR ? errno == EISDIR
? static_cast<packet::error_type>(STATUS_ACCESS_DENIED) ? static_cast<packet::error_type>(STATUS_ACCESS_DENIED)

View File

@ -322,6 +322,8 @@ public:
mkdir(dir_path.c_str(), perms); mkdir(dir_path.c_str(), perms);
EXPECT_TRUE(utils::file::directory(dir_path).exists()); EXPECT_TRUE(utils::file::directory(dir_path).exists());
EXPECT_EQ(0U, utils::file::directory(dir_path).count(false));
EXPECT_EQ(0U, utils::file::directory(dir_path).count(true));
EXPECT_FALSE(utils::file::file(dir_path).exists()); EXPECT_FALSE(utils::file::file(dir_path).exists());
struct stat64 unix_st{}; struct stat64 unix_st{};

View File

@ -85,9 +85,6 @@ auto traverse_directory(
struct dirent *de{nullptr}; struct dirent *de{nullptr};
while (res && (de = readdir(root)) && !is_stop_requested()) { while (res && (de = readdir(root)) && !is_stop_requested()) {
repertory::utils::error::handle_debug(
function_name,
fmt::format("item|{}|type|{}|{}", de->d_name, de->d_type, DT_DIR));
if (de->d_type == DT_DIR) { if (de->d_type == DT_DIR) {
if ((std::string_view(de->d_name) == ".") || if ((std::string_view(de->d_name) == ".") ||
(std::string_view(de->d_name) == "..")) { (std::string_view(de->d_name) == "..")) {