[unit test] Complete FUSE unit tests #22

This commit is contained in:
2025-09-27 06:35:56 -05:00
parent b3624427d5
commit f16cf499cd
5 changed files with 48 additions and 11 deletions

View File

@@ -176,6 +176,8 @@ public:
const open_file_data &ofd, std::uint64_t &handle,
std::shared_ptr<i_open_file> &file) -> api_error;
[[nodiscard]] auto remove_directory(const std::string &api_path) -> api_error;
[[nodiscard]] auto remove_file(const std::string &api_path) -> api_error;
[[nodiscard]] auto rename_directory(const std::string &from_api_path,

View File

@@ -931,12 +931,12 @@ auto fuse_drive::rmdir_impl(std::string api_path) -> api_error {
return res;
}
res = provider_.remove_directory(api_path);
res = fm_->remove_directory(api_path);
if (res != api_error::success) {
return res;
}
auto iter = directory_cache_->remove_directory(api_path);
directory_cache_->remove_directory(api_path);
return api_error::success;
}

View File

@@ -216,17 +216,13 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
FspFileSystemDeleteDirectoryBuffer(&directory_buffer);
}
if (not directory) {
if (directory) {
return handle_error(fm_->remove_directory(api_path));
}
return handle_error(fm_->remove_file(api_path));
}
if (provider_.get_directory_item_count(api_path) == 0) {
return handle_error(provider_.remove_directory(api_path));
}
return handle_error(api_error::directory_not_empty);
}
if (((flags & FspCleanupSetArchiveBit) != 0U) && not directory) {
api_meta_map meta;
if (provider_.get_item_meta(api_path, meta) == api_error::success) {

View File

@@ -101,6 +101,10 @@ void file_manager::close(std::uint64_t handle) {
closeable_file->close();
if (closeable_file->is_directory()) {
return;
}
auto file = utils::file::file{closeable_file->get_source_path()};
if (file.remove()) {
return;
@@ -689,9 +693,41 @@ void file_manager::queue_upload(const std::string &api_path,
}
}
auto file_manager::remove_directory(const std::string &api_path) -> api_error {
REPERTORY_USES_FUNCTION_NAME();
unique_recur_mutex_lock open_lock(open_file_mtx_);
if (provider_.get_directory_item_count(api_path) != 0) {
return api_error::directory_not_empty;
}
auto res = provider_.remove_directory(api_path);
if (res != api_error::success) {
return res;
}
auto file_iter = open_file_lookup_.find(api_path);
if (file_iter == open_file_lookup_.end()) {
return api_error::success;
}
auto closed_file = file_iter->second;
open_file_lookup_.erase(api_path);
closed_file->set_unlinked(true);
for (const auto &[handle, ofd] : closed_file->get_open_data()) {
unlinked_file_lookup_[handle] = closed_file;
}
open_lock.unlock();
return api_error::success;
}
auto file_manager::remove_file(const std::string &api_path) -> api_error {
REPERTORY_USES_FUNCTION_NAME();
unique_recur_mutex_lock open_lock(open_file_mtx_);
filesystem_item fsi{};
auto res = provider_.get_filesystem_item(api_path, false, fsi);
if (res != api_error::success) {
@@ -704,8 +740,6 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
return res;
}
unique_recur_mutex_lock open_lock(open_file_mtx_);
unique_mutex_lock upload_lock(upload_mtx_);
remove_upload(api_path, true);
remove_resume(api_path, fsi.source_path, true);

View File

@@ -115,6 +115,11 @@ TYPED_TEST(fuse_test, directory_can_opendir_after_closedir) {
}
TYPED_TEST(fuse_test, directory_rmdir_on_non_empty_directory_should_fail) {
if (this->current_provider == provider_type::encrypt) {
GTEST_SKIP();
return;
}
std::string dir_name{"non_empty"};
auto dir = this->create_directory_and_test(dir_name);