Skip to content

Commit 4140810

Browse files
committed
efficiency
1 parent 6f9cf36 commit 4140810

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

+stdlib/is_exe.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@
88
end
99
% need to have string array type for p(:)
1010

11-
if ~stdlib.isoctave() && ~isMATLABReleaseOlderThan('R2025a')
11+
try
1212
if isunix
1313
props = ["UserExecute", "GroupExecute", "OtherExecute"];
1414
else
1515
props = "Readable";
1616
end
1717
t = getPermissions(filePermissions(p), props);
1818
ok = isfile(p(:)) & any(t{:,:}, 2);
19-
else
20-
a = file_attributes_legacy(p);
21-
ok = isfile(p) && (a.UserExecute || a.GroupExecute || a.OtherExecute);
19+
catch e
20+
switch e.identifier
21+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
22+
a = file_attributes_legacy(p);
23+
ok = isfile(p) && (a.UserExecute || a.GroupExecute || a.OtherExecute);
24+
end
2225
end
2326

2427
end

+stdlib/is_readable.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
function ok = is_readable(p)
44

5-
if ~stdlib.isoctave() && ~isMATLABReleaseOlderThan('R2025a')
5+
try
66
props = "Readable";
77
if isunix
88
props = [props, "GroupRead", "OtherRead"];
99
end
1010
t = getPermissions(filePermissions(p), props);
1111
ok = any(t{:,:}, 2);
12-
else
13-
a = file_attributes_legacy(p);
14-
ok = a.UserRead || a.GroupRead || a.OtherRead;
12+
catch e
13+
switch e.identifier
14+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
15+
a = file_attributes_legacy(p);
16+
ok = a.UserRead || a.GroupRead || a.OtherRead;
17+
end
1518
end
1619

20+
end
1721
%!assert (is_readable('is_readable.m'))

+stdlib/is_symlink.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
% optional: mex
33

44
function ok = is_symlink(p)
5-
arguments
6-
p {mustBeTextScalar}
7-
end
8-
95

106
try
117
ok = isSymbolicLink(p);

+stdlib/is_url.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
% e.g. https://example.invalid is true
33

44
function y = is_url(s)
5-
arguments
6-
s {mustBeTextScalar}
7-
end
85

96
y = startsWith(s, alphanumericsPattern + "://");
107

+stdlib/is_writable.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
function ok = is_writable(p)
44

5-
if ~stdlib.isoctave() && ~isMATLABReleaseOlderThan('R2025a')
5+
try
66
props = "Writable";
77
if isunix
88
props = [props, "GroupWrite", "OtherWrite"];
99
end
1010
t = getPermissions(filePermissions(p), props);
1111
ok = any(t{:,:}, 2);
12-
else
13-
a = file_attributes_legacy(p);
14-
ok = a.UserWrite || a.GroupWrite || a.OtherWrite;
12+
catch e
13+
switch e.identifier
14+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
15+
a = file_attributes_legacy(p);
16+
ok = a.UserWrite || a.GroupWrite || a.OtherWrite;
17+
end
1518
end
1619

1720
end

0 commit comments

Comments
 (0)