Skip to content

Commit

Permalink
repository: fix OPAMFETCH/OPAMCURL handling
Browse files Browse the repository at this point in the history
OPAMCURL is ignored if OPAMFETCH is set. This is changed to handle
OPAMCURL specification when OPAMFETCH is set to "curl" (simple command,
or new arguments). If OPAMFETCH is set to another tool, OPAMCURL is
ignored.
  • Loading branch information
rjbou committed Sep 12, 2023
1 parent 667b6ed commit 75a3a7a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ users)
* Allow to mark a set of warnings as errors using a new syntax -W @1..9 [#5652 @kit-ty-kate @rjbou - fixes #5651]

## Repository
* Fix `OPAMCURL` and `OPAMFETCH` handling [#5607 @rjbou - fix #5597]

## Lock

Expand Down
14 changes: 10 additions & 4 deletions src/repository/opamRepositoryConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,19 @@ let initk k =
(CString cmd, None), `Default
in
let c = cmd :: List.map (fun a -> OpamTypes.CString a, None) a in
Some (lazy (c, kind))
Some (c, kind)
| [] ->
None
)
>>+ fun () ->
E.curl () >>| (fun s ->
lazy ([CString s, None], `Curl))
|> (fun fetch ->
match E.curl (), fetch with
| None, fetch -> OpamStd.Option.map Lazy.from_val fetch
| Some cmd, Some (((CIdent "curl"| CString "curl"), filter)::args, _) ->
Some (lazy ((CString cmd, filter)::args, `Curl))
| Some cmd, None ->
Some (lazy ([CString cmd, None], `Curl))
| Some _, _ -> (* ignored *)
OpamStd.Option.map Lazy.from_val fetch)
in
let validation_hook =
E.validationhook () >>| fun s ->
Expand Down
21 changes: 13 additions & 8 deletions tests/reftests/download.test
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ The following actions will be performed:
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Processing 1/1: [foo.1: http]
+ curl "--another-args" "3"
[ERROR] Failed to get sources of foo.1: Curl failed
[ERROR] Failed to get sources of foo.1: curl error code ***The curl is a lie*** [args: --another-args 3]

OpamSolution.Fetch_fail("https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz (Curl failed: \"curl --another-args 3\" exited with code 2)")
OpamSolution.Fetch_fail("https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz (curl: code ***The curl is a lie*** [args: --another-args 3] while downloading https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz)")


<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Expand All @@ -100,17 +100,22 @@ OpamSolution.Fetch_fail("https://github.com/UnixJunkie/get_line/archive/v1.0.0.t
Clearing cache of downloaded files
### :I:e: FETCH curl & local curl
### OPAMFETCH=curl OPAMCURL=$BASEDIR/bin/curl
### opam install foo --download-only | grep -v "^+-" | sed-cmd curl | sed-cmd tar | "${OPAMVERSION}" -> "current"
### opam install foo --download-only | grep -v "^+-" | sed-cmd curl | "${OPAMVERSION}" -> "current"
The following actions will be performed:
=== install 1 package
- install foo 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Processing 1/1: [foo.1: http]
+ curl "--write-out" "%{http_code}\n" "--retry" "3" "--retry-delay" "2" "--user-agent" "opam/current" "-L" "-o" "${BASEDIR}/OPAM/download/.opam-switch/sources/foo.1/v1.0.0.tar.gz.part" "--" "https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz"
Processing 1/1:
+ tar "xfz" "${OPAMTMP}/v1.0.0.tar.gz" "-C" "${OPAMTMP}"
Done.
[ERROR] Failed to get sources of foo.1: curl error code ***The curl is a lie*** [args: --write-out %{http_code}\n --retry 3 --retry-delay 2 --user-agent opam/current -L -o ${BASEDIR}/OPAM/download/.opam-switch/sources/foo.1/v1.0.0.tar.gz.part -- https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz]

OpamSolution.Fetch_fail("https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz (curl: code ***The curl is a lie*** [args: --write-out %{http_code}\n --retry 3 --retry-delay 2 --user-agent opam/current -L -o ${BASEDIR}/OPAM/download/.opam-switch/sources/foo.1/v1.0.0.tar.gz.part -- https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz] while downloading https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz)")


<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
'${OPAM} install foo --download-only' failed.
# Return code 40 #
### opam clean -c
Clearing cache of downloaded files
### :I:f: FETCH curl with args & local curl
Expand All @@ -123,9 +128,9 @@ The following actions will be performed:
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Processing 1/1: [foo.1: http]
+ curl "--another-args" "3"
[ERROR] Failed to get sources of foo.1: Curl failed
[ERROR] Failed to get sources of foo.1: curl error code ***The curl is a lie*** [args: --another-args 3]

OpamSolution.Fetch_fail("https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz (Curl failed: \"curl --another-args 3\" exited with code 2)")
OpamSolution.Fetch_fail("https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz (curl: code ***The curl is a lie*** [args: --another-args 3] while downloading https://github.com/UnixJunkie/get_line/archive/v1.0.0.tar.gz)")


<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Expand Down

0 comments on commit 75a3a7a

Please sign in to comment.