Skip to content

Commit

Permalink
lint: add E72 for checking if the same checksum algorithm is used sev…
Browse files Browse the repository at this point in the history
…eral times for a given url in extra-sources section
  • Loading branch information
rjbou committed Aug 26, 2024
1 parent b199050 commit afe4c84
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
26 changes: 26 additions & 0 deletions src/state/opamFileTools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 @
Expand Down
16 changes: 12 additions & 4 deletions tests/reftests/extrasource.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
<default>/multiple-md5.1: Passed.
<default>/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
<default>/multiple-md5.1: Passed.
<default>/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
Expand Down Expand Up @@ -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
<default>/clash-with-all-md5s.666: Passed.
<default>/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
<default>/clash-with-all-md5s.666: Passed.
<default>/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
Expand Down
41 changes: 41 additions & 0 deletions tests/reftests/lint.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
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 #

0 comments on commit afe4c84

Please sign in to comment.