Skip to content

Commit 16e04e8

Browse files
committed
efficiency
1 parent 6f9cf36 commit 16e04e8

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

+stdlib/canonical.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121
return
2222
end
2323

24-
if stdlib.isoctave() || isMATLABReleaseOlderThan('R2024a')
25-
c = acanon(p);
26-
else
24+
try
2725
pth = matlab.io.internal.filesystem.resolvePath(p);
2826
c = pth.ResolvedPath;
2927
if strempty(c)
3028
c = stdlib.normalize(p);
3129
end
30+
catch e
31+
switch e.identifier
32+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}, c = acanon(p);
33+
otherwise, rethrow(e)
34+
end
3235
end
3336

3437
try %#ok<*TRYNC>

+stdlib/inode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if err == 0
1515
i = s.ino;
1616
end
17-
elseif isunix() && stdlib.has_java() && stdlib.java_api() >= 11
17+
elseif isunix() && stdlib.java_api() >= 11
1818
% Java 1.8 is buggy in some corner cases, so we require at least 11.
1919
i = java.nio.file.Files.getAttribute(javaPathObject(path), "unix:ino", javaLinkOption());
2020
end

+stdlib/is_exe.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
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+
otherwise, rethrow(e)
25+
end
2226
end
2327

2428
end

+stdlib/is_readable.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
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+
otherwise, rethrow(e)
18+
end
1519
end
1620

21+
end
1722
%!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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
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+
otherwise, rethrow(e)
18+
end
1519
end
1620

1721
end

0 commit comments

Comments
 (0)