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)pull/61/head
commit
a58f488b91
@ -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;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
@ -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
|
@ -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));
|
||||
}
|
@ -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);
|
||||
}
|
Loading…
Reference in new issue