Skip to content

Commit

Permalink
Look for META files rather than just directories to list plugins
Browse files Browse the repository at this point in the history
If the plugin directory contains anything but directories that each
contain a `META` file, loading plugins fails

This can happen naturally in particular in the following scenario:
- install a package providing a plugin to a command in another package
- and remove that plugin package.
This leaves an empty directory which triggers that failure.

Co-authored-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
Signed-off-by: Samuel Hym <samuel.hym@rustyne.lautre.net>
  • Loading branch information
shym and anmonteiro committed Apr 26, 2024
1 parent 6ec2787 commit 7607948
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
23 changes: 16 additions & 7 deletions otherlibs/dune-site/src/plugins/plugins.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
open Dune_site.Private_
module Data = Dune_site_plugins_data

let readdir dirs =
List.concat
(List.map
(fun dir -> Array.to_list (Sys.readdir dir))
(List.filter Sys.file_exists dirs))
let meta_fn = "META"

let readdir =
let ( / ) = Filename.concat in
let readdir_noexn dir =
try Sys.readdir dir with
| Sys_error _ -> [||]
in
fun dirs ->
List.concat
(List.map
(fun dir ->
List.filter
(fun entry -> Sys.file_exists (dir / entry / meta_fn))
(Array.to_list (readdir_noexn dir)))
dirs)
;;

let rec lookup dirs file =
Expand Down Expand Up @@ -208,8 +219,6 @@ let load file ~pkg =
{ Meta_parser.name = Some pkg; entries }
;;

let meta_fn = "META"

let lookup_and_load_one_dir ~dir ~pkg =
let meta_file = Filename.concat dir meta_fn in
if Sys.file_exists meta_file
Expand Down
3 changes: 1 addition & 2 deletions otherlibs/dune-site/test/opam-uninstall.t
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,5 @@ issue by recreating this empty directory.
$ mkdir -p _install/lib/app/plugins/plugin1

$ OCAMLPATH=_install/lib:$OCAMLPATH _install/bin/app
Fatal error: exception The plugin "plugin1" can't be found in the search paths "$TESTCASE_ROOT/_install/lib/app/plugins".
[2]
Main app starts...

0 comments on commit 7607948

Please sign in to comment.