diff options
author | Erlang/OTP <[email protected]> | 2010-06-03 08:53:26 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2010-06-03 08:53:26 +0000 |
commit | 2d0fe96a13e51f61fbe9cc66b71ab42a690d3542 (patch) | |
tree | 5eb3d2278cf96531447b1cef5f6c9ab97ff79197 /lib/kernel/src | |
parent | 195b98cabf710fd99a58386c36072afc9b4b235f (diff) | |
parent | 5f1628d70b210424a8d83f89c707815059c6710b (diff) | |
download | otp-2d0fe96a13e51f61fbe9cc66b71ab42a690d3542.tar.gz otp-2d0fe96a13e51f61fbe9cc66b71ab42a690d3542.tar.bz2 otp-2d0fe96a13e51f61fbe9cc66b71ab42a690d3542.zip |
Merge branch 'pan/otp_3626_win_find_executable' into dev
* pan/otp_3626_win_find_executable:
Teach os.erl to find executable names with extension (i.e. .exe) on windows
OTP-3626 os:find_executable bug on Windows
os:find_executable can now be fed with the complete name of the executable
on Windows and still find it. I.e os:find_executable("werl.exe") will work
as os:find_executable("werl").
Diffstat (limited to 'lib/kernel/src')
-rw-r--r-- | lib/kernel/src/os.erl | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/kernel/src/os.erl b/lib/kernel/src/os.erl index d0b498edc9..75a11a8afd 100644 --- a/lib/kernel/src/os.erl +++ b/lib/kernel/src/os.erl @@ -50,7 +50,7 @@ find_executable(Name, Path) -> relative -> find_executable1(Name, split_path(Path), Extensions); _ -> - case verify_executable(Name, Extensions) of + case verify_executable(Name, Extensions, Extensions) of {ok, Complete} -> Complete; error -> @@ -60,7 +60,7 @@ find_executable(Name, Path) -> find_executable1(Name, [Base|Rest], Extensions) -> Complete0 = filename:join(Base, Name), - case verify_executable(Complete0, Extensions) of + case verify_executable(Complete0, Extensions, Extensions) of {ok, Complete} -> Complete; error -> @@ -69,7 +69,7 @@ find_executable1(Name, [Base|Rest], Extensions) -> find_executable1(_Name, [], _Extensions) -> false. -verify_executable(Name0, [Ext|Rest]) -> +verify_executable(Name0, [Ext|Rest], OrigExtensions) -> Name1 = Name0 ++ Ext, case os:type() of vxworks -> @@ -78,7 +78,7 @@ verify_executable(Name0, [Ext|Rest]) -> {ok, _} -> {ok, Name1}; _ -> - verify_executable(Name0, Rest) + verify_executable(Name0, Rest, OrigExtensions) end; _ -> case file:read_file_info(Name1) of @@ -87,12 +87,30 @@ verify_executable(Name0, [Ext|Rest]) -> %% on Unix, since we test if any execution bit is set. {ok, Name1}; _ -> - verify_executable(Name0, Rest) + verify_executable(Name0, Rest, OrigExtensions) end end; -verify_executable(_, []) -> +verify_executable(Name, [], OrigExtensions) when OrigExtensions =/= [""] -> %% Windows + %% Will only happen on windows, hence case insensitivity + case can_be_full_name(string:to_lower(Name),OrigExtensions) of + true -> + verify_executable(Name,[""],[""]); + _ -> + error + end; +verify_executable(_, [], _) -> error. +can_be_full_name(_Name,[]) -> + false; +can_be_full_name(Name,[H|T]) -> + case lists:suffix(H,Name) of %% Name is in lowercase, cause this is a windows thing + true -> + true; + _ -> + can_be_full_name(Name,T) + end. + split_path(Path) -> case type() of {win32, _} -> @@ -119,6 +137,7 @@ reverse_element(List) -> lists:reverse(List). -spec extensions() -> [string()]. +%% Extensions in lower case extensions() -> case type() of {win32, _} -> [".exe",".com",".cmd",".bat"]; |