summaryrefslogtreecommitdiff
path: root/lib/prefetch.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/prefetch.ml')
-rw-r--r--lib/prefetch.ml34
1 files changed, 34 insertions, 0 deletions
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;