summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/input_foreman.ml18
-rw-r--r--lib/prefetch.ml34
2 files changed, 42 insertions, 10 deletions
diff --git a/lib/input_foreman.ml b/lib/input_foreman.ml
index ed6374a..4b8b3f1 100644
--- a/lib/input_foreman.ml
+++ b/lib/input_foreman.ml
@@ -295,14 +295,13 @@ let prefetch ~env ~proc_mgr ~name () : (unit, error) result =
| Ok stdout ->
begin
Logs.debug (fun m -> m "Command output: %s" stdout);
- match String.split_on_char '\n' (String.trim stdout) with
- | hash :: path :: _ when Option.is_some (Eio.Path.native (Eio.Path.(Eio.Stdenv.fs env / path))) ->
+ match Prefetch.File.of_stdout ~env stdout with
+ | None -> Error (`Bad_output (method', stdout))
+ | Some {path; hash_value} ->
Ok (
- {input with hash = {input.hash with value = Some hash}},
+ {input with hash = {input.hash with value = Some hash_value}},
path
)
- | _ ->
- Error (`Bad_output (method', stdout))
end
| Error err -> Error err
@@ -326,14 +325,13 @@ let prefetch ~env ~proc_mgr ~name () : (unit, error) result =
| Ok stdout ->
begin
Logs.debug (fun m -> m "Command output: %s" stdout);
- match String.split_on_char '\n' (String.trim stdout) with
- | hash :: path :: _ when Option.is_some (Eio.Path.native (Eio.Path.(Eio.Stdenv.fs env / path))) ->
+ match Prefetch.Archive.of_stdout ~env stdout with
+ | None -> Error (`Bad_output (method', stdout))
+ | Some {path; hash_value} ->
Ok (
- {input with hash = {input.hash with value = Some hash}},
+ {input with hash = {input.hash with value = Some hash_value}},
path
)
- | _ ->
- Error (`Bad_output (method', stdout))
end
| Error err -> Error err
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;