aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2024-02-18 19:58:44 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-02-19 00:00:49 -0300
commitf67bf0e2bb0c8d136774ef138dbd8cce365bf9b3 (patch)
treec816113fa5eb6f113069dd22ffb6d6a8888379e9
parent0ebba5ec21ed524235d95b37e0c5dfff4fd36e81 (diff)
downloadluarocks-f67bf0e2bb0c8d136774ef138dbd8cce365bf9b3.tar.gz
luarocks-f67bf0e2bb0c8d136774ef138dbd8cce365bf9b3.tar.bz2
luarocks-f67bf0e2bb0c8d136774ef138dbd8cce365bf9b3.zip
fix program search when using absolute paths and .exe extensions
Fixes #1001. Thanks @badrazizi for the suggestion!
-rw-r--r--src/luarocks/fs/unix.lua10
-rw-r--r--src/luarocks/fs/win32.lua16
2 files changed, 25 insertions, 1 deletions
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()
227end 227end
228 228
229function unix.search_in_path(program) 229function unix.search_in_path(program)
230 if program:match("/") then
231 local fd = io.open(dir.path(program), "r")
232 if fd then
233 fd:close()
234 return true, program
235 end
236
237 return false
238 end
239
230 for d in (os.getenv("PATH") or ""):gmatch("([^:]+)") do 240 for d in (os.getenv("PATH") or ""):gmatch("([^:]+)") do
231 local fd = io.open(dir.path(d, program), "r") 241 local fd = io.open(dir.path(d, program), "r")
232 if fd then 242 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()
374end 374end
375 375
376function win32.search_in_path(program) 376function win32.search_in_path(program)
377 if program:match("\\") then
378 local fd = io.open(dir.path(program), "r")
379 if fd then
380 fd:close()
381 return true, program
382 end
383
384 return false
385 end
386
387 if not program:lower():match("exe$") then
388 program = program .. ".exe"
389 end
390
377 for d in (os.getenv("PATH") or ""):gmatch("([^;]+)") do 391 for d in (os.getenv("PATH") or ""):gmatch("([^;]+)") do
378 local fd = io.open(dir.path(d, program .. ".exe"), "r") 392 local fd = io.open(dir.path(d, program), "r")
379 if fd then 393 if fd then
380 fd:close() 394 fd:close()
381 return true, d 395 return true, d