Skip to content

Commit

Permalink
Skip directories when looking up programs in the PATH
Browse files Browse the repository at this point in the history
Fixes #1616

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
  • Loading branch information
jeremiedimino committed Dec 10, 2018
1 parent 7e9c4cc commit 59ef63a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ unreleased
- unstable-fmt: use boxes to wrap some lists (#1608, fix #1153, @emillon,
thanks to @rgrinberg)

- skip directories when looking up programs in the PATH (#1628, fixes
#1616, @diml)

1.6.2 (05/12/2018)
------------------

Expand Down
10 changes: 8 additions & 2 deletions src/stdune/bin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ let cons_path p ~_PATH =

let exe = if Sys.win32 then ".exe" else ""

let exists fn =
match Unix.stat (Path.to_string fn) with
| { st_kind = S_DIR; _ } -> false
| exception (Unix.Unix_error _) -> false
| _ -> true

let best_prog dir prog =
let fn = Path.relative dir (prog ^ ".opt" ^ exe) in
if Path.exists fn then
if exists fn then
Some fn
else
let fn = Path.relative dir (prog ^ exe) in
if Path.exists fn then
if exists fn then
Some fn
else
None
Expand Down
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/github1616/run.t
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Regression test for #1616

$ env PATH="$PWD/bin2:$PWD/bin1:$PATH" dune build --root root
Entering directory 'root'
prog alias default
Hello, World!

0 comments on commit 59ef63a

Please sign in to comment.