1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

Merge pull request #59 from falk-werner/remove_uuid

- removed wf_config_set_mountpoint from API (breaking change)
- removed wf_protocol_create from API (breaking change)
- renamed wf_protocol_create2 to wf_protocol_create (breaking change)
- removed dependency to libuuid
- removed uuid mountpoint and uuid mountpoint factory
- simplified implementation of mountpoint factory (dispose is no longer needed)
This commit is contained in:
Falk Werner 2020-03-21 18:50:10 +01:00 committed by GitHub
commit a58f488b91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 69 additions and 527 deletions

View File

@ -15,9 +15,9 @@ RUN set -x \
pkgconf \ pkgconf \
rsync \ rsync \
gdb \ gdb \
valgrind \ valgrind
util-linux \ # util-linux \
util-linux-dev # util-linux-dev
COPY src /usr/local/src COPY src /usr/local/src

View File

@ -15,8 +15,7 @@ RUN set -x \
gdb \ gdb \
gdbserver \ gdbserver \
valgrind \ valgrind \
lcov \ lcov
uuid-dev
COPY src /usr/local/src COPY src /usr/local/src

View File

@ -19,9 +19,9 @@ RUN set -x \
pkgconf \ pkgconf \
rsync \ rsync \
gdb \ gdb \
valgrind \ valgrind
util-linux \ # util-linux \
util-linux-dev # util-linux-dev
COPY src /usr/local/src COPY src /usr/local/src

View File

@ -18,8 +18,7 @@ RUN set -x \
rsync \ rsync \
gdb \ gdb \
gdbserver \ gdbserver \
lcov \ lcov
uuid-dev
COPY src /usr/local/src COPY src /usr/local/src

View File

