From f2eafe0f14517dab4949ca17f4d91d7cf62da57d Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 13 Nov 2024 11:58:30 -0600 Subject: [PATCH] fuse unit tests and fixes --- .../src/drives/fuse/fuse_drive.cpp | 7 +- .../fuse/remotefuse/remote_fuse_drive.cpp | 79 +++++++++---------- .../src/fuse_drive_create_and_open_test.cpp | 3 + 3 files changed, 42 insertions(+), 47 deletions(-) diff --git a/repertory/librepertory/src/drives/fuse/fuse_drive.cpp b/repertory/librepertory/src/drives/fuse/fuse_drive.cpp index 03f06067..9b8e0975 100644 --- a/repertory/librepertory/src/drives/fuse/fuse_drive.cpp +++ b/repertory/librepertory/src/drives/fuse/fuse_drive.cpp @@ -706,11 +706,8 @@ auto fuse_drive::opendir_impl(std::string api_path, return api_error::directory_not_found; } - if ((file_info->flags & O_APPEND) == O_APPEND) { - return api_error::directory_exists; - } - - if ((file_info->flags & O_EXCL) == O_EXCL) { + if ((file_info->flags & O_APPEND) == O_APPEND || + (file_info->flags & O_EXCL) == O_EXCL) { return api_error::directory_exists; } diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp index 93b17ebf..bda66542 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp @@ -40,8 +40,8 @@ #include "utils/utils.hpp" namespace repertory::remote_fuse { -auto remote_fuse_drive::access_impl(std::string api_path, int mask) - -> api_error { +auto remote_fuse_drive::access_impl(std::string api_path, + int mask) -> api_error { return utils::to_api_error( remote_instance_->fuse_access(api_path.c_str(), mask)); } @@ -59,8 +59,8 @@ auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode, struct fuse_file_info * /*f_info*/) -> api_error { #else -auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode) - -> api_error { +auto remote_fuse_drive::chmod_impl(std::string api_path, + mode_t mode) -> api_error { #endif return utils::to_api_error(remote_instance_->fuse_chmod( api_path.c_str(), static_cast(mode))); @@ -71,8 +71,8 @@ auto remote_fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid, struct fuse_file_info * /*f_info*/) -> api_error { #else -auto remote_fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid) - -> api_error { +auto remote_fuse_drive::chown_impl(std::string api_path, uid_t uid, + gid_t gid) -> api_error { #endif return utils::to_api_error( remote_instance_->fuse_chown(api_path.c_str(), uid, gid)); @@ -116,10 +116,9 @@ void remote_fuse_drive::destroy_impl(void *ptr) { fuse_base::destroy_impl(ptr); } -auto remote_fuse_drive::fgetattr_impl(std::string api_path, - struct stat *unix_st, - struct fuse_file_info *f_info) - -> api_error { +auto remote_fuse_drive::fgetattr_impl( + std::string api_path, struct stat *unix_st, + struct fuse_file_info *f_info) -> api_error { remote::stat r_stat{}; auto directory = false; @@ -180,8 +179,8 @@ auto remote_fuse_drive::getattr_impl(std::string api_path, struct stat *unix_st, struct fuse_file_info * /*f_info*/) -> api_error { #else -auto remote_fuse_drive::getattr_impl(std::string api_path, struct stat *unix_st) - -> api_error { +auto remote_fuse_drive::getattr_impl(std::string api_path, + struct stat *unix_st) -> api_error { #endif bool directory = false; remote::stat r_stat{}; @@ -264,8 +263,8 @@ auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn) -> void * { return ret; } -auto remote_fuse_drive::mkdir_impl(std::string api_path, mode_t mode) - -> api_error { +auto remote_fuse_drive::mkdir_impl(std::string api_path, + mode_t mode) -> api_error { return utils::to_api_error(remote_instance_->fuse_mkdir( api_path.c_str(), static_cast(mode))); } @@ -287,9 +286,12 @@ auto remote_fuse_drive::open_impl(std::string api_path, f_info->fh)); } -auto remote_fuse_drive::opendir_impl(std::string api_path, - struct fuse_file_info *f_info) - -> api_error { +auto remote_fuse_drive::opendir_impl( + std::string api_path, struct fuse_file_info *f_info) -> api_error { + if ((f_info->flags & O_APPEND) == O_APPEND || + (f_info->flags & O_EXCL) == O_EXCL) { + return api_error::directory_exists; + } return utils::to_api_error( remote_instance_->fuse_opendir(api_path.c_str(), f_info->fh)); @@ -378,18 +380,14 @@ auto remote_fuse_drive::read_impl(std::string api_path, char *buffer, } #if FUSE_USE_VERSION >= 30 -auto remote_fuse_drive::readdir_impl(std::string api_path, void *buf, - fuse_fill_dir_t fuse_fill_dir, - off_t offset, - struct fuse_file_info *f_info, - fuse_readdir_flags /*flags*/) - -> api_error { +auto remote_fuse_drive::readdir_impl( + std::string api_path, void *buf, fuse_fill_dir_t fuse_fill_dir, + off_t offset, struct fuse_file_info *f_info, + fuse_readdir_flags /*flags*/) -> api_error { #else -auto remote_fuse_drive::readdir_impl(std::string api_path, void *buf, - fuse_fill_dir_t fuse_fill_dir, - off_t offset, - struct fuse_file_info *f_info) - -> api_error { +auto remote_fuse_drive::readdir_impl( + std::string api_path, void *buf, fuse_fill_dir_t fuse_fill_dir, + off_t offset, struct fuse_file_info *f_info) -> api_error { #endif std::string item_path; int res = 0; @@ -417,16 +415,14 @@ auto remote_fuse_drive::readdir_impl(std::string api_path, void *buf, return utils::to_api_error(res); } -auto remote_fuse_drive::release_impl(std::string api_path, - struct fuse_file_info *f_info) - -> api_error { +auto remote_fuse_drive::release_impl( + std::string api_path, struct fuse_file_info *f_info) -> api_error { return utils::to_api_error( remote_instance_->fuse_release(api_path.c_str(), f_info->fh)); } -auto remote_fuse_drive::releasedir_impl(std::string api_path, - struct fuse_file_info *f_info) - -> api_error { +auto remote_fuse_drive::releasedir_impl( + std::string api_path, struct fuse_file_info *f_info) -> api_error { return utils::to_api_error( remote_instance_->fuse_releasedir(api_path.c_str(), f_info->fh)); } @@ -523,8 +519,8 @@ api_error remote_fuse_drive::statfs_x_impl(std::string api_path, return utils::to_api_error(res); } #else // __APPLE__ -auto remote_fuse_drive::statfs_impl(std::string api_path, struct statvfs *stbuf) - -> api_error { +auto remote_fuse_drive::statfs_impl(std::string api_path, + struct statvfs *stbuf) -> api_error { auto res = statvfs(config_.get_data_directory().c_str(), stbuf); if (res == 0) { remote::statfs r_stat{}; @@ -551,8 +547,8 @@ auto remote_fuse_drive::truncate_impl(std::string api_path, off_t size, struct fuse_file_info * /*f_info*/) -> api_error { #else -auto remote_fuse_drive::truncate_impl(std::string api_path, off_t size) - -> api_error { +auto remote_fuse_drive::truncate_impl(std::string api_path, + off_t size) -> api_error { #endif return utils::to_api_error(remote_instance_->fuse_truncate( api_path.c_str(), static_cast(size))); @@ -563,10 +559,9 @@ auto remote_fuse_drive::unlink_impl(std::string api_path) -> api_error { } #if FUSE_USE_VERSION >= 30 -auto remote_fuse_drive::utimens_impl(std::string api_path, - const struct timespec tv[2], - struct fuse_file_info * /*f_info*/) - -> api_error { +auto remote_fuse_drive::utimens_impl( + std::string api_path, const struct timespec tv[2], + struct fuse_file_info * /*f_info*/) -> api_error { #else auto remote_fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2]) -> api_error { diff --git a/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp b/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp index 40d2c783..93bcc5cd 100644 --- a/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp @@ -484,6 +484,9 @@ TYPED_TEST(fuse_test, create_open_fails_if_path_is_directory) { for (auto &&flags : ops) { auto handle = open(dir_path.c_str(), flags); EXPECT_EQ(-1, handle); + if (handle != -1) { + std::cout << std::oct << flags << std::endl; + } EXPECT_EQ(EISDIR, errno); }