added implemention of readdir

pull/2/head
user 5 years ago
parent 6ba4e3934d
commit 318b9afdf9

@ -23,7 +23,7 @@ function startup()
}
FileSystem.prototype.getattr = function(path) {
entry = this.getEntry(path);
var entry = this.getEntry(path);
if (entry) {
return {
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({
mode: 0755,
type: "dir",
@ -70,6 +89,9 @@ function startup()
case "getattr":
result = fs.getattr(request.params[0]);
break;
case "readdir":
result = fs.readdir(request.params[0]);
break;
default:
break;
}

@ -88,13 +88,27 @@ wsfs_status wsfs_filesystem_getattr(
wsfs_status wsfs_filesystem_readdir(
struct wsfs_filesystem * filesystem,
char const * path,
void * WSFS_UNUSED_PARAM(buffer),
wsfs_add_entry_fn * WSFS_UNUSED_PARAM(add_entry))
void * buffer,
wsfs_add_entry_fn * add_entry)
{
json_t * result = NULL;
wsfs_status const status = wsfs_jsonrpc_invoke(filesystem->rpc, &result, "readdir", "s", path);
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);
}

Loading…
Cancel
Save