extra-source #14
2 changed files with 23 additions and 11 deletions
|
@ -82,6 +82,25 @@ let extract_url_checksum filename items =
|
||||||
| Some url, Some cs -> Some (url, cs)
|
| Some url, Some cs -> Some (url, cs)
|
||||||
| _ -> None
|
| _ -> None
|
||||||
|
|
||||||
|
let extract_checksums_and_urls filename opam =
|
||||||
|
let open OpamParserTypes.FullPos in
|
||||||
|
List.fold_left (fun acc ->
|
||||||
|
function
|
||||||
|
| { pelem = Section ({ section_kind = { pelem = "url" ; _ } ; section_items = { pelem = items ; _ } ; _ }) ; _} ->
|
||||||
|
begin match extract_url_checksum filename items with
|
||||||
|
| None -> acc
|
||||||
|
| Some url -> url :: acc
|
||||||
|
end
|
||||||
|
| { pelem = Section ({ section_kind = { pelem = "extra-source" ; _ } ; section_name = Some { pelem ; _ } ; section_items = { pelem = items ; _ }; _ }) ; _} ->
|
||||||
|
begin
|
||||||
|
Log.debug (fun m -> m "extracting for extra-source %s in %s" filename pelem);
|
||||||
|
match extract_url_checksum filename items with
|
||||||
|
| None -> acc
|
||||||
|
| Some url -> url :: acc
|
||||||
|
end
|
||||||
|
| _ -> acc)
|
||||||
|
[] opam.file_contents
|
||||||
|
|
||||||
let extract_urls filename str =
|
let extract_urls filename str =
|
||||||
(* in an opam file, there may be:
|
(* in an opam file, there may be:
|
||||||
url { src: <string> checksum: [ STRING ] } <- list of hash
|
url { src: <string> checksum: [ STRING ] } <- list of hash
|
||||||
|
@ -102,13 +121,6 @@ let extract_urls filename str =
|
||||||
in
|
in
|
||||||
if unavailable then
|
if unavailable then
|
||||||
(Log.debug (fun m -> m "%s is marked unavailable, skipping" filename);
|
(Log.debug (fun m -> m "%s is marked unavailable, skipping" filename);
|
||||||
None)
|
[])
|
||||||
else
|
else
|
||||||
match
|
extract_checksums_and_urls filename opamfile
|
||||||
List.find_opt (function
|
|
||||||
| { pelem = Section ({ section_kind = { pelem = "url" ; _ } ; _ }) ; _} -> true | _ -> false)
|
|
||||||
opamfile.file_contents
|
|
||||||
with
|
|
||||||
| Some { pelem = Section ({ section_items = { pelem = items ; _ }; _}) ; _ } ->
|
|
||||||
extract_url_checksum filename items
|
|
||||||
| _ -> Log.debug (fun m -> m "no url section for %s" filename); None
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ module Make
|
||||||
(* TODO report parser errors *)
|
(* TODO report parser errors *)
|
||||||
(try
|
(try
|
||||||
let url_csums = Opam_file.extract_urls (Mirage_kv.Key.to_string path) data in
|
let url_csums = Opam_file.extract_urls (Mirage_kv.Key.to_string path) data in
|
||||||
Option.fold ~none:acc ~some:(fun (url, csums) ->
|
List.fold_left (fun acc (url, csums) ->
|
||||||
if HM.cardinal csums = 0 then
|
if HM.cardinal csums = 0 then
|
||||||
(Logs.warn (fun m -> m "no checksums for %s, ignoring" url); acc)
|
(Logs.warn (fun m -> m "no checksums for %s, ignoring" url); acc)
|
||||||
else
|
else
|
||||||
|
@ -146,7 +146,7 @@ module Make
|
||||||
Logs.warn (fun m -> m "mismatching hashes for %s: %s vs %s"
|
Logs.warn (fun m -> m "mismatching hashes for %s: %s vs %s"
|
||||||
url (hm_to_s csums') (hm_to_s csums));
|
url (hm_to_s csums') (hm_to_s csums));
|
||||||
None
|
None
|
||||||
end) acc) url_csums
|
end) acc) acc url_csums
|
||||||
with _ ->
|
with _ ->
|
||||||
Logs.warn (fun m -> m "some error in %a, ignoring" Mirage_kv.Key.pp path);
|
Logs.warn (fun m -> m "some error in %a, ignoring" Mirage_kv.Key.pp path);
|
||||||
acc)
|
acc)
|
||||||
|
|
Loading…
Reference in a new issue