1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00
falk-werner_webfuse-provider/src/wsfs/operation/readdir.c

41 lines
993 B
C
Raw Normal View History

2019-01-29 22:11:46 +00:00
#include "wsfs/operations.h"
#include <jansson.h>
#include "wsfs/util.h"
#include "wsfs/jsonrpc.h"
int wsfs_operation_readdir(
char const * path,
void * buffer,
fuse_fill_dir_t filler,
off_t WSFS_UNUSED_PARAM(offset),
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info),
enum fuse_readdir_flags WSFS_UNUSED_PARAM(flags))
{
struct fuse_context * context = fuse_get_context();
struct wsfs_jsonrpc * rpc = context->private_data;
json_t * result = NULL;
wsfs_status const status = wsfs_jsonrpc_invoke(rpc, &result, "readdir", "s", path);
if (NULL != result)
{
if (json_is_array(result))
{
bool buffer_full = false;
size_t const count = json_array_size(result);
for(size_t i = 0; (!buffer_full) && (i < count); i++)
{
json_t * entry =json_array_get(result, i);
if (json_is_string(entry))
{
buffer_full = filler(buffer, json_string_value(entry), NULL, 0, 0);
}
}
}
json_decref(result);
}
return wsfs_status_to_rc(status);
}