Skip to content

Commit b6c56e1

Browse files
committed
is_exe simplify
1 parent 8cd0c5e commit b6c56e1

File tree

5 files changed

+42
-70
lines changed

5 files changed

+42
-70
lines changed

+stdlib/+legacy/is_exe.m

Lines changed: 0 additions & 15 deletions
This file was deleted.

+stdlib/+native/is_exe.m

Lines changed: 0 additions & 29 deletions
This file was deleted.

+stdlib/is_exe.m

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
%%% Outputs
77
% ok: true if path is a file and has executable permissions
88
%
9-
% the legacy backend is like 40x faster than native.
9+
% this method is like 40x faster than native.
1010

11-
function [ok, b] = is_exe(file)
11+
function y = is_exe(file)
1212
arguments
13-
file string
13+
file (1,1) string
1414
end
1515

16-
if isscalar(file)
17-
ok = stdlib.legacy.is_exe(file);
18-
b = 'legacy';
19-
else
20-
ok = stdlib.native.is_exe(file);
21-
b = 'native';
16+
y = false;
17+
18+
if ispc() && ~stdlib.native.has_windows_executable_suffix(file)
19+
return
20+
end
21+
22+
a = stdlib.legacy.file_attributes(file);
23+
24+
if ~isempty(a)
25+
y = ~a.directory && (a.UserExecute || a.GroupExecute || a.OtherExecute);
2226
end
2327

2428
end

example/+native/is_exe.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function y = is_exe(file)
2+
arguments
3+
file string
4+
end
5+
6+
y = false;
7+
8+
if ispc() && ~stdlib.native.has_windows_executable_suffix(file)
9+
return
10+
end
11+
12+
if isunix
13+
props = ["UserExecute", "GroupExecute", "OtherExecute"];
14+
else
15+
props = "Readable";
16+
end
17+
18+
try
19+
y = getPermissions(filePermissions(file), props);
20+
catch e
21+
switch e.identifier
22+
case 'MATLAB:io:filesystem:filePermissions:CannotFindLocation'
23+
y = logical.empty;
24+
otherwise
25+
rethrow(e)
26+
end
27+
end
28+
29+
end

test/TestIsExe.m

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,13 @@ function test_is_exe(tc, p)
3131
end
3232

3333

34-
function test_is_exe_legacy(tc, p)
35-
r = stdlib.legacy.is_exe(p{1});
36-
tc.verifyEqual(r, p{2})
37-
end
38-
39-
4034
function test_is_executable_binary(tc, peb)
4135
b = stdlib.is_executable_binary(peb{1});
4236
tc.verifyEqual(b, peb{2}, peb{1})
4337
end
4438
end
4539

4640

47-
methods (Test, TestTags={'R2025a'})
48-
function test_is_exe_array(tc)
49-
tc.assumeFalse(isMATLABReleaseOlderThan('R2025a'))
50-
n = fullfile(matlabroot, "bin/matlab");
51-
if ispc()
52-
n = n + ".exe";
53-
end
54-
r = stdlib.is_exe(["Readme.md", tempname(), n]);
55-
tc.verifyEqual(r, [false, false, true])
56-
end
57-
end
5841

5942
end
6043

0 commit comments

Comments
 (0)