mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
added ondispose to mountpoint to allow custom cleanup
This commit is contained in:
parent
e727a9a54d
commit
6a94cea6f9
@ -8,6 +8,10 @@ extern "C"
|
|||||||
|
|
||||||
struct wf_mountpoint;
|
struct wf_mountpoint;
|
||||||
|
|
||||||
|
typedef void
|
||||||
|
wf_mountpoint_ondispose_fn(
|
||||||
|
struct wf_mountpoint * mountpoint);
|
||||||
|
|
||||||
extern struct wf_mountpoint *
|
extern struct wf_mountpoint *
|
||||||
wf_mountpoint_create(
|
wf_mountpoint_create(
|
||||||
char const * path);
|
char const * path);
|
||||||
@ -20,6 +24,11 @@ extern char const *
|
|||||||
wf_mountpoint_get_path(
|
wf_mountpoint_get_path(
|
||||||
struct wf_mountpoint const * mountpoint);
|
struct wf_mountpoint const * mountpoint);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
wf_mountpoint_set_ondispose(
|
||||||
|
struct wf_mountpoint * mountpoint,
|
||||||
|
wf_mountpoint_ondispose_fn * ondispose);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -158,3 +158,11 @@ wf_mountpoint_get_path(
|
|||||||
{
|
{
|
||||||
return wf_impl_mountpoint_get_path(mountpoint);
|
return wf_impl_mountpoint_get_path(mountpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_mountpoint_set_ondispose(
|
||||||
|
struct wf_mountpoint * mountpoint,
|
||||||
|
wf_mountpoint_ondispose_fn * ondispose)
|
||||||
|
{
|
||||||
|
wf_impl_mountpoint_set_ondispose(mountpoint, ondispose);
|
||||||
|
}
|
||||||
|
@ -6,14 +6,23 @@
|
|||||||
struct wf_mountpoint
|
struct wf_mountpoint
|
||||||
{
|
{
|
||||||
char * path;
|
char * path;
|
||||||
|
wf_mountpoint_ondispose_fn * ondispose;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void wf_impl_mountpoint_default_ondispose(
|
||||||
|
struct wf_mountpoint * mountpoint)
|
||||||
|
{
|
||||||
|
(void) mountpoint;
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
struct wf_mountpoint *
|
struct wf_mountpoint *
|
||||||
wf_impl_mountpoint_create(
|
wf_impl_mountpoint_create(
|
||||||
char const * path)
|
char const * path)
|
||||||
{
|
{
|
||||||
struct wf_mountpoint * mountpoint = malloc(sizeof(struct wf_mountpoint));
|
struct wf_mountpoint * mountpoint = malloc(sizeof(struct wf_mountpoint));
|
||||||
mountpoint->path = strdup(path);
|
mountpoint->path = strdup(path);
|
||||||
|
mountpoint->ondispose = &wf_impl_mountpoint_default_ondispose;
|
||||||
|
|
||||||
return mountpoint;
|
return mountpoint;
|
||||||
}
|
}
|
||||||
@ -22,6 +31,8 @@ void
|
|||||||
wf_impl_mountpoint_dispose(
|
wf_impl_mountpoint_dispose(
|
||||||
struct wf_mountpoint * mountpoint)
|
struct wf_mountpoint * mountpoint)
|
||||||
{
|
{
|
||||||
|
mountpoint->ondispose(mountpoint);
|
||||||
|
|
||||||
free(mountpoint->path);
|
free(mountpoint->path);
|
||||||
free(mountpoint);
|
free(mountpoint);
|
||||||
}
|
}
|
||||||
@ -32,3 +43,11 @@ wf_impl_mountpoint_get_path(
|
|||||||
{
|
{
|
||||||
return mountpoint->path;
|
return mountpoint->path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wf_impl_mountpoint_set_ondispose(
|
||||||
|
struct wf_mountpoint * mountpoint,
|
||||||
|
wf_mountpoint_ondispose_fn * ondispose)
|
||||||
|
{
|
||||||
|
mountpoint->ondispose = ondispose;
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef WF_IMPL_MOUNTPOINT_H
|
#ifndef WF_IMPL_MOUNTPOINT_H
|
||||||
#define WF_IMPL_MOUNTPOINT_H
|
#define WF_IMPL_MOUNTPOINT_H
|
||||||
|
|
||||||
|
#include "webfuse/adapter/mountpoint.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@ -18,6 +20,10 @@ extern char const *
|
|||||||
wf_impl_mountpoint_get_path(
|
wf_impl_mountpoint_get_path(
|
||||||
struct wf_mountpoint const * mountpoint);
|
struct wf_mountpoint const * mountpoint);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
wf_impl_mountpoint_set_ondispose(
|
||||||
|
struct wf_mountpoint * mointpoint,
|
||||||
|
wf_mountpoint_ondispose_fn * ondispose);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,45 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <gmock/gmock.h>
|
||||||
#include "webfuse/adapter/mountpoint.h"
|
#include "webfuse/adapter/mountpoint.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class MockMountpointDisposer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MOCK_METHOD1(ondispose, void(wf_mountpoint * mountpoint));
|
||||||
|
};
|
||||||
|
|
||||||
|
MockMountpointDisposer * global_disposer = nullptr;
|
||||||
|
|
||||||
|
void ondispose(wf_mountpoint * mountpoint)
|
||||||
|
{
|
||||||
|
global_disposer->ondispose(mountpoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(mountpoint, get_path)
|
TEST(mountpoint, get_path)
|
||||||
{
|
{
|
||||||
wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path");
|
wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path");
|
||||||
|
|
||||||
ASSERT_NE(nullptr, mountpoint);
|
ASSERT_NE(nullptr, mountpoint);
|
||||||
|
|
||||||
ASSERT_STREQ("/some/path", wf_mountpoint_get_path(mountpoint));
|
ASSERT_STREQ("/some/path", wf_mountpoint_get_path(mountpoint));
|
||||||
|
|
||||||
wf_mountpoint_dispose(mountpoint);
|
wf_mountpoint_dispose(mountpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST(mountpoint, ondispose)
|
||||||
|
{
|
||||||
|
MockMountpointDisposer disposer;
|
||||||
|
global_disposer = &disposer;
|
||||||
|
|
||||||
|
wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path");
|
||||||
|
ASSERT_NE(nullptr, mountpoint);
|
||||||
|
|
||||||
|
wf_mountpoint_set_ondispose(mountpoint, ondispose);
|
||||||
|
EXPECT_CALL(disposer, ondispose(mountpoint)).Times(1);
|
||||||
|
|
||||||
|
wf_mountpoint_dispose(mountpoint);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user