@ -40,8 +40,6 @@ add_executable(alltests
test/webfuse/tests/adapter/test_authenticator.cc test/webfuse/tests/adapter/test_authenticator.cc
test/webfuse/tests/adapter/test_authenticators.cc test/webfuse/tests/adapter/test_authenticators.cc
test/webfuse/tests/adapter/test_mountpoint.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/adapter/test_fuse_req.cc
test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_url.cc
test/webfuse/tests/provider/test_client_protocol.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/include
lib/wf/timer/src lib/wf/timer/src
${FUSE3_INCLUDE_DIRS} ${FUSE3_INCLUDE_DIRS}
${UUID_INCLUDE_DIRS}
) )
target_compile_options(alltests PUBLIC target_compile_options(alltests PUBLIC
${FUSE3_CFLAGS_OTHER} ${FUSE3_CFLAGS_OTHER}
${UUID_CFLAGS_OTHER}
) )
target_link_libraries(alltests PUBLIC target_link_libraries(alltests PUBLIC
@ -73,7 +69,6 @@ target_link_libraries(alltests PUBLIC
${FUSE3_LIBRARIES} ${FUSE3_LIBRARIES}
${LWS_LIBRARIES} ${LWS_LIBRARIES}
${JANSSON_LIBRARIES} ${JANSSON_LIBRARIES}
${UUID_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${GMOCK_LIBRARIES} ${GMOCK_LIBRARIES}
${GTEST_LIBRARIES} ${GTEST_LIBRARIES}

View File

@ -1,7 +1,6 @@
if(NOT WITHOUT_ADAPTER) if(NOT WITHOUT_ADAPTER)
pkg_check_modules(FUSE3 REQUIRED fuse3) pkg_check_modules(FUSE3 REQUIRED fuse3)
pkg_check_modules(UUID REQUIRED uuid)
add_library(webfuse-adapter-static STATIC add_library(webfuse-adapter-static STATIC
lib/webfuse/adapter/api.c 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/operations.c
lib/webfuse/adapter/impl/mountpoint.c lib/webfuse/adapter/impl/mountpoint.c
lib/webfuse/adapter/impl/mountpoint_factory.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/lookup.c
lib/webfuse/adapter/impl/operation/getattr.c lib/webfuse/adapter/impl/operation/getattr.c
lib/webfuse/adapter/impl/operation/readdir.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/timer/include
lib/wf/jsonrpc/include lib/wf/jsonrpc/include
${FUSE3_INCLUDE_DIRS} ${FUSE3_INCLUDE_DIRS}
${UUID_INCLUDE_DIRS}
) )
target_compile_options(webfuse-adapter-static PUBLIC target_compile_options(webfuse-adapter-static PUBLIC
${FUSE3_CFLAGS_OTHER} ${FUSE3_CFLAGS_OTHER}
${UUID_CFLAGS_OTHER}
) )
set_target_properties(webfuse-adapter-static PROPERTIES OUTPUT_NAME webfuse-adapter) 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 target_include_directories(webfuse-adapter PRIVATE
${FUSE3_INCLUDE_DIRS} ${FUSE3_INCLUDE_DIRS}
${UUID_INCLUDE_DIRS}
) )
target_compile_options(webfuse-adapter PUBLIC target_compile_options(webfuse-adapter PUBLIC
${FUSE3_CFLAGS_OTHER} ${FUSE3_CFLAGS_OTHER}
${UUID_CFLAGS_OTHER}
) )

View File

@ -23,7 +23,7 @@ struct wf_mountpoint;
/// \return newly created mountpoint or NULL, on error /// \return newly created mountpoint or NULL, on error
/// ///
/// \see wf_server_config_set_mountpoint_factory /// \see wf_server_config_set_mountpoint_factory
/// \see wf_server_protocol_create2 /// \see wf_server_protocol_create
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
typedef struct wf_mountpoint * typedef struct wf_mountpoint *
wf_create_mountpoint_fn( wf_create_mountpoint_fn(

View File

@ -42,23 +42,6 @@ extern WF_API struct wf_server_config * wf_server_config_create(void);
extern WF_API void wf_server_config_dispose( extern WF_API void wf_server_config_dispose(
struct wf_server_config * config); 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. /// \brief Sets the mountpoint factory of the configuration.
/// ///

View File

@ -32,17 +32,6 @@ struct wf_server_protocol;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
struct lws_protocols; 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. /// \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 factory function to create mountpoints
/// \param create_mountpoint_context context of mountpoint factory /// \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, wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context); void * create_mountpoint_context);

View File

@ -39,16 +39,10 @@ void wf_server_interrupt(
// server protocol // server protocol
struct wf_server_protocol * wf_server_protocol_create( 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, wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context) 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( void wf_server_protocol_dispose(
@ -86,13 +80,6 @@ void wf_server_config_dispose(
wf_impl_server_config_dispose(config); 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( void wf_server_config_set_mountpoint_factory(
struct wf_server_config * config, struct wf_server_config * config,
wf_create_mountpoint_fn * create_mountpoint, wf_create_mountpoint_fn * create_mountpoint,

View File

@ -6,7 +6,6 @@
#include "webfuse/core/string.h" #include "webfuse/core/string.h"
#include <libwebsockets.h> #include <libwebsockets.h>
#include <uuid/uuid.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>

View File

@ -7,19 +7,16 @@ wf_impl_mountpoint_factory_init_default(
{ {
factory->create_mountpoint = NULL; factory->create_mountpoint = NULL;
factory->user_data = NULL; factory->user_data = NULL;
factory->dispose = NULL;
} }
void void
wf_impl_mountpoint_factory_init( wf_impl_mountpoint_factory_init(
struct wf_impl_mountpoint_factory * factory, struct wf_impl_mountpoint_factory * factory,
wf_create_mountpoint_fn * create_mountpoint, wf_create_mountpoint_fn * create_mountpoint,
void * user_data, void * user_data)
wf_impl_mountpoint_factory_dispose_fn * dispose)
{ {
factory->create_mountpoint = create_mountpoint; factory->create_mountpoint = create_mountpoint;
factory->user_data = user_data; factory->user_data = user_data;
factory->dispose = dispose;
} }
void void
@ -29,10 +26,8 @@ wf_impl_mountpoint_factory_move(
{ {
other->create_mountpoint = factory->create_mountpoint; other->create_mountpoint = factory->create_mountpoint;
other->user_data = factory->user_data; other->user_data = factory->user_data;
other->dispose = factory->dispose;
factory->create_mountpoint = NULL; factory->create_mountpoint = NULL;
factory->dispose = NULL;
factory->user_data = NULL; factory->user_data = NULL;
} }
@ -47,13 +42,8 @@ void
wf_impl_mountpoint_factory_cleanup( wf_impl_mountpoint_factory_cleanup(
struct wf_impl_mountpoint_factory * factory) struct wf_impl_mountpoint_factory * factory)
{ {
if (NULL != factory->dispose)
{
factory->dispose(factory->user_data);
}
factory->create_mountpoint = NULL; factory->create_mountpoint = NULL;
factory->dispose = NULL;
factory->user_data = NULL; factory->user_data = NULL;
} }

View File

@ -9,14 +9,9 @@ extern "C"
{ {
#endif #endif
typedef void
wf_impl_mountpoint_factory_dispose_fn(
void * user_data);
struct wf_impl_mountpoint_factory struct wf_impl_mountpoint_factory
{ {
wf_create_mountpoint_fn * create_mountpoint; wf_create_mountpoint_fn * create_mountpoint;
wf_impl_mountpoint_factory_dispose_fn * dispose;
void * user_data; void * user_data;
}; };
@ -28,8 +23,7 @@ extern void
wf_impl_mountpoint_factory_init( wf_impl_mountpoint_factory_init(
struct wf_impl_mountpoint_factory * factory, struct wf_impl_mountpoint_factory * factory,
wf_create_mountpoint_fn * create_mountpoint, wf_create_mountpoint_fn * create_mountpoint,
void * user_data, void * user_data);
wf_impl_mountpoint_factory_dispose_fn * dispose);
extern void extern void
wf_impl_mountpoint_factory_move( wf_impl_mountpoint_factory_move(

View File

@ -1,5 +1,4 @@
#include "webfuse/adapter/impl/server_config.h" #include "webfuse/adapter/impl/server_config.h"
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -72,21 +71,13 @@ void wf_impl_server_config_dispose(
free(config); 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( void wf_impl_server_config_set_mountpoint_factory(
struct wf_server_config * config, struct wf_server_config * config,
wf_create_mountpoint_fn * create_mountpoint, wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context) void * create_mountpoint_context)
{ {
wf_impl_mountpoint_factory_init(&config->mountpoint_factory, wf_impl_mountpoint_factory_init(&config->mountpoint_factory,
create_mountpoint, create_mountpoint_context, NULL); create_mountpoint, create_mountpoint_context);
} }

View File

@ -34,10 +34,6 @@ extern void wf_impl_server_config_clone(
struct wf_server_config * config, struct wf_server_config * config,
struct wf_server_config * clone); 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( extern void wf_impl_server_config_set_mountpoint_factory(
struct wf_server_config * config, struct wf_server_config * config,
wf_create_mountpoint_fn * create_mountpoint, wf_create_mountpoint_fn * create_mountpoint,

View File

@ -9,7 +9,6 @@
#include "webfuse/core/protocol_names.h" #include "webfuse/core/protocol_names.h"
#include "webfuse/adapter/impl/credentials.h" #include "webfuse/adapter/impl/credentials.h"
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
#include "webfuse/core/status_intern.h" #include "webfuse/core/status_intern.h"
#include "wf/jsonrpc/request.h" #include "wf/jsonrpc/request.h"
@ -82,21 +81,6 @@ static int wf_impl_server_protocol_callback(
} }
struct wf_server_protocol * wf_impl_server_protocol_create( 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, wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context) void * create_mountpoint_context)
{ {
@ -105,7 +89,7 @@ struct wf_server_protocol * wf_impl_server_protocol_create2(
{ {
struct wf_impl_mountpoint_factory mountpoint_factory; struct wf_impl_mountpoint_factory mountpoint_factory;
wf_impl_mountpoint_factory_init(&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); wf_impl_server_protocol_init(protocol, &mountpoint_factory);
} }

View File

@ -36,10 +36,7 @@ extern void wf_impl_server_protocol_init(
extern void wf_impl_server_protocol_cleanup( extern void wf_impl_server_protocol_cleanup(
struct wf_server_protocol * protocol); struct wf_server_protocol * protocol);
extern struct wf_server_protocol * wf_impl_server_protocol_create( extern WF_API 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, wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context); void * create_mountpoint_context);

View File

@ -1,124 +0,0 @@
#include "webfuse/adapter/impl/uuid_mountpoint.h"
#include "webfuse/adapter/impl/mountpoint.h"
#include "webfuse/core/string.h"
#include <uuid/uuid.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
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;
}

View File

@ -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

View File

@ -1,84 +0,0 @@
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
#include "webfuse/adapter/impl/uuid_mountpoint.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
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;
}

View File

@ -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 <stdbool.h>
#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

View File

@ -8,13 +8,27 @@
#include "webfuse/adapter/server.h" #include "webfuse/adapter/server.h"
#include "webfuse/adapter/server_config.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) TEST(server, create_dispose)
{ {
mkdir("test", 0700); mkdir("test", 0700);
struct wf_server_config * config = wf_server_config_create(); 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); struct wf_server * server = wf_server_create(config);
ASSERT_NE(nullptr, server); ASSERT_NE(nullptr, server);

View File

@ -120,38 +120,18 @@ TEST(server_config, set_port)
wf_server_config_dispose(config); 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) TEST(server_config, set_mounpoint_factory)
{ {
wf_server_config * config = wf_server_config_create(); wf_server_config * config = wf_server_config_create();
ASSERT_NE(nullptr, config); ASSERT_NE(nullptr, config);
ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint); ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint);
ASSERT_EQ(nullptr, config->mountpoint_factory.user_data); ASSERT_EQ(nullptr, config->mountpoint_factory.user_data);
ASSERT_EQ(nullptr, config->mountpoint_factory.dispose);
int value = 42; int value = 42;
void * user_data = reinterpret_cast<void*>(&value); void * user_data = reinterpret_cast<void*>(&value);
wf_server_config_set_mountpoint_factory(config, &create_mountpoint, user_data); wf_server_config_set_mountpoint_factory(config, &create_mountpoint, user_data);
ASSERT_EQ(&create_mountpoint, config->mountpoint_factory.create_mountpoint); ASSERT_EQ(&create_mountpoint, config->mountpoint_factory.create_mountpoint);
ASSERT_EQ(user_data, config->mountpoint_factory.user_data); ASSERT_EQ(user_data, config->mountpoint_factory.user_data);
ASSERT_EQ(nullptr, config->mountpoint_factory.dispose);
wf_server_config_dispose(config); wf_server_config_dispose(config);
} }

View File

@ -1,72 +0,0 @@
#include <gtest/gtest.h>
#include "webfuse/utils/tempdir.hpp"
#include "webfuse/utils/file_utils.hpp"
#include "webfuse_adapter.h"
#include "webfuse/adapter/impl/uuid_mountpoint.h"
#include <string>
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));
}

View File

@ -1,61 +0,0 @@
#include <gtest/gtest.h>
#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);
}

View File

@ -4,11 +4,43 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h>
#include "webfuse_adapter.h" #include "webfuse_adapter.h"
#include "webfuse/adapter/impl/server.h" #include "webfuse/adapter/impl/server.h"
#define WF_PATH_MAX (100) #define WF_PATH_MAX (100)
extern "C"
{
static void webfuse_test_server_cleanup_mountpoint(
void * user_data)
{
char * path = reinterpret_cast<char*>(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<char const*>(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<void*>(strdup(path)),
&webfuse_test_server_cleanup_mountpoint);
return mountpoint;
}
}
namespace webfuse_test namespace webfuse_test
{ {
@ -28,7 +60,9 @@ public:
config = wf_server_config_create(); config = wf_server_config_create();
wf_server_config_set_port(config, 8080); 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<void*>(base_dir));
server = wf_server_create(config); server = wf_server_create(config);

View File

@ -68,7 +68,7 @@ TEST_F(IntegrationTest, HasMountpoint)
TEST_F(IntegrationTest, ProvidesTextFile) 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({ ASSERT_EXIT({
struct stat buffer; struct stat buffer;
@ -85,7 +85,7 @@ TEST_F(IntegrationTest, ProvidesTextFile)
TEST_F(IntegrationTest, ReadTextFile) 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({ ASSERT_EXIT({
FILE * file = fopen(file_name.c_str(), "rb"); FILE * file = fopen(file_name.c_str(), "rb");
@ -106,7 +106,7 @@ TEST_F(IntegrationTest, ReadTextFile)
TEST_F(IntegrationTest, ReadDir) TEST_F(IntegrationTest, ReadDir)
{ {
std::string dir_name = std::string(GetBaseDir()) + "/cprovider/default"; std::string dir_name = std::string(GetBaseDir()) + "/cprovider";
ASSERT_EXIT({ ASSERT_EXIT({