diff --git a/master_changes.md b/master_changes.md index 4d94b28225e..42ab9d90f6d 100644 --- a/master_changes.md +++ b/master_changes.md @@ -69,6 +69,7 @@ users) ## Repository * No longer call tar tool to create archives, use tar library instead [#6945 @kit-ty-kate] + * [BUG] Do not fail on directories named `opam` when scanning the `packages` directory of a repository during `opam repo add` or `opam init` (worked on subsequent `opam update`) [#6941 @kit-ty-kate @rjbou] ## Lock * [BUG] Fix `undefined variable` error when a lock file filter contains an undefined variables: fail gracefully with strict mode, continue and default the variable to false on normal mode [#6947 @rjbou - fix #6946] @@ -185,6 +186,7 @@ users) * Fix some forgotten sed in `extrasource` and `update` tests in #6734 [#6970 @rjbou] * Add a test for `opam config subst` [#6936 @NathanReb] * Add a lock test for undefined variables in a lock file [#6947 @rjbou - fix #6946] + * Add a test showing the behaviour of `opam repo add` and `opam update` when faced with a repository containing an `opam` directory [#6995 @kit-ty-kate] ### Engine * Add `http-server` to launch a minimal http server [#6939 @rjbou] diff --git a/src/state/opamRepositoryState.ml b/src/state/opamRepositoryState.ml index fcd813a4e63..80166a6555a 100644 --- a/src/state/opamRepositoryState.ml +++ b/src/state/opamRepositoryState.ml @@ -129,8 +129,11 @@ let load_opams_from_dir repo_name repo_root = (* FIXME: why is this different from OpamPackage.list ? *) let rec aux r dir = if OpamFilename.exists_dir dir then - let fnames = Sys.readdir (OpamFilename.Dir.to_string dir) in - if Array.exists (fun f -> String.equal f OpamPathName.opam_f) fnames then + let dir_str = OpamFilename.Dir.to_string dir in + let fnames = Sys.readdir dir_str in + let ( / ) = Filename.concat in + if Array.exists (fun f -> String.equal f OpamPathName.opam_f && + not (Sys.is_directory (dir_str / f))) fnames then match read_package_opam ~repo_name ~repo_root dir with | Some (nv, opam) -> OpamPackage.Map.add nv opam r | None -> r diff --git a/tests/reftests/repository.test b/tests/reftests/repository.test index 23a7c206499..2f38a4d0ea5 100644 --- a/tests/reftests/repository.test +++ b/tests/reftests/repository.test @@ -967,3 +967,45 @@ Now run 'opam upgrade' to apply any package updates. +++ test-git.new/packages/test/test.4/opam @@ -0,0 +1,1 @@ +opam-version: "2.0" +### :: Test the scan of directories named 'opam' +### opam switch create opam-dir --empty +### +opam-version: "2.0" +### +opam-version: "2.0" +build: ["echo" "init"] +### opam repo add --this-switch opam-dir OPAM-DIR +[opam-dir] Initialised +### opam install --verbose opam | sed-cmd echo +The following actions will be performed: +=== install 1 package + - install opam 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +Processing 2/3: [opam: echo init] ++ echo "init" (CWD=${BASEDIR}/OPAM/opam-dir/.opam-switch/build/opam.1) +- init +-> compiled opam.1 +-> installed opam.1 +Done. +### +opam-version: "2.0" +build: ["echo" "update"] +### opam update opam-dir + +<><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><> +[opam-dir] synchronised from file://${BASEDIR}/OPAM-DIR +Now run 'opam upgrade' to apply any package updates. +### opam reinstall --yes --verbose opam | sed-cmd echo +The following actions will be performed: +=== recompile 1 package + - recompile opam 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +Processing 2/4: [opam: echo update] ++ echo "update" (CWD=${BASEDIR}/OPAM/opam-dir/.opam-switch/build/opam.1) +- update +-> compiled opam.1 +-> removed opam.1 +-> installed opam.1 +Done.