1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

added implemention of readdir

This commit is contained in:
user 2019-01-27 10:17:48 +01:00
parent 6ba4e3934d
commit 318b9afdf9
2 changed files with 39 additions and 3 deletions

View File

@ -23,7 +23,7 @@ function startup()
} }
FileSystem.prototype.getattr = function(path) { FileSystem.prototype.getattr = function(path) {
entry = this.getEntry(path); var entry = this.getEntry(path);
if (entry) { if (entry) {
return { return {
mode: entry.mode || 0755, mode: entry.mode || 0755,
@ -39,6 +39,25 @@ function startup()
} }
}; };
FileSystem.prototype.readdir = function(path) {
var result, entry, subdir, i, len;
entry = this.getEntry(path);
if ((entry) && (entry.type == "dir")) {
result = [".", ".."];
for(subdir in entry.entries) {
if (entry.entries.hasOwnProperty(subdir)) {
result.push(subdir);
}
}
}
else {
result = FileSystem.BAD_NO_ENTRY;
}
return result;
};
var fs = new FileSystem({ var fs = new FileSystem({
mode: 0755, mode: 0755,
type: "dir", type: "dir",
@ -70,6 +89,9 @@ function startup()
case "getattr": case "getattr":
result = fs.getattr(request.params[0]); result = fs.getattr(request.params[0]);
break; break;
case "readdir":
result = fs.readdir(request.params[0]);
break;
default: default:
break; break;
} }

View File

@ -88,13 +88,27 @@ wsfs_status wsfs_filesystem_getattr(
wsfs_status wsfs_filesystem_readdir( wsfs_status wsfs_filesystem_readdir(
struct wsfs_filesystem * filesystem, struct wsfs_filesystem * filesystem,
char const * path, char const * path,
void * WSFS_UNUSED_PARAM(buffer), void * buffer,
wsfs_add_entry_fn * WSFS_UNUSED_PARAM(add_entry)) wsfs_add_entry_fn * add_entry)
{ {
json_t * result = NULL; json_t * result = NULL;
wsfs_status const status = wsfs_jsonrpc_invoke(filesystem->rpc, &result, "readdir", "s", path); wsfs_status const status = wsfs_jsonrpc_invoke(filesystem->rpc, &result, "readdir", "s", path);
if (NULL != result) if (NULL != result)
{ {
if (json_is_array(result))
{
bool has_capacity = true;
size_t const count = json_array_size(result);
for(size_t i = 0; (has_capacity) && (i < count); i++)
{
json_t * entry =json_array_get(result, i);
if (json_is_string(entry))
{
has_capacity = add_entry(buffer, json_string_value(entry));
}
}
}
json_decref(result); json_decref(result);
} }