diff options
| author | ยท๐๐ด๐๐๐ฉ๐ค | 2025-12-31 14:21:34 +0000 |
|---|---|---|
| committer | ยท๐๐ด๐๐๐ฉ๐ค | 2025-12-31 14:21:34 +0000 |
| commit | f0fc310fe424d5657f416a7fd1c908cb4590e8e9 (patch) | |
| tree | b59c3e9122fc4bd32efe5520933a86e8a0742ede | |
| parent | e8504548c82c5b9bb4ee5a797c6e73db5db41357 (diff) | |
| download | nixtaml-f0fc310fe424d5657f416a7fd1c908cb4590e8e9.tar nixtaml-f0fc310fe424d5657f416a7fd1c908cb4590e8e9.tar.gz nixtaml-f0fc310fe424d5657f416a7fd1c908cb4590e8e9.tar.bz2 nixtaml-f0fc310fe424d5657f416a7fd1c908cb4590e8e9.tar.lz nixtaml-f0fc310fe424d5657f416a7fd1c908cb4590e8e9.tar.xz nixtaml-f0fc310fe424d5657f416a7fd1c908cb4590e8e9.tar.zst nixtaml-f0fc310fe424d5657f416a7fd1c908cb4590e8e9.zip | |
Prefetch: File+Archive stdout result into module
| -rw-r--r-- | lib/input_foreman.ml | 18 | ||||
| -rw-r--r-- | lib/prefetch.ml | 34 |
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; |
