Skip to content

Commit 5e9de0b

Browse files
committed
is_{readable,writable}: array
1 parent 6178075 commit 5e9de0b

File tree

5 files changed

+40
-17
lines changed

5 files changed

+40
-17
lines changed

+stdlib/+native/is_readable.m

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

3-
y = false;
4-
5-
if ~stdlib.exists(file), return, end
3+
i = stdlib.exists(file);
4+
if ~any(i)
5+
y = i;
6+
return
7+
end
68

79
props = "Readable";
810
if isunix
911
props = [props, "GroupRead", "OtherRead"];
1012
end
1113

12-
t = getPermissions(filePermissions(file), props);
13-
y = any(t{1, :});
14+
t = getPermissions(filePermissions(file(i)), props);
15+
y(i) = t.(props).';
1416

1517
end

+stdlib/+native/is_writable.m

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

3-
y = false;
4-
5-
if ~stdlib.exists(p), return, end
3+
i = stdlib.exists(file);
4+
if ~any(i)
5+
y = i;
6+
return
7+
end
68

79
props = "Writable";
810
if isunix
911
props = [props, "GroupWrite", "OtherWrite"];
1012
end
1113

12-
t = getPermissions(filePermissions(p), props);
13-
y = any(t{1, :});
14+
t = getPermissions(filePermissions(file(i)), props);
15+
y(i) = t.(props).';
1416

1517
end

+stdlib/is_readable.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
function y = is_readable(file, backend)
99
arguments
10-
file {mustBeTextScalar}
10+
file string
1111
backend (1,:) string = ["java", "native", "legacy"]
1212
end
1313

14-
fun = hbackend(backend, "is_readable", 'R2025a');
14+
[fun, b] = hbackend(backend, "is_readable", 'R2025a');
1515

16-
y = fun(file);
16+
if isscalar(file) || b == "native"
17+
y = fun(file);
18+
else
19+
y = arrayfun(fun, file);
20+
end
1721

1822
end

+stdlib/is_writable.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
function y = is_writable(file, backend)
99
arguments
10-
file {mustBeTextScalar}
10+
file string
1111
backend (1,:) string = ["java", "native", "legacy"]
1212
end
1313

14-
fun = hbackend(backend, "is_writable", 'R2025a');
14+
[fun, b] = hbackend(backend, "is_writable", 'R2025a');
1515

16-
y = fun(file);
16+
if isscalar(file) || b == "native"
17+
y = fun(file);
18+
else
19+
y = arrayfun(fun, file);
20+
end
1721

1822
end

test/TestExists.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ function test_is_rw(tc, Ps, backend, fname)
4343
end
4444

4545

46+
function test_is_rw_array(tc, backend, fname)
47+
h = str2func("stdlib." + fname);
48+
try
49+
r = h([".", tempname(), mfilename() + ".m"], backend);
50+
tc.verifyEqual(r, [true, false, true])
51+
catch e
52+
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
53+
end
54+
end
55+
56+
4657
function test_is_char_device(tc, icm)
4758
% /dev/stdin may not be available on CI systems
4859
if ispc

0 commit comments

Comments
 (0)