• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MinaProtocol / mina / 1612

21 Oct 2024 08:28AM UTC coverage: 61.111% (+0.02%) from 61.093%
1612

push

buildkite

web-flow
Merge pull request #16255 from MinaProtocol/release/3.0.2

682 of 1335 new or added lines in 129 files covered. (51.09%)

148 existing lines in 47 files now uncovered.

47180 of 77204 relevant lines covered (61.11%)

555482.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/lib/key_cache/async/key_cache_async.ml
1
open Core
2
open Async
3
open Key_cache
4
open Async_kernel
5
include T (Deferred.Or_error)
6

7
let on_disk to_string read write prefix =
8
  let path k = prefix ^/ to_string k in
×
9
  let read k =
10
    let p = path k in
×
11
    match%bind Sys.file_exists p with
×
12
    | `No | `Unknown ->
×
13
        return (Or_error.errorf "file %s does not exist or cannot be read" p)
×
14
    | `Yes ->
×
15
        read k ~path:p
16
  in
17
  let write key v =
18
    match%bind Sys.is_directory prefix with
×
19
    | `No | `Unknown ->
×
20
        return
21
          (Or_error.errorf "directory %s does not exist or cannot be read"
×
22
             prefix )
23
    | `Yes ->
×
24
        write key v (path key)
×
25
  in
26
  { read; write }
27

28
module Disk_storable = struct
29
  include Disk_storable (Deferred.Or_error)
30

31
  let of_binable (type t) to_string (module B : Binable.S with type t = t) =
32
    let read _ ~path = Reader.load_bin_prot path B.bin_reader_t in
×
33
    let write _ t path =
34
      Deferred.map
×
35
        (Writer.save_bin_prot path B.bin_writer_t t)
×
36
        ~f:Or_error.return
37
    in
38
    { to_string; read; write }
39

40
  let simple to_string read write =
41
    { to_string
×
42
    ; read = (fun k ~path -> read k ~path)
×
43
    ; write = (fun v s -> write v s)
×
44
    }
45
end
46

47
let read spec { Disk_storable.to_string; read = r; write = w } k =
48
  Deferred.Or_error.find_map_ok spec ~f:(fun s ->
×
49
      let open Deferred.Or_error.Let_syntax in
×
50
      match s with
51
      | Spec.On_disk { directory; should_write } ->
×
52
          let%map res = (on_disk to_string r w directory).read k in
×
53
          (res, if should_write then `Locally_generated else `Cache_hit)
×
NEW
54
      | S3 _ ->
×
55
          Deferred.Or_error.errorf "Downloading from S3 is disabled" )
56

57
let write spec { Disk_storable.to_string; read = r; write = w } k v =
58
  let%map errs =
59
    Deferred.List.filter_map spec ~f:(fun s ->
×
60
        let res =
×
61
          match s with
62
          | Spec.On_disk { directory; should_write } ->
×
63
              if should_write then
64
                let%bind () = Unix.mkdir ~p:() directory in
×
65
                (on_disk to_string r w directory).write k v
×
66
              else Deferred.Or_error.return ()
×
67
          | S3 { bucket_prefix = _; install_path = _ } ->
×
68
              Deferred.Or_error.return ()
×
69
        in
70
        match%map res with Error e -> Some e | Ok () -> None )
×
71
  in
72
  match errs with [] -> Ok () | errs -> Error (Error.of_list errs)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc