1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

removed uuid mountpoint and factory

This commit is contained in:
Falk Werner
2020-03-21 09:11:18 +01:00
parent 428c192910
commit 43c989e7af
25 changed files with 65 additions and 512 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,4 @@
#include "webfuse/adapter/impl/server_config.h"
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
#include <stdlib.h>
#include <string.h>
@@ -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);
}

View File

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

View File

@@ -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);
}

View File

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

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