Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix merlint and dupfind issues in irmin

- Extract shared rm_rf into test_helpers.ml (was duplicated 4x)
- Fix catch-all exception in pds_interop.ml (now catches Eio.Io)
- Extract err_invalid_cid helper in backend.ml Disk module

dupfind: 0 clones. merlint: only docs/naming suggestions remain.

+30 -51
+4 -2
lib/backend.ml
··· 552 552 let sha256 ~sw root = 553 553 pack_disk ~sw root Hash.to_hex Hash.sha256_of_hex Hash.equal 554 554 555 + let err_invalid_cid s exn = 556 + Error (`Msg (Fmt.str "invalid CID %S: %s" s (Printexc.to_string exn))) 557 + 555 558 let cid ~sw root = 556 559 pack_disk ~sw root Atp.Cid.to_string 557 560 (fun s -> 558 561 try Ok (Atp.Cid.of_string s) 559 - with exn -> 560 - Error (`Msg (Fmt.str "invalid CID %S: %s" s (Printexc.to_string exn)))) 562 + with Eio.Io _ as exn -> err_invalid_cid s exn) 561 563 Atp.Cid.equal 562 564 end
+1 -1
lib/pds_interop.ml
··· 29 29 30 30 let decode_ref_cid data = 31 31 match Atp.Dagcbor.decode_string ~cid_format:`Atproto data with 32 - | `String s -> ( try Some (Atp.Cid.of_string s) with _ -> None) 32 + | `String s -> ( try Some (Atp.Cid.of_string s) with Eio.Io _ -> None) 33 33 | _ -> None 34 34 35 35 module Pds_backend : Backend.S with type t = Pds.t and type hash = Atp.Cid.t =
+5 -12
test/test_backend.ml
··· 1 1 open Irmin 2 2 open Private 3 3 4 - let rec rm_rf path = 5 - if Eio.Path.is_directory path then begin 6 - List.iter 7 - (fun name -> rm_rf Eio.Path.(path / name)) 8 - (Eio.Path.read_dir path); 9 - Eio.Path.rmdir path 10 - end 11 - else if Eio.Path.is_file path then Eio.Path.unlink path 12 - 13 4 let with_temp_dir f = 14 5 Eio_main.run @@ fun env -> 15 6 let cwd = Eio.Stdenv.cwd env in ··· 17 8 let tmp_name = Fmt.str "irmin-test-%d" (Random.int 100000) in 18 9 let tmp_path = Eio.Path.(cwd / tmp_name) in 19 10 Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 tmp_path; 20 - Fun.protect ~finally:(fun () -> rm_rf tmp_path) (fun () -> f ~sw tmp_path) 11 + Fun.protect 12 + ~finally:(fun () -> Test_helpers.rm_rf tmp_path) 13 + (fun () -> f ~sw tmp_path) 21 14 22 15 let test_memory_backend () = 23 16 let backend = Backend.Memory.sha1 () in ··· 90 83 "ref persisted" true 91 84 (Option.is_some (Backend.get_ref backend "refs/heads/main")); 92 85 Backend.close backend); 93 - rm_rf tmp_path 86 + Test_helpers.rm_rf tmp_path 94 87 95 88 let test_disk_backend_refs () = 96 89 with_temp_dir @@ fun ~sw tmp_path -> ··· 149 142 "exists after recovery" true 150 143 (Backend.exists backend hash); 151 144 Backend.close backend); 152 - rm_rf tmp_path 145 + Test_helpers.rm_rf tmp_path 153 146 154 147 let suite = 155 148 ( "backend",
+3 -10
test/test_git_interop.ml
··· 1 1 open Irmin 2 2 open Private 3 3 4 - let rec rm_rf path = 5 - if Eio.Path.is_directory path then begin 6 - List.iter 7 - (fun name -> rm_rf Eio.Path.(path / name)) 8 - (Eio.Path.read_dir path); 9 - Eio.Path.rmdir path 10 - end 11 - else if Eio.Path.is_file path then Eio.Path.unlink path 12 - 13 4 let with_temp_dir f = 14 5 Eio_main.run @@ fun env -> 15 6 let fs = Eio.Stdenv.fs env in ··· 18 9 let tmp_name = Fmt.str "irmin-git-test-%d" (Random.int 100000) in 19 10 let tmp_path = Eio.Path.(cwd / tmp_name) in 20 11 Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 tmp_path; 21 - Fun.protect ~finally:(fun () -> rm_rf tmp_path) (fun () -> f ~sw ~fs tmp_path) 12 + Fun.protect 13 + ~finally:(fun () -> Test_helpers.rm_rf tmp_path) 14 + (fun () -> f ~sw ~fs tmp_path) 22 15 23 16 let test_init_git () = 24 17 with_temp_dir @@ fun ~sw ~fs tmp_path ->
+8
test/test_helpers.ml
··· 1 + let rec rm_rf path = 2 + if Eio.Path.is_directory path then begin 3 + List.iter 4 + (fun name -> rm_rf Eio.Path.(path / name)) 5 + (Eio.Path.read_dir path); 6 + Eio.Path.rmdir path 7 + end 8 + else if Eio.Path.is_file path then Eio.Path.unlink path
+1
test/test_helpers.mli
··· 1 + val rm_rf : _ Eio.Path.t -> unit
+5 -14
test/test_pds_interop.ml
··· 9 9 10 10 let test_did = Atp.Did.of_string_exn "did:web:example.com" 11 11 12 - let rec rm_rf path = 13 - if Eio.Path.is_directory path then begin 14 - List.iter 15 - (fun name -> rm_rf Eio.Path.(path / name)) 16 - (Eio.Path.read_dir path); 17 - Eio.Path.rmdir path 18 - end 19 - else if Eio.Path.is_file path then Eio.Path.unlink path 20 - 21 12 let with_temp_dir f = 22 13 Eio_main.run @@ fun env -> 23 14 let cwd = Eio.Stdenv.cwd env in ··· 26 17 let name = Fmt.str "repo_%d" (Random.int 1_000_000) in 27 18 let path = Eio.Path.(tmp_dir / name) in 28 19 Fun.protect 29 - ~finally:(fun () -> try rm_rf path with Eio.Io _ -> ()) 20 + ~finally:(fun () -> try Test_helpers.rm_rf path with Eio.Io _ -> ()) 30 21 (fun () -> f path) 31 22 32 23 (* ---- PDS write → MST read ---- *) ··· 202 193 let path2 = Eio.Path.(tmp_dir / name2) in 203 194 Fun.protect 204 195 ~finally:(fun () -> 205 - (try rm_rf path1 with Eio.Io _ -> ()); 206 - try rm_rf path2 with Eio.Io _ -> ()) 196 + (try Test_helpers.rm_rf path1 with Eio.Io _ -> ()); 197 + try Test_helpers.rm_rf path2 with Eio.Io _ -> ()) 207 198 (fun () -> 208 199 (* Create source repo with data *) 209 200 let car_data = ··· 234 225 let name = Fmt.str "persist_%d" (Random.int 1_000_000) in 235 226 let path = Eio.Path.(tmp_dir / name) in 236 227 Fun.protect 237 - ~finally:(fun () -> try rm_rf path with Eio.Io _ -> ()) 228 + ~finally:(fun () -> try Test_helpers.rm_rf path with Eio.Io _ -> ()) 238 229 (fun () -> 239 230 let data = 240 231 Atp.Dagcbor.encode_string ~cid_format:`Atproto ··· 274 265 let name = Fmt.str "did_%d" (Random.int 1_000_000) in 275 266 let path = Eio.Path.(tmp_dir / name) in 276 267 Fun.protect 277 - ~finally:(fun () -> try rm_rf path with Eio.Io _ -> ()) 268 + ~finally:(fun () -> try Test_helpers.rm_rf path with Eio.Io _ -> ()) 278 269 (fun () -> 279 270 let custom_did = Atp.Did.of_string_exn "did:plc:abc123xyz" in 280 271 Eio.Switch.run (fun sw ->
+3 -12
test/test_stores.ml
··· 1 1 (** Backend configs for the generic store test suite. Tests all combinations: 2 2 in-memory, on-disk, Git, PDS. *) 3 3 4 - let rec rm_rf path = 5 - if Eio.Path.is_directory path then begin 6 - List.iter 7 - (fun name -> rm_rf Eio.Path.(path / name)) 8 - (Eio.Path.read_dir path); 9 - Eio.Path.rmdir path 10 - end 11 - else if Eio.Path.is_file path then Eio.Path.unlink path 12 - 13 4 (* {1 MST in-memory (SHA-256)} *) 14 5 15 6 let mst_memory = ··· 25 16 let name = Fmt.str "/tmp/irmin-test-mst-%d" (Random.int 1_000_000) in 26 17 let path = Eio.Path.(fs / name) in 27 18 Fun.protect 28 - ~finally:(fun () -> try rm_rf path with _ -> ()) 19 + ~finally:(fun () -> try Test_helpers.rm_rf path with _ -> ()) 29 20 (fun () -> f (Irmin.Mst.disk ~sw path))) 30 21 31 22 (* {1 Git (SHA-1, on-disk)} *) ··· 38 29 let name = Fmt.str "/tmp/irmin-test-git-%d" (Random.int 1_000_000) in 39 30 let path = Eio.Path.(fs / name) in 40 31 Fun.protect 41 - ~finally:(fun () -> try rm_rf path with _ -> ()) 32 + ~finally:(fun () -> try Test_helpers.rm_rf path with _ -> ()) 42 33 (fun () -> f (Irmin.Git.init ~sw ~fs ~path:(Fpath.v name)))) 43 34 44 35 (* {1 ATProto PDS (CID/DAG-CBOR, on-disk)} *) ··· 52 43 let path = Eio.Path.(cwd / "_build" / name) in 53 44 (try Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 path with _ -> ()); 54 45 Fun.protect 55 - ~finally:(fun () -> try rm_rf path with _ -> ()) 46 + ~finally:(fun () -> try Test_helpers.rm_rf path with _ -> ()) 56 47 (fun () -> 57 48 let did = Atp.Did.of_string_exn "did:web:test.irmin" in 58 49 let p = Pds.v ~sw path ~did in