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

MinaProtocol / mina / 2850

30 Oct 2024 07:56AM UTC coverage: 33.411% (-27.7%) from 61.098%
2850

push

buildkite

web-flow
Merge pull request #16306 from MinaProtocol/dkijania/fix_promotion_to_gcr

Fix promotion job PUBLISH misuse

22272 of 66661 relevant lines covered (33.41%)

129089.82 hits per line

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

74.29
/src/lib/key_cache/sync/key_cache_sync.ml
1
open Core
2
open Key_cache
3
include T (Or_error)
4

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

24
module Disk_storable = struct
25
  include Disk_storable (Or_error)
26

27
  let of_binable to_string m =
28
    (* TODO: Make more efficient *)
29
    let read _ ~path =
×
30
      Or_error.try_with (fun () ->
×
31
          Binable.of_string m (In_channel.read_all path) )
×
32
    in
33
    let write _k t path =
34
      Or_error.try_with (fun () ->
×
35
          Out_channel.write_all path ~data:(Binable.to_string m t) )
×
36
    in
37
    { to_string; read; write }
38

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

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

59
let write spec { Disk_storable.to_string; read = r; write = w } k v =
60
  let errs =
16✔
61
    List.filter_map spec ~f:(fun s ->
62
        let res =
76✔
63
          match s with
64
          | Spec.On_disk { directory; should_write } ->
64✔
65
              if should_write then (
16✔
66
                Unix.mkdir_p directory ;
67
                (on_disk to_string r w directory).write k v )
16✔
68
              else Or_error.return ()
48✔
69
          | S3 { bucket_prefix = _; install_path = _ } ->
12✔
70
              Or_error.return ()
12✔
71
        in
72
        match res with Error e -> Some e | Ok () -> None )
4✔
73
  in
74
  match errs with [] -> Ok () | errs -> Error (Error.of_list errs)
2✔
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

© 2026 Coveralls, Inc