1
0
mirror of https://github.com/falk-werner/webfuse synced 2025-06-13 12:54:15 +00:00

adds implementation of static_filesystem_add and add_text

This commit is contained in:
Falk Werner 2019-04-22 08:58:23 +02:00
parent b9e7900f97
commit ef69187a91
4 changed files with 86 additions and 14 deletions

View File

@ -100,3 +100,17 @@ wf_path_get_element(
return result;
}
char const *
wf_path_get_filename(
struct wf_path * path)
{
char const * result = NULL;
if (0 < path->count)
{
result = path->elements[path->count - 1];
}
return result;
}

View File

@ -32,6 +32,10 @@ wf_path_get_element(
struct wf_path * path,
size_t i);
extern char const *
wf_path_get_filename(
struct wf_path * path);
#ifdef __cplusplus
}
#endif

View File

@ -3,11 +3,14 @@
#include "webfuse/provider/dirbuffer.h"
#include "webfuse/provider/operation/error.h"
#include "webfuse/core/path.h"
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY (16)
#define WFP_STATIC_FILSYSTEM_INDOE_ROOT (1)
struct wfp_static_filesystem_entry
{
@ -126,13 +129,15 @@ wfp_static_filesystem_entry_get_info(
}
static void
static size_t
wfp_static_filesystem_add_dir(
struct wfp_static_filesystem * filesystem,
size_t parent,
char const * name
)
{
size_t result = 0;
struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry_by_name(filesystem, parent, name);
if (NULL == entry)
{
@ -146,7 +151,31 @@ wfp_static_filesystem_add_dir(
entry->get_info = &wfp_static_filesystem_entry_get_info;
entry->size = 0;
entry->content = NULL;
result = entry->inode;
}
return result;
}
static size_t
wfp_impl_static_filesystem_make_parent(
struct wfp_static_filesystem * filesystem,
struct wf_path * path)
{
size_t result = WFP_STATIC_FILSYSTEM_INDOE_ROOT;
size_t count = wf_path_element_count(path);
if (0 < count)
{
for(size_t i = 0; i < (count - 1); i++)
{
char const * name = wf_path_get_element(path, i);
result = wfp_static_filesystem_add_dir(filesystem, result, name);
}
}
return result;
}
static void wfp_static_filesystem_stat(
@ -320,13 +349,25 @@ wfp_impl_static_filesystem_add(
char const * content,
size_t length)
{
(void) filesystem;
(void) path;
(void) mode;
(void) content;
(void) length;
struct wf_path * path_ = wf_path_create(path);
if (NULL != path_)
{
size_t parent = wfp_impl_static_filesystem_make_parent(filesystem, path_);
struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem);
entry->parent = parent;
entry->is_file = true;
entry->name = strdup(wf_path_get_filename(path_));
entry->mode = mode;
entry->size = length;
entry->get_info = &wfp_static_filesystem_entry_get_info;
entry->read = &wfp_static_filesystem_entry_read;
entry->user_data = entry;
// ToDo: implement me
entry->content = malloc(length);
memcpy(entry->content, content, length);
wf_path_dispose(path_);
}
}
void
@ -336,12 +377,8 @@ wfp_impl_static_filesystem_add_text(
int mode,
char const * content)
{
(void) filesystem;
(void) path;
(void) mode;
(void) content;
// ToDo: implement me
size_t length = strlen(content);
wfp_impl_static_filesystem_add(filesystem, path, mode, content, length);
}
void

View File

@ -42,3 +42,20 @@ TEST(wfp_static_filesystem, contains_default_dirs)
wfp_impl_static_filesystem_dispose(filesystem);
wfp_client_config_dispose(config);
}
TEST(wfp_static_filesystem, add_text)
{
struct wfp_client_config * config = wfp_client_config_create();
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
wfp_impl_static_filesystem_add_text(filesystem, "text.file", 666, "some text");
MockRequest mock;
struct wfp_request * request = request_create(&mock, 23);
char const * contained_elements[] = {"text.file", nullptr};
EXPECT_CALL(mock, respond(ReaddirMatcher(contained_elements), 23)).Times(1);
config->provider.readdir(request, 1, config->user_data);
wfp_impl_static_filesystem_dispose(filesystem);
wfp_client_config_dispose(config);
}