Skip to content

Commit f0f8af2

Browse files
committed
is_readable improve test coverage
1 parent 5360bda commit f0f8af2

File tree

5 files changed

+26
-30
lines changed

5 files changed

+26
-30
lines changed

+stdlib/+native/file_attributes.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
function a = file_attributes(p)
2-
arguments
3-
p {mustBeTextScalar}
4-
end
52

63
assert(~stdlib.strempty(p), 'Path must not be empty.')
74

+stdlib/+native/is_readable.m

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
function y = is_readable(p)
1+
function y = is_readable(file)
22

33
y = false;
44

5-
if ~stdlib.exists(p), return, end
6-
7-
if ~isMATLABReleaseOlderThan('R2025a')
8-
9-
props = "Readable";
10-
if isunix
11-
props = [props, "GroupRead", "OtherRead"];
12-
end
13-
14-
t = getPermissions(filePermissions(p), props);
15-
y = any(t{1, :});
16-
17-
else
18-
19-
a = stdlib.native.file_attributes(p);
20-
y = a.UserRead || a.GroupRead || a.OtherRead;
5+
if ~stdlib.exists(file), return, end
216

7+
props = "Readable";
8+
if isunix
9+
props = [props, "GroupRead", "OtherRead"];
2210
end
2311

12+
t = getPermissions(filePermissions(file), props);
13+
y = any(t{1, :});
14+
2415
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function y = is_readable_legacy(file)
2+
3+
if stdlib.exists(file)
4+
a = stdlib.native.file_attributes(file);
5+
y = a.UserRead || a.GroupRead || a.OtherRead;
6+
else
7+
y = false;
8+
end
9+
10+
end

+stdlib/is_readable.m

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
%% IS_READABLE is file readable
22
%
33
%%% Inputs
4-
% p: string array of file paths
4+
% file: single path string
55
%% Outputs
6-
% ok: logical array of the same size as p, true if file is readable
6+
% ok: true if file is readable
77

8-
function y = is_readable(p)
9-
arguments
10-
p {mustBeTextScalar}
11-
end
8+
function y = is_readable(file)
129

1310
if stdlib.has_java()
14-
y = stdlib.java.is_readable(p);
11+
y = stdlib.java.is_readable(file);
12+
elseif isMATLABReleaseOlderThan('R2025a')
13+
y = stdlib.native.is_readable_legacy(file);
1514
else
16-
y = stdlib.native.is_readable(p);
15+
y = stdlib.native.is_readable(file);
1716
end
1817

19-
2018
end

test/TestExists.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{tempname(), false}
99
}
1010
% on CI matlabroot can be writable!
11-
isr_fun = {@stdlib.is_readable, @stdlib.java.is_readable, @stdlib.native.is_readable}
11+
isr_fun = {@stdlib.is_readable, @stdlib.java.is_readable, @stdlib.native.is_readable, @stdlib.native.is_readable_legacy}
1212
isw_fun = {@stdlib.is_writable, @stdlib.java.is_writable, @stdlib.native.is_writable}
1313
end
1414

0 commit comments

Comments
 (0)