From 43c989e7af53b1190b14f6f85a2d604c04688db1 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 09:11:18 +0100 Subject: [PATCH 1/2] removed uuid mountpoint and factory --- build/amd64-alpine-builder.dockerfile | 6 +- build/amd64-ubuntu-builder.dockerfile | 3 +- build/arm32v7-alpine-builder.dockerfile | 6 +- build/arm32v7-ubuntu-builder.dockerfile | 3 +- cmake/unit_tests.cmake | 5 - cmake/webfuse_adapter.cmake | 7 - include/webfuse/adapter/server_config.h | 17 --- lib/webfuse/adapter/api.c | 13 -- lib/webfuse/adapter/impl/filesystem.c | 1 - lib/webfuse/adapter/impl/mountpoint_factory.c | 12 +- lib/webfuse/adapter/impl/mountpoint_factory.h | 8 +- lib/webfuse/adapter/impl/server_config.c | 11 +- lib/webfuse/adapter/impl/server_config.h | 4 - lib/webfuse/adapter/impl/server_protocol.c | 18 +-- lib/webfuse/adapter/impl/server_protocol.h | 3 - lib/webfuse/adapter/impl/uuid_mountpoint.c | 124 ------------------ lib/webfuse/adapter/impl/uuid_mountpoint.h | 20 --- .../adapter/impl/uuid_mountpoint_factory.c | 84 ------------ .../adapter/impl/uuid_mountpoint_factory.h | 21 --- test/webfuse/tests/adapter/test_server.cc | 16 ++- .../tests/adapter/test_server_config.cc | 20 --- .../tests/adapter/test_uuid_mountpoint.cc | 72 ---------- .../adapter/test_uuid_mountpoint_factory.cc | 61 --------- test/webfuse/tests/integration/server.cc | 36 ++++- .../tests/integration/test_integration.cc | 6 +- 25 files changed, 65 insertions(+), 512 deletions(-) delete mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint.c delete mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint.h delete mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint_factory.c delete mode 100644 lib/webfuse/adapter/impl/uuid_mountpoint_factory.h delete mode 100644 test/webfuse/tests/adapter/test_uuid_mountpoint.cc delete mode 100644 test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc diff --git a/build/amd64-alpine-builder.dockerfile b/build/amd64-alpine-builder.dockerfile index 50e0490..6bd7713 100644 --- a/build/amd64-alpine-builder.dockerfile +++ b/build/amd64-alpine-builder.dockerfile @@ -15,9 +15,9 @@ RUN set -x \ pkgconf \ rsync \ gdb \ - valgrind \ - util-linux \ - util-linux-dev + valgrind +# util-linux \ +# util-linux-dev COPY src /usr/local/src diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index 37a5f35..7f5cc46 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -15,8 +15,7 @@ RUN set -x \ gdb \ gdbserver \ valgrind \ - lcov \ - uuid-dev + lcov COPY src /usr/local/src diff --git a/build/arm32v7-alpine-builder.dockerfile b/build/arm32v7-alpine-builder.dockerfile index e3a53ca..4eca9a6 100644 --- a/build/arm32v7-alpine-builder.dockerfile +++ b/build/arm32v7-alpine-builder.dockerfile @@ -19,9 +19,9 @@ RUN set -x \ pkgconf \ rsync \ gdb \ - valgrind \ - util-linux \ - util-linux-dev + valgrind +# util-linux \ +# util-linux-dev COPY src /usr/local/src diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index b3c368d..a84a8e3 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -18,8 +18,7 @@ RUN set -x \ rsync \ gdb \ gdbserver \ - lcov \ - uuid-dev + lcov COPY src /usr/local/src diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index b541706..aaf5381 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -40,8 +40,6 @@ add_executable(alltests test/webfuse/tests/adapter/test_authenticator.cc test/webfuse/tests/adapter/test_authenticators.cc test/webfuse/tests/adapter/test_mountpoint.cc - test/webfuse/tests/adapter/test_uuid_mountpoint.cc - test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc test/webfuse/tests/adapter/test_fuse_req.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc @@ -56,12 +54,10 @@ target_include_directories(alltests PRIVATE lib/wf/timer/include lib/wf/timer/src ${FUSE3_INCLUDE_DIRS} - ${UUID_INCLUDE_DIRS} ) target_compile_options(alltests PUBLIC ${FUSE3_CFLAGS_OTHER} - ${UUID_CFLAGS_OTHER} ) target_link_libraries(alltests PUBLIC @@ -73,7 +69,6 @@ target_link_libraries(alltests PUBLIC ${FUSE3_LIBRARIES} ${LWS_LIBRARIES} ${JANSSON_LIBRARIES} - ${UUID_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES} diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index bb0f723..f6e777c 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -1,7 +1,6 @@ if(NOT WITHOUT_ADAPTER) pkg_check_modules(FUSE3 REQUIRED fuse3) -pkg_check_modules(UUID REQUIRED uuid) add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/api.c @@ -17,8 +16,6 @@ add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/impl/operations.c lib/webfuse/adapter/impl/mountpoint.c lib/webfuse/adapter/impl/mountpoint_factory.c - lib/webfuse/adapter/impl/uuid_mountpoint_factory.c - lib/webfuse/adapter/impl/uuid_mountpoint.c lib/webfuse/adapter/impl/operation/lookup.c lib/webfuse/adapter/impl/operation/getattr.c lib/webfuse/adapter/impl/operation/readdir.c @@ -32,12 +29,10 @@ target_include_directories(webfuse-adapter-static PRIVATE lib/wf/timer/include lib/wf/jsonrpc/include ${FUSE3_INCLUDE_DIRS} - ${UUID_INCLUDE_DIRS} ) target_compile_options(webfuse-adapter-static PUBLIC ${FUSE3_CFLAGS_OTHER} - ${UUID_CFLAGS_OTHER} ) set_target_properties(webfuse-adapter-static PROPERTIES OUTPUT_NAME webfuse-adapter) @@ -49,12 +44,10 @@ add_library(webfuse-adapter SHARED target_include_directories(webfuse-adapter PRIVATE ${FUSE3_INCLUDE_DIRS} - ${UUID_INCLUDE_DIRS} ) target_compile_options(webfuse-adapter PUBLIC ${FUSE3_CFLAGS_OTHER} - ${UUID_CFLAGS_OTHER} ) diff --git a/include/webfuse/adapter/server_config.h b/include/webfuse/adapter/server_config.h index 83a1c34..e140c4d 100644 --- a/include/webfuse/adapter/server_config.h +++ b/include/webfuse/adapter/server_config.h @@ -42,23 +42,6 @@ extern WF_API struct wf_server_config * wf_server_config_create(void); extern WF_API void wf_server_config_dispose( struct wf_server_config * config); -//------------------------------------------------------------------------------ -/// \brief Sets a mountpoint path. -/// \deprecated This function will be removed soon. Use \ref -/// wf_server_config_set_mountpoint_factory instead. -/// -/// Sets the root path of UUID-based file system. -/// -/// \note A valid configuration needs either a mountpoint or a mounpoint -/// factory. -/// -/// \param config pointer of configuration object -/// \param mount_point root path of UUID-based file system. -//------------------------------------------------------------------------------ -extern WF_API void wf_server_config_set_mountpoint( - struct wf_server_config * config, - char const * mount_point); - //------------------------------------------------------------------------------ /// \brief Sets the mountpoint factory of the configuration. /// diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index 2047029..6b08e0f 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -38,12 +38,6 @@ void wf_server_interrupt( // server protocol -struct wf_server_protocol * wf_server_protocol_create( - char * mount_point) -{ - return wf_impl_server_protocol_create(mount_point); -} - struct wf_server_protocol * wf_server_protocol_create2( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context) @@ -86,13 +80,6 @@ void wf_server_config_dispose( wf_impl_server_config_dispose(config); } -void wf_server_config_set_mountpoint( - struct wf_server_config * config, - char const * mount_point) -{ - wf_impl_server_config_set_mountpoint(config, mount_point); -} - void wf_server_config_set_mountpoint_factory( struct wf_server_config * config, wf_create_mountpoint_fn * create_mountpoint, diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index e4a3435..03c2217 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -6,7 +6,6 @@ #include "webfuse/core/string.h" #include -#include #include #include diff --git a/lib/webfuse/adapter/impl/mountpoint_factory.c b/lib/webfuse/adapter/impl/mountpoint_factory.c index 54679ef..2da5db3 100644 --- a/lib/webfuse/adapter/impl/mountpoint_factory.c +++ b/lib/webfuse/adapter/impl/mountpoint_factory.c @@ -7,19 +7,16 @@ wf_impl_mountpoint_factory_init_default( { factory->create_mountpoint = NULL; factory->user_data = NULL; - factory->dispose = NULL; } void wf_impl_mountpoint_factory_init( struct wf_impl_mountpoint_factory * factory, wf_create_mountpoint_fn * create_mountpoint, - void * user_data, - wf_impl_mountpoint_factory_dispose_fn * dispose) + void * user_data) { factory->create_mountpoint = create_mountpoint; factory->user_data = user_data; - factory->dispose = dispose; } void @@ -29,10 +26,8 @@ wf_impl_mountpoint_factory_move( { other->create_mountpoint = factory->create_mountpoint; other->user_data = factory->user_data; - other->dispose = factory->dispose; factory->create_mountpoint = NULL; - factory->dispose = NULL; factory->user_data = NULL; } @@ -47,13 +42,8 @@ void wf_impl_mountpoint_factory_cleanup( struct wf_impl_mountpoint_factory * factory) { - if (NULL != factory->dispose) - { - factory->dispose(factory->user_data); - } factory->create_mountpoint = NULL; - factory->dispose = NULL; factory->user_data = NULL; } diff --git a/lib/webfuse/adapter/impl/mountpoint_factory.h b/lib/webfuse/adapter/impl/mountpoint_factory.h index 98e5469..63bbbfc 100644 --- a/lib/webfuse/adapter/impl/mountpoint_factory.h +++ b/lib/webfuse/adapter/impl/mountpoint_factory.h @@ -9,14 +9,9 @@ extern "C" { #endif -typedef void -wf_impl_mountpoint_factory_dispose_fn( - void * user_data); - struct wf_impl_mountpoint_factory { wf_create_mountpoint_fn * create_mountpoint; - wf_impl_mountpoint_factory_dispose_fn * dispose; void * user_data; }; @@ -28,8 +23,7 @@ extern void wf_impl_mountpoint_factory_init( struct wf_impl_mountpoint_factory * factory, wf_create_mountpoint_fn * create_mountpoint, - void * user_data, - wf_impl_mountpoint_factory_dispose_fn * dispose); + void * user_data); extern void wf_impl_mountpoint_factory_move( diff --git a/lib/webfuse/adapter/impl/server_config.c b/lib/webfuse/adapter/impl/server_config.c index 2d9fc6d..bcf022e 100644 --- a/lib/webfuse/adapter/impl/server_config.c +++ b/lib/webfuse/adapter/impl/server_config.c @@ -1,5 +1,4 @@ #include "webfuse/adapter/impl/server_config.h" -#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" #include #include @@ -72,21 +71,13 @@ void wf_impl_server_config_dispose( free(config); } -void wf_impl_server_config_set_mountpoint( - struct wf_server_config * config, - char const * mount_point) -{ - wf_impl_uuid_mountpoint_factory_init(&config->mountpoint_factory, - mount_point); -} - void wf_impl_server_config_set_mountpoint_factory( struct wf_server_config * config, wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context) { wf_impl_mountpoint_factory_init(&config->mountpoint_factory, - create_mountpoint, create_mountpoint_context, NULL); + create_mountpoint, create_mountpoint_context); } diff --git a/lib/webfuse/adapter/impl/server_config.h b/lib/webfuse/adapter/impl/server_config.h index 48de4ed..400b842 100644 --- a/lib/webfuse/adapter/impl/server_config.h +++ b/lib/webfuse/adapter/impl/server_config.h @@ -34,10 +34,6 @@ extern void wf_impl_server_config_clone( struct wf_server_config * config, struct wf_server_config * clone); -extern void wf_impl_server_config_set_mountpoint( - struct wf_server_config * config, - char const * mount_point); - extern void wf_impl_server_config_set_mountpoint_factory( struct wf_server_config * config, wf_create_mountpoint_fn * create_mountpoint, diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 9085a14..7bcec27 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -9,7 +9,6 @@ #include "webfuse/core/protocol_names.h" #include "webfuse/adapter/impl/credentials.h" -#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" #include "webfuse/core/status_intern.h" #include "wf/jsonrpc/request.h" @@ -81,21 +80,6 @@ static int wf_impl_server_protocol_callback( return 0; } -struct wf_server_protocol * wf_impl_server_protocol_create( - char * mount_point) -{ - struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol)); - if (NULL != protocol) - { - struct wf_impl_mountpoint_factory mountpoint_factory; - wf_impl_uuid_mountpoint_factory_init(&mountpoint_factory, mount_point); - - wf_impl_server_protocol_init(protocol, &mountpoint_factory); - } - - return protocol; -} - struct wf_server_protocol * wf_impl_server_protocol_create2( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context) @@ -105,7 +89,7 @@ struct wf_server_protocol * wf_impl_server_protocol_create2( { struct wf_impl_mountpoint_factory mountpoint_factory; wf_impl_mountpoint_factory_init(&mountpoint_factory, - create_mountpoint, create_mountpoint_context, NULL); + create_mountpoint, create_mountpoint_context); wf_impl_server_protocol_init(protocol, &mountpoint_factory); } diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index 5d8052e..05ebe12 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -36,9 +36,6 @@ extern void wf_impl_server_protocol_init( extern void wf_impl_server_protocol_cleanup( struct wf_server_protocol * protocol); -extern struct wf_server_protocol * wf_impl_server_protocol_create( - char * mount_point); - extern WF_API struct wf_server_protocol * wf_impl_server_protocol_create2( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context); diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint.c b/lib/webfuse/adapter/impl/uuid_mountpoint.c deleted file mode 100644 index 4573329..0000000 --- a/lib/webfuse/adapter/impl/uuid_mountpoint.c +++ /dev/null @@ -1,124 +0,0 @@ -#include "webfuse/adapter/impl/uuid_mountpoint.h" -#include "webfuse/adapter/impl/mountpoint.h" - -#include "webfuse/core/string.h" - -#include - -#include -#include -#include -#include - -#include -#include -#include - -struct wf_impl_uuid_mountpoint_data -{ - char * id; - char * filesystem_path; - char * default_path; - char * full_path; -}; - -static char * wf_impl_uuid_mountpoint_create_id(void) -{ - uuid_t uuid; - uuid_generate(uuid); - char id[UUID_STR_LEN]; - uuid_unparse(uuid, id); - - return strdup(id); -} - -static bool wf_impl_uuid_mountpoint_is_link_broken(char const * path, char const * id) -{ - bool result = false; - - char buffer[UUID_STR_LEN]; - ssize_t count = readlink(path, buffer, UUID_STR_LEN); - if ((0 < count) && (count < UUID_STR_LEN)) - { - buffer[count] = '\0'; - result = (0 == strcmp(buffer, id)); - } - - return result; -} - -static bool wf_impl_uuid_mountpoint_link_first_subdir( - char const * link_path, - char const * path) -{ - bool result = false; - DIR * dir = opendir(path); - if (NULL != dir) - { - struct dirent * entry = readdir(dir); - while (NULL != entry) - { - if ((DT_DIR == entry->d_type) && ('.' != entry->d_name[0])) - { - int rc = symlink(entry->d_name, link_path); - result = (0 == rc); - break; - } - - entry = readdir(dir); - } - - closedir(dir); - } - - return result; -} - -static void -wf_impl_uuid_mountpoint_data_dispose( - void * user_data) -{ - struct wf_impl_uuid_mountpoint_data * data = user_data; - - rmdir(data->full_path); - - if (wf_impl_uuid_mountpoint_is_link_broken(data->default_path, data->id)) - { - unlink(data->default_path); - - bool const success = wf_impl_uuid_mountpoint_link_first_subdir(data->default_path, data->filesystem_path); - if (!success) - { - rmdir(data->filesystem_path); - } - } - - free(data->id); - free(data->filesystem_path); - free(data->default_path); - free(data->full_path); - free(data); -} - -struct wf_mountpoint * -wf_impl_uuid_mountpoint_create( - char const * root_path, - char const * filesystem) -{ - struct wf_impl_uuid_mountpoint_data * data = malloc(sizeof(struct wf_impl_uuid_mountpoint_data)); - data->filesystem_path = wf_create_string("%s/%s", root_path, filesystem); - mkdir(data->filesystem_path, 0755); - - data->id = wf_impl_uuid_mountpoint_create_id(); - data->full_path = wf_create_string("%s/%s/%s", root_path, filesystem, data->id); - mkdir(data->full_path, 0755); - - data->default_path = wf_create_string("%s/%s/default", root_path, filesystem); - int rc = symlink(data->id, data->default_path); - (void) rc; // ignore missing symlink - - struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(data->full_path); - wf_impl_mountpoint_set_userdata(mountpoint, data, &wf_impl_uuid_mountpoint_data_dispose); - - return mountpoint; -} diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint.h b/lib/webfuse/adapter/impl/uuid_mountpoint.h deleted file mode 100644 index 7287be3..0000000 --- a/lib/webfuse/adapter/impl/uuid_mountpoint.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef WF_IMPL_UUID_MOUNTPOINT_H -#define WF_IMPL_UUID_MOUNTPOINT_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_mountpoint; - -extern struct wf_mountpoint * -wf_impl_uuid_mountpoint_create( - char const * root_path, - char const * filesystem); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c deleted file mode 100644 index 3b4d543..0000000 --- a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" -#include "webfuse/adapter/impl/uuid_mountpoint.h" - -#include -#include -#include - -#include -#include -#include - -struct wf_impl_uuid_mountpoint_factory -{ - char * root_path; - bool root_created; -}; - -static void * -wf_impl_uuid_mountpoint_factory_create_context( - char const * root_path) -{ - struct wf_impl_uuid_mountpoint_factory * factory = NULL; - bool root_created = false; - - struct stat info; - int rc = stat(root_path, &info); - if ((0 != rc) || (!S_ISDIR(info.st_mode))) - { - rc = mkdir(root_path, 0755); - root_created = true; - } - - if (0 == rc) - { - factory = malloc(sizeof(struct wf_impl_uuid_mountpoint_factory)); - factory->root_path = strdup(root_path); - factory->root_created = root_created; - } - - return factory; -} - -static void -wf_impl_uuid_mountpoint_factory_dispose( - void * user_data) -{ - struct wf_impl_uuid_mountpoint_factory * factory = user_data; - - if (factory->root_created) - { - rmdir(factory->root_path); - } - - free(factory->root_path); - free(factory); -} - -static struct wf_mountpoint * -wf_impl_uuid_mountpoint_factory_create_mountpoint( - char const * filesystem, - void * user_data) -{ - struct wf_impl_uuid_mountpoint_factory * factory = user_data; - - return wf_impl_uuid_mountpoint_create(factory->root_path, filesystem); -} - -bool -wf_impl_uuid_mountpoint_factory_init( - struct wf_impl_mountpoint_factory * factory, - char const * root_path) -{ - void * context = wf_impl_uuid_mountpoint_factory_create_context(root_path); - bool const result = (NULL != context); - - if (result) - { - factory->create_mountpoint = &wf_impl_uuid_mountpoint_factory_create_mountpoint; - factory->user_data = context; - factory->dispose = &wf_impl_uuid_mountpoint_factory_dispose; - } - - return result; -} diff --git a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h b/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h deleted file mode 100644 index eed8fa0..0000000 --- a/lib/webfuse/adapter/impl/uuid_mountpoint_factory.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef WF_IMPL_UUID_MOUNTPOINT_FACTORY_H -#define WF_IMPL_UUID_MOUNTPOINT_FACTORY_H - -#include "webfuse/adapter/impl/mountpoint_factory.h" -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern bool -wf_impl_uuid_mountpoint_factory_init( - struct wf_impl_mountpoint_factory * factory, - char const * root_path); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/test/webfuse/tests/adapter/test_server.cc b/test/webfuse/tests/adapter/test_server.cc index ef8fa25..1b2a881 100644 --- a/test/webfuse/tests/adapter/test_server.cc +++ b/test/webfuse/tests/adapter/test_server.cc @@ -8,13 +8,27 @@ #include "webfuse/adapter/server.h" #include "webfuse/adapter/server_config.h" +namespace +{ +struct wf_mountpoint * +create_mountpoint( + char const * filesystem, + void * user_data) +{ + (void) filesystem; + (void) user_data; + + return nullptr; +} + +} TEST(server, create_dispose) { mkdir("test", 0700); struct wf_server_config * config = wf_server_config_create(); - wf_server_config_set_mountpoint(config, "test"); + wf_server_config_set_mountpoint_factory(config, &create_mountpoint, nullptr); struct wf_server * server = wf_server_create(config); ASSERT_NE(nullptr, server); diff --git a/test/webfuse/tests/adapter/test_server_config.cc b/test/webfuse/tests/adapter/test_server_config.cc index f85aa92..b9687be 100644 --- a/test/webfuse/tests/adapter/test_server_config.cc +++ b/test/webfuse/tests/adapter/test_server_config.cc @@ -120,38 +120,18 @@ TEST(server_config, set_port) wf_server_config_dispose(config); } -TEST(server_config, set_mountpoint) -{ - TempDir temp("server_config"); - - wf_server_config * config = wf_server_config_create(); - ASSERT_NE(nullptr, config); - ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint); - ASSERT_EQ(nullptr, config->mountpoint_factory.user_data); - ASSERT_EQ(nullptr, config->mountpoint_factory.dispose); - - wf_server_config_set_mountpoint(config, temp.path()); - ASSERT_NE(nullptr, config->mountpoint_factory.create_mountpoint); - ASSERT_NE(nullptr, config->mountpoint_factory.user_data); - ASSERT_NE(nullptr, config->mountpoint_factory.dispose); - - wf_server_config_dispose(config); -} - TEST(server_config, set_mounpoint_factory) { wf_server_config * config = wf_server_config_create(); ASSERT_NE(nullptr, config); ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint); ASSERT_EQ(nullptr, config->mountpoint_factory.user_data); - ASSERT_EQ(nullptr, config->mountpoint_factory.dispose); int value = 42; void * user_data = reinterpret_cast(&value); wf_server_config_set_mountpoint_factory(config, &create_mountpoint, user_data); ASSERT_EQ(&create_mountpoint, config->mountpoint_factory.create_mountpoint); ASSERT_EQ(user_data, config->mountpoint_factory.user_data); - ASSERT_EQ(nullptr, config->mountpoint_factory.dispose); wf_server_config_dispose(config); } diff --git a/test/webfuse/tests/adapter/test_uuid_mountpoint.cc b/test/webfuse/tests/adapter/test_uuid_mountpoint.cc deleted file mode 100644 index 7549b84..0000000 --- a/test/webfuse/tests/adapter/test_uuid_mountpoint.cc +++ /dev/null @@ -1,72 +0,0 @@ -#include - -#include "webfuse/utils/tempdir.hpp" -#include "webfuse/utils/file_utils.hpp" -#include "webfuse_adapter.h" -#include "webfuse/adapter/impl/uuid_mountpoint.h" - -#include - -using webfuse_test::TempDir; -using webfuse_test::is_dir; -using webfuse_test::is_symlink; -using webfuse_test::is_same_path; - -TEST(uuid_mountpoint, create) -{ - TempDir temp("uuid_mountpoint"); - - std::string filesystem_path = std::string(temp.path()) + "/dummy"; - std::string default_path = std::string(temp.path()) + "/dummy/default"; - - wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_create(temp.path(), "dummy"); - std::string path = wf_mountpoint_get_path(mountpoint); - ASSERT_NE(nullptr, mountpoint); - ASSERT_TRUE(is_dir(filesystem_path)); - ASSERT_TRUE(is_symlink(default_path)); - ASSERT_TRUE(is_dir(default_path)); - ASSERT_TRUE(is_dir(path)); - ASSERT_TRUE(is_same_path(default_path, path)); - - wf_mountpoint_dispose(mountpoint); - ASSERT_FALSE(is_dir(filesystem_path)); - ASSERT_FALSE(is_symlink(default_path)); - ASSERT_FALSE(is_dir(default_path)); - ASSERT_FALSE(is_dir(path)); -} - -TEST(uuid_mountpoint, relink_default) -{ - TempDir temp("uuid_mountpoint"); - - std::string filesystem_path = std::string(temp.path()) + "/dummy"; - std::string default_path = std::string(temp.path()) + "/dummy/default"; - - wf_mountpoint * mountpoint_a = wf_impl_uuid_mountpoint_create(temp.path(), "dummy"); - std::string path_a = wf_mountpoint_get_path(mountpoint_a); - - wf_mountpoint * mountpoint_b = wf_impl_uuid_mountpoint_create(temp.path(), "dummy"); - std::string path_b = wf_mountpoint_get_path(mountpoint_b); - - ASSERT_TRUE(is_dir(filesystem_path)); - ASSERT_TRUE(is_symlink(default_path)); - ASSERT_TRUE(is_dir(default_path)); - ASSERT_TRUE(is_dir(path_a)); - ASSERT_TRUE(is_dir(path_b)); - ASSERT_TRUE(is_same_path(default_path, path_a)); - - wf_mountpoint_dispose(mountpoint_a); - ASSERT_TRUE(is_dir(filesystem_path)); - ASSERT_TRUE(is_symlink(default_path)); - ASSERT_TRUE(is_dir(default_path)); - ASSERT_FALSE(is_dir(path_a)); - ASSERT_TRUE(is_dir(path_b)); - ASSERT_TRUE(is_same_path(default_path, path_b)); - - wf_mountpoint_dispose(mountpoint_b); - ASSERT_FALSE(is_dir(filesystem_path)); - ASSERT_FALSE(is_symlink(default_path)); - ASSERT_FALSE(is_dir(default_path)); - ASSERT_FALSE(is_dir(path_a)); - ASSERT_FALSE(is_dir(path_b)); -} diff --git a/test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc b/test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc deleted file mode 100644 index dca941f..0000000 --- a/test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include "webfuse_adapter.h" -#include "webfuse/adapter/impl/uuid_mountpoint_factory.h" -#include "webfuse/utils/tempdir.hpp" -#include "webfuse/utils/file_utils.hpp" - -using webfuse_test::TempDir; -using webfuse_test::is_dir; - -TEST(uuid_mountpoint_factory, create_existing_dir) -{ - TempDir temp("uuid_mountpoint_factory"); - - struct wf_impl_mountpoint_factory factory; - bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, temp.path()); - ASSERT_TRUE(factory_created); - ASSERT_TRUE(is_dir(temp.path())); - - wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy"); - std::string path = wf_mountpoint_get_path(mountpoint); - ASSERT_TRUE(is_dir(path)); - - wf_mountpoint_dispose(mountpoint); - ASSERT_FALSE(is_dir(path)); - - wf_impl_mountpoint_factory_cleanup(&factory); - // keep dir not created by factory - ASSERT_TRUE(is_dir(temp.path())); -} - -TEST(uuid_mountpoint_factory, create_nonexisting_dir) -{ - TempDir temp("uuid_mountpoint_factory"); - std::string root_path = std::string(temp.path()) + "/root"; - - struct wf_impl_mountpoint_factory factory; - bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str()); - ASSERT_TRUE(factory_created); - ASSERT_TRUE(is_dir(root_path)); - - wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy"); - std::string path = wf_mountpoint_get_path(mountpoint); - ASSERT_TRUE(is_dir(path)); - - wf_mountpoint_dispose(mountpoint); - ASSERT_FALSE(is_dir(path)); - - wf_impl_mountpoint_factory_cleanup(&factory); - // remove dir, created by factory - ASSERT_FALSE(is_dir(root_path)); -} - -TEST(uuid_mountpoint_factory, fail_to_created_nested_dir) -{ - TempDir temp("uuid_mountpoint_factory"); - std::string root_path = std::string(temp.path()) + "/nested/root"; - - struct wf_impl_mountpoint_factory factory; - bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str()); - ASSERT_FALSE(factory_created); -} \ No newline at end of file diff --git a/test/webfuse/tests/integration/server.cc b/test/webfuse/tests/integration/server.cc index 177a69f..931f932 100644 --- a/test/webfuse/tests/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -4,11 +4,43 @@ #include #include #include +#include #include "webfuse_adapter.h" #include "webfuse/adapter/impl/server.h" #define WF_PATH_MAX (100) +extern "C" +{ + +static void webfuse_test_server_cleanup_mountpoint( + void * user_data) +{ + char * path = reinterpret_cast(user_data); + rmdir(path); + free(path); +} + +static struct wf_mountpoint * +webfuse_test_server_create_mountpoint( + char const * filesystem, + void * user_data) +{ + char const * base_dir = reinterpret_cast(user_data); + char path[WF_PATH_MAX]; + snprintf(path, WF_PATH_MAX, "%s/%s", base_dir, filesystem); + mkdir(path, 0755); + struct wf_mountpoint * mountpoint = wf_mountpoint_create(path); + wf_mountpoint_set_userdata( + mountpoint, + reinterpret_cast(strdup(path)), + &webfuse_test_server_cleanup_mountpoint); + + return mountpoint; +} + +} + namespace webfuse_test { @@ -28,7 +60,9 @@ public: config = wf_server_config_create(); wf_server_config_set_port(config, 8080); - wf_server_config_set_mountpoint(config, base_dir); + wf_server_config_set_mountpoint_factory(config, + &webfuse_test_server_create_mountpoint, + reinterpret_cast(base_dir)); server = wf_server_create(config); diff --git a/test/webfuse/tests/integration/test_integration.cc b/test/webfuse/tests/integration/test_integration.cc index 203856c..4cc2844 100644 --- a/test/webfuse/tests/integration/test_integration.cc +++ b/test/webfuse/tests/integration/test_integration.cc @@ -68,7 +68,7 @@ TEST_F(IntegrationTest, HasMountpoint) TEST_F(IntegrationTest, ProvidesTextFile) { - std::string file_name = std::string(GetBaseDir()) + "/cprovider/default/hello.txt"; + std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt"; ASSERT_EXIT({ struct stat buffer; @@ -85,7 +85,7 @@ TEST_F(IntegrationTest, ProvidesTextFile) TEST_F(IntegrationTest, ReadTextFile) { - std::string file_name = std::string(GetBaseDir()) + "/cprovider/default/hello.txt"; + std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt"; ASSERT_EXIT({ FILE * file = fopen(file_name.c_str(), "rb"); @@ -106,7 +106,7 @@ TEST_F(IntegrationTest, ReadTextFile) TEST_F(IntegrationTest, ReadDir) { - std::string dir_name = std::string(GetBaseDir()) + "/cprovider/default"; + std::string dir_name = std::string(GetBaseDir()) + "/cprovider"; ASSERT_EXIT({ From 425e017bc4906949de8b6ea02d5fdbf188fed41f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 09:18:04 +0100 Subject: [PATCH 2/2] renamed function: wf_impl_server_protocol_create2 to ..create: remove of uuid mountpoint was already API breaking --- include/webfuse/adapter/mountpoint_factory.h | 2 +- include/webfuse/adapter/server_protocol.h | 13 +------------ lib/webfuse/adapter/api.c | 4 ++-- lib/webfuse/adapter/impl/server_protocol.c | 2 +- lib/webfuse/adapter/impl/server_protocol.h | 2 +- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/include/webfuse/adapter/mountpoint_factory.h b/include/webfuse/adapter/mountpoint_factory.h index 8a69821..7a10bb1 100644 --- a/include/webfuse/adapter/mountpoint_factory.h +++ b/include/webfuse/adapter/mountpoint_factory.h @@ -23,7 +23,7 @@ struct wf_mountpoint; /// \return newly created mountpoint or NULL, on error /// /// \see wf_server_config_set_mountpoint_factory -/// \see wf_server_protocol_create2 +/// \see wf_server_protocol_create //------------------------------------------------------------------------------ typedef struct wf_mountpoint * wf_create_mountpoint_fn( diff --git a/include/webfuse/adapter/server_protocol.h b/include/webfuse/adapter/server_protocol.h index 8808669..68b1dbe 100644 --- a/include/webfuse/adapter/server_protocol.h +++ b/include/webfuse/adapter/server_protocol.h @@ -32,17 +32,6 @@ struct wf_server_protocol; //------------------------------------------------------------------------------ struct lws_protocols; -//------------------------------------------------------------------------------ -/// \brief Creates a new protocol with a given mounpoint. -/// \deprecated This function will be removed soon. Use \ref -/// wf_server_protocol_create2 instead. -/// -/// \param mount_point root path of UUID-based file system. -/// \return newly created protocol -//------------------------------------------------------------------------------ -extern WF_API struct wf_server_protocol * wf_server_protocol_create( - char * mount_point); - //------------------------------------------------------------------------------ /// \brief Creates a new protocol by a mountpoint factory. /// @@ -53,7 +42,7 @@ extern WF_API struct wf_server_protocol * wf_server_protocol_create( /// \param create_mountpoint factory function to create mountpoints /// \param create_mountpoint_context context of mountpoint factory //------------------------------------------------------------------------------ -extern WF_API struct wf_server_protocol * wf_server_protocol_create2( +extern WF_API struct wf_server_protocol * wf_server_protocol_create( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context); diff --git a/lib/webfuse/adapter/api.c b/lib/webfuse/adapter/api.c index 6b08e0f..72ab6bc 100644 --- a/lib/webfuse/adapter/api.c +++ b/lib/webfuse/adapter/api.c @@ -38,11 +38,11 @@ void wf_server_interrupt( // server protocol -struct wf_server_protocol * wf_server_protocol_create2( +struct wf_server_protocol * wf_server_protocol_create( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context) { - return wf_impl_server_protocol_create2(create_mountpoint, create_mountpoint_context); + return wf_impl_server_protocol_create(create_mountpoint, create_mountpoint_context); } void wf_server_protocol_dispose( diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 7bcec27..927d1cb 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -80,7 +80,7 @@ static int wf_impl_server_protocol_callback( return 0; } -struct wf_server_protocol * wf_impl_server_protocol_create2( +struct wf_server_protocol * wf_impl_server_protocol_create( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context) { diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index 05ebe12..df98c8f 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -36,7 +36,7 @@ extern void wf_impl_server_protocol_init( extern void wf_impl_server_protocol_cleanup( struct wf_server_protocol * protocol); -extern WF_API struct wf_server_protocol * wf_impl_server_protocol_create2( +extern WF_API struct wf_server_protocol * wf_impl_server_protocol_create( wf_create_mountpoint_fn * create_mountpoint, void * create_mountpoint_context);