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,20 +296,23 @@ 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 ();
let abs_path = Fpath.(v datadir // artifact_path sha256) in if not (FpathSet.mem (artifact_path sha256) !files_tracked) then
(match Bos.OS.File.read abs_path with let abs_path = Fpath.(v datadir // artifact_path sha256) in
| Error (`Msg msg) -> Logs.err (fun m -> m "file %a not present: %s" Fpath.pp abs_path msg) (match Bos.OS.File.read abs_path with
| Ok data -> | Error (`Msg msg) -> Logs.err (fun m -> m "file %a not present: %s" Fpath.pp abs_path msg)
files_tracked := FpathSet.add (artifact_path sha256) !files_tracked; | Ok data ->
let s = Int64.of_int (String.length data) in files_tracked := FpathSet.add (artifact_path sha256) !files_tracked;
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 s = Int64.of_int (String.length data) in
let sha256' = Mirage_crypto.Hash.SHA256.digest (Cstruct.of_string data) in 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 not (Cstruct.equal sha256 sha256') then let sha256' = Mirage_crypto.Hash.SHA256.digest (Cstruct.of_string data) in
Logs.err (fun m -> m "File %a has different hash (in DB %a on disk %a" if not (Cstruct.equal sha256 sha256') then
Fpath.pp abs_path Logs.err (fun m -> m "File %a has different hash (in DB %a on disk %a)"
Hex.pp (Hex.of_cstruct sha256) Fpath.pp abs_path
Hex.pp (Hex.of_cstruct sha256'))) ; Hex.pp (Hex.of_cstruct sha256)
Ok () Hex.pp (Hex.of_cstruct sha256'))) ;
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) ->