From f0fc310fe424d5657f416a7fd1c908cb4590e8e9 Mon Sep 17 00:00:00 2001 From: ยท๐‘‘๐‘ด๐‘•๐‘‘๐‘ฉ๐‘ค Date: Wed, 31 Dec 2025 14:21:34 +0000 Subject: Prefetch: File+Archive stdout result into module --- lib/prefetch.ml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'lib/prefetch.ml') diff --git a/lib/prefetch.ml b/lib/prefetch.ml index 3cc4c2f..c4685b8 100644 --- a/lib/prefetch.ml +++ b/lib/prefetch.ml @@ -27,6 +27,40 @@ module Hash = struct |> Object.opt_mem "sha512" string end +module File = struct + type t = { + path: string; + hash_value: string; + } + + (* env can assert it is a path *) + let of_stdout ?env (stdout : string) : t option = + match String.split_on_char '\n' (String.trim stdout), env with + | hash_value :: path :: _, None -> + Some {path; hash_value} + | hash_value :: path :: _, Some env' when Option.is_some (Eio.Path.native (Eio.Path.(Eio.Stdenv.fs env' / path))) -> + Some {path; hash_value} + | _ -> + None +end + +module Archive = struct + type t = { + path: string; + hash_value: string; + } + + (* env can assert it is a path *) + let of_stdout ?env (stdout : string) : t option = + match String.split_on_char '\n' (String.trim stdout), env with + | hash_value :: path :: _, None -> + Some {path; hash_value} + | hash_value :: path :: _, Some env' when Option.is_some (Eio.Path.native (Eio.Path.(Eio.Stdenv.fs env' / path))) -> + Some {path; hash_value} + | _ -> + None +end + module Git = struct type t = { datetime: string option; -- cgit v1.2.3