Implement list function

This commit is contained in:
Romain Calascibetta 2022-09-21 12:02:34 +02:00
parent ad09080ee6
commit 503bf47ccb

View file

@ -143,9 +143,22 @@ let get_partial t key ~offset ~length =
let l = min length (String.length data - offset) in
String.sub data offset l
let list _t _key =
(* ((string * [`Value | `Dictionary]) list, error) result Lwt.t *)
assert false
let list t key =
let open Lwt.Infix in
match t.head with
| None -> Lwt.return (Error (`Not_found key))
| Some head ->
Search.find t.store head (`Path (Mirage_kv.Key.segments key)) >>= function
| None -> Lwt.return (Error (`Not_found key))
| Some tree ->
Store.read_exn t.store tree >>= function
| Tree t ->
Lwt_list.map_p (fun { Git.Tree.perm; name; _ } -> match perm with
| `Commit | `Dir -> Lwt.return (name, `Dictionary)
| `Everybody | `Exec | `Normal -> Lwt.return (name, `Value)
| `Link -> failwith "Unimplemented link follow")
(Store.Value.Tree.to_list t) >|= Result.ok
| _ -> Lwt.return (Error (`Dictionary_expected key))
let last_modified t key =
let open Lwt.Infix in