builder_db_app: verify_data_dir: compute size and sha256 only once per artifact

This commit is contained in:
Robur 2024-01-09 14:48:53 +00:00
parent f66932da48
commit 1e522e2b39

View file

@ -296,6 +296,7 @@ let verify_data_dir () datadir =
let* () = let* () =
Db.iter_s build_artifacts (fun (_job, _uuid, (_fpath, sha256, size)) -> Db.iter_s build_artifacts (fun (_job, _uuid, (_fpath, sha256, size)) ->
progress (); progress ();
if not (FpathSet.mem (artifact_path sha256) !files_tracked) then
let abs_path = Fpath.(v datadir // artifact_path sha256) in let abs_path = Fpath.(v datadir // artifact_path sha256) in
(match Bos.OS.File.read abs_path with (match Bos.OS.File.read abs_path with
| Error (`Msg msg) -> Logs.err (fun m -> m "file %a not present: %s" Fpath.pp abs_path msg) | Error (`Msg msg) -> Logs.err (fun m -> m "file %a not present: %s" Fpath.pp abs_path msg)
@ -305,11 +306,13 @@ let verify_data_dir () datadir =
if s <> size then Logs.err (fun m -> m "File %a has different size (in DB %Lu on disk %Lu)" Fpath.pp abs_path size s); if s <> size then Logs.err (fun m -> m "File %a has different size (in DB %Lu on disk %Lu)" Fpath.pp abs_path size s);
let sha256' = Mirage_crypto.Hash.SHA256.digest (Cstruct.of_string data) in let sha256' = Mirage_crypto.Hash.SHA256.digest (Cstruct.of_string data) in
if not (Cstruct.equal sha256 sha256') then if not (Cstruct.equal sha256 sha256') then
Logs.err (fun m -> m "File %a has different hash (in DB %a on disk %a" Logs.err (fun m -> m "File %a has different hash (in DB %a on disk %a)"
Fpath.pp abs_path Fpath.pp abs_path
Hex.pp (Hex.of_cstruct sha256) Hex.pp (Hex.of_cstruct sha256)
Hex.pp (Hex.of_cstruct sha256'))) ; Hex.pp (Hex.of_cstruct sha256'))) ;
Ok () Ok ()
else
Ok ()
) () ) ()
in in
Db.iter_s script_and_console (fun (job, uuid, console, script) -> Db.iter_s script_and_console (fun (job, uuid, console, script) ->