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

feature: try to create mount point, if not present

This commit is contained in:
Falk Werner 2019-03-11 23:21:49 +01:00
parent 7dd3827555
commit c5cebc7cf2

View File

@ -4,6 +4,10 @@
#include <stdbool.h> #include <stdbool.h>
#include <libwebsockets.h> #include <libwebsockets.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "wsfs/adapter/server_config_intern.h" #include "wsfs/adapter/server_config_intern.h"
#include "wsfs/adapter/server_protocol_intern.h" #include "wsfs/adapter/server_protocol_intern.h"
@ -74,10 +78,34 @@ static struct lws_context * wsfs_server_context_create(
} }
static bool wsfs_server_check_mountpoint(
struct wsfs_server_config * config)
{
bool result = false;
if (NULL != config->mount_point)
{
struct stat info;
int const rc = stat(config->mount_point, &info);
bool const isDir = ((0 == rc) && (S_ISDIR(info.st_mode)));
if (!isDir)
{
result = (0 == mkdir(config->mount_point, 0755));
}
}
return result;
}
struct wsfs_server * wsfs_server_create( struct wsfs_server * wsfs_server_create(
struct wsfs_server_config * config) struct wsfs_server_config * config)
{ {
struct wsfs_server * server = malloc(sizeof(struct wsfs_server)); struct wsfs_server * server = NULL;
if (wsfs_server_check_mountpoint(config))
{
server = malloc(sizeof(struct wsfs_server));
if (NULL != server) if (NULL != server)
{ {
if (wsfs_server_protocol_init(&server->protocol, config->mount_point)) if (wsfs_server_protocol_init(&server->protocol, config->mount_point))
@ -92,6 +120,7 @@ struct wsfs_server * wsfs_server_create(
server = NULL; server = NULL;
} }
} }
}
return server; return server;
} }