Skip to content

Commit

Permalink
source: add no & require checksums flags to harmonise with opam install
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Dec 4, 2024
1 parent eee0e46 commit 5e48fdf
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 3 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ users)
## Exec

## Source
* [NEW] Add options `--require-checksums` and `--no-checksums` to harmonise with `opam install` [#5563 @rjbou]

## Lint

Expand Down
19 changes: 16 additions & 3 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3703,8 +3703,19 @@ let source cli =
"Choose package without consideration for \
the current (or any other) switch (installed or pinned packages, etc.)"
in
let source global_options atom dev_repo pin no_switch dir () =
let no_checksums = no_checksums cli (cli_from cli2_4) in
let req_checksums = require_checksums cli (cli_from cli2_4) in
let source global_options atom dev_repo pin no_switch dir
no_checksums req_checksums () =
apply_global_options cli global_options;
let force_checksums =
if req_checksums then Some (Some true)
else if no_checksums then Some (Some false)
else None
in
OpamStd.Option.iter (fun force_checksums ->
OpamRepositoryConfig.update ~force_checksums ())
force_checksums;
OpamGlobalState.with_ `Lock_none @@ fun gt ->
let get_package_dir t =
let nv =
Expand Down Expand Up @@ -3829,9 +3840,11 @@ let source cli =
OpamSwitchState.drop
(OpamClient.PIN.pin t nv.name ~version:nv.version target)
in
mk_command ~cli cli_original "source" ~doc ~man
mk_command ~cli cli_original "source" ~doc ~man
Term.(const source
$global_options cli $atom $dev_repo $pin $no_switch $dir)
$global_options cli
$atom $dev_repo $pin $no_switch $dir
$no_checksums $req_checksums)

(* LINT *)
let lint_doc = "Checks and validate package description ('opam') files."
Expand Down
62 changes: 62 additions & 0 deletions tests/reftests/archive.test
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ Done.
### opam source good-md5
Successfully extracted to ${BASEDIR}/good-md5.1
### test -f good-md5.1/hello
### rm -r good-md5.1
### opam source good-md5 --require-checksums
Successfully extracted to ${BASEDIR}/good-md5.1
### test -f good-md5.1/hello
### opam clean --download-cache
Clearing cache of downloaded files
### :I:2: good sha256
Expand Down Expand Up @@ -321,6 +325,10 @@ Done.
### opam source good-sha256
Successfully extracted to ${BASEDIR}/good-sha256.1
### test -f good-sha256.1/hello
### rm -r good-sha256.1
### opam source good-sha256 --require-checksums
Successfully extracted to ${BASEDIR}/good-sha256.1
### test -f good-sha256.1/hello
### opam clean --download-cache
Clearing cache of downloaded files
### :I:3: good md5 & sha256
Expand Down Expand Up @@ -375,6 +383,10 @@ Done.
### opam source good-md5-good-sha256
Successfully extracted to ${BASEDIR}/good-md5-good-sha256.1
### test -f good-md5-good-sha256.1/hello
### rm -r good-md5-good-sha256.1
### opam source good-md5-good-sha256 --require-checksums
Successfully extracted to ${BASEDIR}/good-md5-good-sha256.1
### test -f good-md5-good-sha256.1/hello
### opam clean --download-cache
Clearing cache of downloaded files
### :I:4: good sha256 & good md5
Expand Down Expand Up @@ -426,6 +438,10 @@ Done.
### opam source good-sha256-good-md5
Successfully extracted to ${BASEDIR}/good-sha256-good-md5.1
### test -f good-sha256-good-md5.1/hello
### rm -r good-sha256-good-md5.1
### opam source good-sha256-good-md5 --require-checksums
Successfully extracted to ${BASEDIR}/good-sha256-good-md5.1
### test -f good-sha256-good-md5.1/hello
### opam clean --download-cache
Clearing cache of downloaded files
### :I:5: no checksum
Expand Down Expand Up @@ -472,6 +488,12 @@ OpamSolution.Fetch_fail("no-checksum.1: Missing checksum, and `--require-checksu
### opam source no-checksum
Successfully extracted to ${BASEDIR}/no-checksum.1
### test -f no-checksum.1/hello
### rm -r no-checksum.1
### opam source no-checksum --require-checksums
[ERROR] Download failed: no-checksum.1: Missing checksum, and `--require-checksums` was set.
# Return code 40 #
### test -f no-checksum.1/hello
# Return code 1 #
### opam clean --download-cache
Clearing cache of downloaded files
### :I:6: multiple md5
Expand Down Expand Up @@ -534,6 +556,14 @@ OpamSolution.Fetch_fail("Checksum mismatch")
# Return code 40 #
### test -f multiple-md5.1/hello
# Return code 1 #
### opam source multiple-md5 --require-checksums | '[0-9a-z]{32}' -> 'hash'
[ERROR] multiple-md5.1: Checksum mismatch for file://${BASEDIR}/archive.tgz:
expected md5=hash
got md5=hash
[ERROR] Download failed: Checksum mismatch
# Return code 40 #
### test -f multiple-md5.1/hello
# Return code 1 #
### opam clean --download-cache
Clearing cache of downloaded files
### :I:7: bad md5
Expand Down Expand Up @@ -593,6 +623,14 @@ OpamSolution.Fetch_fail("Checksum mismatch")
# Return code 40 #
### test -f bad-md5.1/hello
# Return code 1 #
### opam source bad-md5 --require-checksums | '[0-9a-z]{32}' -> 'hash'
[ERROR] bad-md5.1: Checksum mismatch for file://${BASEDIR}/archive.tgz:
expected md5=hash
got md5=hash
[ERROR] Download failed: Checksum mismatch
# Return code 40 #
### test -f bad-md5.1/hello
# Return code 1 #
### opam clean --download-cache
Clearing cache of downloaded files
### :I:8: good md5 & bad sha256
Expand Down Expand Up @@ -722,6 +760,14 @@ OpamSolution.Fetch_fail("Checksum mismatch")
# Return code 40 #
### test -f good-md5-bad-sha256.1/hello
# Return code 1 #
### opam source good-md5-bad-sha256 --require-checksums | '[0-9a-z]{64}' -> 'md5'
[ERROR] good-md5-bad-sha256.1: Checksum mismatch for file://${BASEDIR}/archive.tgz:
expected sha256=md5
got sha256=md5
[ERROR] Download failed: Checksum mismatch
# Return code 40 #
### test -f good-md5-bad-sha256.1/hello
# Return code 1 #
### opam clean --download-cache
Clearing cache of downloaded files
### :I:9: good sha256 & bad md5
Expand Down Expand Up @@ -781,6 +827,14 @@ OpamSolution.Fetch_fail("Checksum mismatch")
# Return code 40 #
### test -f good-sha256-bad-md5.1/hello
# Return code 1 #
### opam source good-sha256-bad-md5 --require-checksums | '[0-9a-z]{32}' -> 'hash'
[ERROR] good-sha256-bad-md5.1: Checksum mismatch for file://${BASEDIR}/archive.tgz:
expected md5=hash
got md5=hash
[ERROR] Download failed: Checksum mismatch
# Return code 40 #
### test -f good-sha256-bad-md5.1/hello
# Return code 1 #
### opam clean --download-cache
Clearing cache of downloaded files
### :I:10: clash with all md5
Expand Down Expand Up @@ -928,6 +982,14 @@ OpamSolution.Fetch_fail("Checksum mismatch")
# Return code 40 #
### test -f clash-with-all-md5s.666/hello
# Return code 1 #
### opam source clash-with-all-md5s --require-checksums | '[0-9a-z]{32}' -> 'hash'
[ERROR] clash-with-all-md5s.666: Checksum mismatch for file://${BASEDIR}/archive.tgz:
expected md5=hash
got md5=hash
[ERROR] Download failed: Checksum mismatch
# Return code 40 #
### test -f clash-with-all-md5s.666/hello
# Return code 1 #
### opam clean --download-cache
Clearing cache of downloaded files
### :::::::::::::::::
Expand Down
29 changes: 29 additions & 0 deletions tests/reftests/extrafile.test
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ Done.
### opam source good-md5
Successfully extracted to ${BASEDIR}/good-md5.1
### test -f good-md5.1/p.patch
### rm -r good-md5.1
### opam source good-md5 --require-checksums
Successfully extracted to ${BASEDIR}/good-md5.1
### test -f good-md5.1/p.patch
### opam clean --download-cache
Clearing cache of downloaded files
### :I:2: good md5 & sha256
Expand Down Expand Up @@ -234,6 +238,10 @@ Done.
### opam source good-md5-good-sha256
Successfully extracted to ${BASEDIR}/good-md5-good-sha256.1
### test -f good-md5-good-sha256.1/p.patch
### rm -r good-md5-good-sha256.1
### opam source good-md5-good-sha256 --require-checksums
Successfully extracted to ${BASEDIR}/good-md5-good-sha256.1
### test -f good-md5-good-sha256.1/p.patch
### opam clean --download-cache
Clearing cache of downloaded files
### :I:3: bad md5
Expand Down Expand Up @@ -282,6 +290,12 @@ Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p
### opam source bad-md5 | '.n"' -> '"'
[WARNING] Some errors extracting to ${BASEDIR}/bad-md5.1: Failure("Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p.patch")

### test -f bad-md5.1/p.patch
# Return code 1 #
### rm -r bad-md5.1
### opam source bad-md5 --require-checksums | '.n"' -> '"'
[WARNING] Some errors extracting to ${BASEDIR}/bad-md5.1: Failure("Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/bad-md5/bad-md5.1/files/p.patch")

### test -f bad-md5.1/p.patch
# Return code 1 #
### opam clean --download-cache
Expand Down Expand Up @@ -332,6 +346,11 @@ Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-
### opam source good-md5-bad-sha256 | '.n"' -> '"'
[WARNING] Some errors extracting to ${BASEDIR}/good-md5-bad-sha256.1: Failure("Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-md5-bad-sha256.1/files/p.patch")

### test -f good-md5-bad-sha256.1/p.patch
### rm -r good-md5-bad-sha256.1
### opam source good-md5-bad-sha256 --require-checksums | '.n"' -> '"'
[WARNING] Some errors extracting to ${BASEDIR}/good-md5-bad-sha256.1: Failure("Bad hash for - ${BASEDIR}/OPAM/repo/default/packages/good-md5-bad-sha256/good-md5-bad-sha256.1/files/p.patch")

### test -f good-md5-bad-sha256.1/p.patch
### opam clean --download-cache
Clearing cache of downloaded files
Expand Down Expand Up @@ -395,6 +414,11 @@ The following actions will be performed:
Successfully extracted to ${BASEDIR}/no-checksum.1
### test -f no-checksum.1/p.patch
# Return code 1 #
### rm -r no-checksum.1
### opam source no-checksum --require-checksums
Successfully extracted to ${BASEDIR}/no-checksum.1
### test -f no-checksum.1/p.patch
# Return code 1 #
### opam clean --download-cache
Clearing cache of downloaded files
### :::::::::::::::::
Expand Down Expand Up @@ -447,6 +471,11 @@ The following actions will be performed:
Successfully extracted to ${BASEDIR}/not-mentioned.1
### test -f not-mentioned.1/p.patch
# Return code 1 #
### rm -r not-mentioned.1
### opam source not-mentioned --require-checksums
Successfully extracted to ${BASEDIR}/not-mentioned.1
### test -f not-mentioned.1/p.patch
# Return code 1 #
### opam clean --download-cache
Clearing cache of downloaded files
### :II:2: not present
Expand Down
Loading

0 comments on commit 5e48fdf

Please sign in to comment.