From f67bf0e2bb0c8d136774ef138dbd8cce365bf9b3 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 18 Feb 2024 19:58:44 -0300 Subject: fix program search when using absolute paths and .exe extensions Fixes #1001. Thanks @badrazizi for the suggestion! --- src/luarocks/fs/unix.lua | 10 ++++++++++ src/luarocks/fs/win32.lua | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index f3db5b30..6bc183cb 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -227,6 +227,16 @@ function unix.system_cache_dir() end function unix.search_in_path(program) + if program:match("/") then + local fd = io.open(dir.path(program), "r") + if fd then + fd:close() + return true, program + end + + return false + end + for d in (os.getenv("PATH") or ""):gmatch("([^:]+)") do local fd = io.open(dir.path(d, program), "r") if fd then diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 1842ac4c..879f3e76 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -374,8 +374,22 @@ function win32.system_cache_dir() end function win32.search_in_path(program) + if program:match("\\") then + local fd = io.open(dir.path(program), "r") + if fd then + fd:close() + return true, program + end + + return false + end + + if not program:lower():match("exe$") then + program = program .. ".exe" + end + for d in (os.getenv("PATH") or ""):gmatch("([^;]+)") do - local fd = io.open(dir.path(d, program .. ".exe"), "r") + local fd = io.open(dir.path(d, program), "r") if fd then fd:close() return true, d -- cgit v1.2.3-55-g6feb