added implemention of readdir

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

@ -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;
} }

@ -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);
} }

Loading…
Cancel
Save