Skip to content

Commit

Permalink
Improve error message when src directory for repo add doesn't exist
Browse files Browse the repository at this point in the history
Closes #5632

Co-authored-by: Raja Boujbel <raja.boujbel@ocamlpro.com>
  • Loading branch information
punchagan and rjbou committed Aug 21, 2024
1 parent 0c4ace3 commit f02cdd4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ users)
## Lint

## Repository
* Improve error message when `opam repo add` fails because local src directory doesn't exist [#5689 @punchagan - fix #5632]

## Lock

Expand Down
15 changes: 11 additions & 4 deletions src/repository/opamLocal.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ let rsync_dirs ?args ?exclude_vcdirs url dst =
if not (is_remote url) &&
not (OpamFilename.exists_dir (OpamFilename.Dir.of_string src_s))
then
Done (Not_available (None, Printf.sprintf "Directory %s does not exist" src_s))
let msg = Printf.sprintf "directory %s doesn't exist" src_s in
Done (Not_available (Some msg, msg))
else
rsync ?args ?exclude_vcdirs src_s dst_s @@| function
| Not_available _ as na -> na
Expand All @@ -118,7 +119,8 @@ let rsync_file ?(args=[]) url dst =
let dst_s = OpamFilename.to_string dst in
log "rsync_file src=%s dst=%s" src_s dst_s;
if not (is_remote url || OpamFilename.(exists (of_string src_s))) then
Done (Not_available (None, src_s))
let msg = Printf.sprintf "file %s doesn't exist" dst_s in
Done (Not_available (Some msg, msg))
else if src_s = dst_s then
Done (Up_to_date dst)
else
Expand Down Expand Up @@ -168,9 +170,14 @@ module B = struct
else
OpamFilename.mkdir quarantine;
pull_dir_quiet quarantine url) @@+ function
| Not_available _ ->
| Not_available (reason, _) ->
finalise ();
Done (OpamRepositoryBackend.Update_err (Failure "rsync failed"))
let err =
match reason with
| None -> "rsync failed"
| Some err -> err
in
Done (OpamRepositoryBackend.Update_err (Failure err))
| Up_to_date _ ->
finalise (); Done OpamRepositoryBackend.Update_empty
| Result _ ->
Expand Down
2 changes: 1 addition & 1 deletion tests/reftests/lint.test
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ url { src:"another-archive.tgz" }
### opam lint ./lint.opam --check-upstream
${BASEDIR}/lint.opam: Errors.
warning 59: url doesn't contain a checksum
error 60: Upstream check failed: "Source not found: ${BASEDIR}/another-archive.tgz"
error 60: Upstream check failed: "Source not found: file ${OPAMTMP}/lint-check-upstream doesn't exist"
# Return code 1 #
### <lint.opam>
opam-version: "2.0"
Expand Down
16 changes: 8 additions & 8 deletions tests/reftests/repository.test
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ first --
### <OPER/packages/fantom/fantom.0/opam>
opam-version: "2.0"
### opam repository set-url oper ./OPER4
[ERROR] Could not update repository "oper": rsync failed
[ERROR] Could not update repository "oper": directory ${BASEDIR}/OPER4/ doesn't exist
[ERROR] Fetching repository oper with file://${BASEDIR}/OPER4 fails, reverting to file://${BASEDIR}/OPER
# Return code 40 #
### opam list --available --repo=oper
Expand Down Expand Up @@ -329,7 +329,7 @@ first --
# Name # Installed # Synopsis
first --
### opam repository set-url oper ./OPER4
[ERROR] Could not update repository "oper": rsync failed
[ERROR] Could not update repository "oper": directory ${BASEDIR}/OPER4/ doesn't exist
[ERROR] Fetching repository oper with file://${BASEDIR}/OPER4 fails, reverting to git+file://${BASEDIR}/OPER
# Return code 40 #
### opam list --available --repo=oper
Expand Down Expand Up @@ -369,15 +369,15 @@ first --
[oper] Initialised
### :: Simply failing urls ::
### opam repository --this-switch add oper4 ./OPER4
[ERROR] Could not update repository "oper4": rsync failed
[ERROR] Could not update repository "oper4": directory ${BASEDIR}/OPER4/ doesn't exist
[ERROR] Initial repository fetch failed
# Return code 40 #
### opam repository --this-switch

<><> Repository configuration for switch repos ><><><><><><><><><><><><><><><><>
1 oper file://${BASEDIR}/OPER
### opam repository --this-switch set-url oper ./OPER4
[ERROR] Could not update repository "oper": rsync failed
[ERROR] Could not update repository "oper": directory ${BASEDIR}/OPER4/ doesn't exist
[ERROR] Fetching repository oper with file://${BASEDIR}/OPER4 fails, reverting to file://${BASEDIR}/OPER
# Return code 40 #
### opam repository --this-switch
Expand Down Expand Up @@ -456,7 +456,7 @@ first --
### <OPER/packages/fantom/fantom.0/opam>
opam-version: "2.0"
### opam repository set-url oper ./OPER4
[ERROR] Could not update repository "oper": rsync failed
[ERROR] Could not update repository "oper": directory ${BASEDIR}/OPER4/ doesn't exist
[ERROR] Fetching repository oper with file://${BASEDIR}/OPER4 fails, reverting to file://${BASEDIR}/OPER
# Return code 40 #
### opam list --available --repo=oper
Expand Down Expand Up @@ -495,7 +495,7 @@ first --
# Name # Installed # Synopsis
first --
### opam repository set-url oper ./OPER4
[ERROR] Could not update repository "oper": rsync failed
[ERROR] Could not update repository "oper": directory ${BASEDIR}/OPER4/ doesn't exist
[ERROR] Fetching repository oper with file://${BASEDIR}/OPER4 fails, reverting to git+file://${BASEDIR}/OPER
# Return code 40 #
### opam list --available --repo=oper
Expand Down Expand Up @@ -535,15 +535,15 @@ first --
[oper] Initialised
### ::: Simply failing urls :::
### opam repository --this-switch add oper4 ./OPER4
[ERROR] Could not update repository "oper4": rsync failed
[ERROR] Could not update repository "oper4": directory ${BASEDIR}/OPER4/ doesn't exist
[ERROR] Initial repository fetch failed
# Return code 40 #
### opam repository --this-switch

<><> Repository configuration for switch repos ><><><><><><><><><><><><><><><><>
1 oper file://${BASEDIR}/OPER
### opam repository --this-switch set-url oper ./OPER4
[ERROR] Could not update repository "oper": rsync failed
[ERROR] Could not update repository "oper": directory ${BASEDIR}/OPER4/ doesn't exist
[ERROR] Fetching repository oper with file://${BASEDIR}/OPER4 fails, reverting to file://${BASEDIR}/OPER
# Return code 40 #
### opam repository --this-switch
Expand Down

0 comments on commit f02cdd4

Please # to comment.