diff --git a/master_changes.md b/master_changes.md index 853d59650f6..21bc114fe8b 100644 --- a/master_changes.md +++ b/master_changes.md @@ -71,6 +71,7 @@ users) ## Lint * Add E70 to check `extra-files:` duplicated fields [#5561 @rjbou] * Add E71 to check if the same checksum algorithm is used several times for a given url in `url` section [#5561 @rjbou] + * Add E72 to check if the same checksum algorithm is used several times for a given url in `extra-sources` section [#5561 @rjbou] ## Repository * Mitigate curl/curl#13845 by falling back from --write-out to --fail if exit code 43 is returned by curl [#6168 @dra27 - fix #6120] @@ -183,6 +184,7 @@ users) * lint: update W37 to test other urls scheme [#5561 @rjbou] * lint: add E70 test [#5561 @rjbou] * lint: add E71 test [#5561 @rjbou] + * lint: add E72 test [#5561 @rjbou] ### Engine * Add a test filtering mechanism [#6105 @Keryan-dev] diff --git a/src/state/opamFileTools.ml b/src/state/opamFileTools.ml index b50145904cc..a860e147952 100644 --- a/src/state/opamFileTools.ml +++ b/src/state/opamFileTools.ml @@ -1052,6 +1052,32 @@ let t_lint ?check_extra_files ?(check_upstream=false) ?(all=false) t = cond 71 `Error "Field 'url.checksum' contains duplicated checksums" ?detail has_double); + (let has_double, detail = + OpamFile.OPAM.extra_sources t + |> List.rev_map (fun (basename, url) -> + basename, + OpamFile.URL.checksum url + |> List.rev_map OpamHash.kind + |> check_double + OpamHash.compare_kind + OpamHash.string_of_kind) + |> List.fold_left (fun (has_double, details) (basename, (double, detail)) -> + let has_double = has_double || double in + let details = + match detail with + | None -> details + | Some detail -> + Printf.sprintf "%s have %s" + (OpamFilename.Base.to_string basename) + (OpamStd.Format.pretty_list detail) + :: details + in + has_double, details) (false, []) + |> (function hd, [] -> hd, None | hd, d -> hd, Some d) + in + cond 72 `Error + "Field 'extra-sources' contains duplicated checksums" + ?detail has_double); ] in format_errors @ diff --git a/tests/reftests/extrasource.test b/tests/reftests/extrasource.test index fa65a343d65..c5445355894 100644 --- a/tests/reftests/extrasource.test +++ b/tests/reftests/extrasource.test @@ -549,9 +549,13 @@ Successfully extracted to ${BASEDIR}/no-checksum.1 Clearing cache of downloaded files ### :I:6: multiple md5 ### opam lint --package multiple-md5 -/multiple-md5.1: Passed. +/multiple-md5.1: Errors. + error 72: Field 'extra-sources' contains duplicated checksums: "i-am-a-patch have md5: 2 occurences" +# Return code 1 # ### opam lint --package multiple-md5 --check-upstream -/multiple-md5.1: Passed. +/multiple-md5.1: Errors. + error 72: Field 'extra-sources' contains duplicated checksums: "i-am-a-patch have md5: 2 occurences" +# Return code 1 # ### opam install multiple-md5 | '[0-9a-z]{32}' -> 'hash' The following actions will be performed: === install 1 package @@ -839,9 +843,13 @@ OpamSolution.Fetch_fail("Checksum mismatch") Clearing cache of downloaded files ### :I:10: clash with all md5 ### opam lint --package clash-with-all-md5s -/clash-with-all-md5s.666: Passed. +/clash-with-all-md5s.666: Errors. + error 72: Field 'extra-sources' contains duplicated checksums: "i-am-a-patch have md5: 17 occurences" +# Return code 1 # ### opam lint --package clash-with-all-md5s --check-upstream -/clash-with-all-md5s.666: Passed. +/clash-with-all-md5s.666: Errors. + error 72: Field 'extra-sources' contains duplicated checksums: "i-am-a-patch have md5: 17 occurences" +# Return code 1 # ### opam install clash-with-all-md5s | '[0-9a-z]{32}' -> 'hash' The following actions will be performed: === install 1 package diff --git a/tests/reftests/lint.test b/tests/reftests/lint.test index 7e3c6b70e9d..54fa33e1851 100644 --- a/tests/reftests/lint.test +++ b/tests/reftests/lint.test @@ -1116,3 +1116,44 @@ url { ${BASEDIR}/lint.opam: Errors. error 71: Field 'url.checksum' contains duplicated checksums: "md5: 2 occurences", "sha256: 3 occurences" # Return code 1 # +### : E72: Field 'extra-sources' contains duplicated checksums +### +opam-version: "2.0" +synopsis: "A word" +description: "Two words." +authors: "the testing team" +homepage: "egapemoh" +maintainer: "maint@tain.er" +license: "ISC" +dev-repo: "hg+https://to@li.nt" +bug-reports: "https://nobug" +extra-source "double-file" { + src:"https://git.url/repo.tgz" + checksum:[ + "md5=00000000000000000000000000000000" + "md5=11111111111111111111111111111111" + "sha256=2222222222222222222222222222222222222222222222222222222222222222" + "sha256=3333333333333333333333333333333333333333333333333333333333333333" + "sha256=4444444444444444444444444444444444444444444444444444444444444444" + "sha512=55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" + ] +} +extra-source "double-file2" { + src:"https://git.url/repo.tgz" + checksum:[ + "md5=00000000000000000000000000000000" + "md5=11111111111111111111111111111111" + ] +} +extra-source "double-file3" { + src:"https://git.url/repo.tgz" + checksum:[ + "md5=00000000000000000000000000000000" + "sha256=3333333333333333333333333333333333333333333333333333333333333333" + "sha512=55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" + ] +} +### opam lint ./lint.opam +${BASEDIR}/lint.opam: Errors. + error 72: Field 'extra-sources' contains duplicated checksums: "double-file have md5: 2 occurences and sha256: 3 occurences", "double-file2 have md5: 2 occurences" +# Return code 1 #