Return error on bad checksum when finalizing write

This commit is contained in:
Reynir Björnsson 2023-01-31 10:27:25 +01:00
parent a3128e1de5
commit 1a6c6b8f9d

View file

@ -468,7 +468,7 @@ module Make
let dest = to_delete_key (hash, csum) in let dest = to_delete_key (hash, csum) in
(* if the checksums mismatch we need to mark the file for deletion *) (* if the checksums mismatch we need to mark the file for deletion *)
KV.rename t.dev ~source ~dest >|= function KV.rename t.dev ~source ~dest >|= function
| Ok () -> Ok () | Ok () -> Error (`Bad_checksum (hash, csum))
| Error e -> | Error e ->
Logs.warn (fun m -> m "Error renaming file %a -> %a: %a" Logs.warn (fun m -> m "Error renaming file %a -> %a: %a"
Mirage_kv.Key.pp source Mirage_kv.Key.pp dest KV.pp_write_error e); Mirage_kv.Key.pp source Mirage_kv.Key.pp dest KV.pp_write_error e);
@ -886,6 +886,7 @@ stamp: %S
let body = Httpaf.Reqd.respond_with_streaming reqd resp in let body = Httpaf.Reqd.respond_with_streaming reqd resp in
Disk.read_chunked store h hash (fun () chunk -> Disk.read_chunked store h hash (fun () chunk ->
let wait, wakeup = Lwt.task () in let wait, wakeup = Lwt.task () in
(* FIXME: catch exception when body is closed *)
Httpaf.Body.write_string body chunk; Httpaf.Body.write_string body chunk;
Httpaf.Body.flush body (Lwt.wakeup wakeup); Httpaf.Body.flush body (Lwt.wakeup wakeup);
wait) () >|= fun _ -> wait) () >|= fun _ ->