Skip to content

Commit b56f744

Browse files
committed
is_exe: array
1 parent 5b32ef1 commit b56f744

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

+stdlib/+native/is_exe.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
y = isfile(file);
44

55
if ispc()
6-
y = y && stdlib.native.has_windows_executable_suffix(file);
6+
y = y & stdlib.native.has_windows_executable_suffix(file);
77
end
88

9-
if ~y, return, end
9+
if ~any(y)
10+
return
11+
end
1012

1113
if isunix
1214
props = ["UserExecute", "GroupExecute", "OtherExecute"];
1315
else
1416
props = "Readable";
1517
end
1618

17-
t = getPermissions(filePermissions(file), props);
19+
t = getPermissions(filePermissions(file(y)), props);
1820

19-
y = any(t{1, :});
21+
y(y) = any(t{:, :}, 2);
2022

2123
end

+stdlib/is_exe.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
function y = is_exe(file, backend)
66
arguments
7-
file {mustBeTextScalar}
7+
file string
88
backend (1,:) string = ["java", "python", "native", "legacy"]
99
end
1010

1111
% Java or Python ~ 100x faster than Matlab native
12-
fun = hbackend(backend, "is_exe", 'R2025a');
12+
[fun, b] = hbackend(backend, "is_exe", 'R2025a');
1313

14-
y = fun(file);
14+
if isscalar(file) || b == "native"
15+
y = fun(file);
16+
else
17+
y = arrayfun(fun, file);
18+
end
1519

1620
end

test/TestIsExe.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ function test_is_exe(tc, p, backend)
3232
end
3333

3434

35+
function test_is_exe_array(tc, backend)
36+
try
37+
n = fullfile(matlabroot, "bin/matlab");
38+
if ispc()
39+
n = n + ".exe";
40+
end
41+
r = stdlib.is_exe(["Readme.md", tempname(), n], backend);
42+
tc.verifyEqual(r, [false, false, true])
43+
catch e
44+
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
45+
end
46+
47+
end
48+
49+
3550
function test_is_executable_binary(tc, peb)
3651

3752
b = stdlib.is_executable_binary(peb{1});

test/TestWhich.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function test_which_name(tc)
3131
for n = names
3232
exe = stdlib.which(n);
3333
tc.verifyNotEmpty(exe, "Executable not found: " + n)
34-
tc.verifyTrue(isfile(exe), "Executable is not a file: " + n)
34+
tc.verifyThat(exe, matlab.unittest.constraints.IsFile, "Executable is not a file: " + n)
3535
tc.verifyTrue(stdlib.is_exe(exe), "Executable is not executable: " + n)
3636
end
3737

0 commit comments

Comments
 (0)