Implement exists function
This commit is contained in:
parent
b1bfa51f2f
commit
2ef62f3307
1 changed files with 12 additions and 4 deletions
|
@ -109,10 +109,18 @@ let of_octets ctx ~remote data =
|
||||||
let edn, branch = split_url remote in
|
let edn, branch = split_url remote in
|
||||||
{ ctx ; edn ; branch ; store ; head = Some head }
|
{ ctx ; edn ; branch ; store ; head = Some head }
|
||||||
|
|
||||||
let exists _t _key =
|
let exists t key =
|
||||||
(* Search.find t.store t.head (`Path (Mirage_kv.Key.segments key)) >>= function *)
|
let open Lwt.Infix in
|
||||||
(* ([`Value | `Dictionary] option, error) result Lwt.t *)
|
match t.head with
|
||||||
assert false
|
| None -> Lwt.return (Ok None)
|
||||||
|
| Some head ->
|
||||||
|
Search.mem t.store head (`Path (Mirage_kv.Key.segments key)) >>= function
|
||||||
|
| false -> Lwt.return (Ok None)
|
||||||
|
| true ->
|
||||||
|
Search.find t.store head (`Path (Mirage_kv.Key.segments key))
|
||||||
|
>|= Option.get >>= Store.read_exn t.store >>= function
|
||||||
|
| Blob _ -> Lwt.return (Ok (Some `Value))
|
||||||
|
| Tree _ | Commit _ | Tag _ -> Lwt.return (Ok (Some `Dictionary))
|
||||||
|
|
||||||
let get t key =
|
let get t key =
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
|
|
Loading…
Reference in a new issue