Skip to content

Commit 64deb68

Browse files
committed
is_{read,writ}able: native only
Same rationale as is_exe native only
1 parent bf005d5 commit 64deb68

File tree

8 files changed

+38
-53
lines changed

8 files changed

+38
-53
lines changed

+stdlib/+java/is_readable.m

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

+stdlib/+java/is_writable.m

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

+stdlib/is_readable.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44
% file: single path string
55
%% Outputs
66
% ok: true if file is readable
7-
% b: backend used
87

9-
function [ok, b] = is_readable(file, backend)
8+
function ok = is_readable(file)
109
arguments
1110
file string
12-
backend (1,:) string = ["java", "native", "legacy"]
1311
end
1412

15-
[fun, b] = hbackend(backend, "is_readable");
16-
17-
if isscalar(file) || b == "native"
18-
ok = fun(file);
13+
if isscalar(file)
14+
ok = stdlib.legacy.is_readable(file);
1915
else
20-
ok = arrayfun(fun, file);
16+
ok = stdlib.native.is_readable(file);
2117
end
2218

2319
end

+stdlib/is_writable.m

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,18 @@
22
%
33
%%% Inputs
44
% * file: path to file or folder
5-
% * backend: backend to use
65
%% Outputs
76
% * ok: true if file is writable
8-
% * b: backend used
97

10-
function [ok, b] = is_writable(file, backend)
8+
function ok = is_writable(file)
119
arguments
1210
file string
13-
backend (1,:) string = ["java", "native", "legacy"]
1411
end
1512

16-
[fun, b] = hbackend(backend, "is_writable");
17-
18-
if isscalar(file) || b == "native"
19-
ok = fun(file);
13+
if isscalar(file)
14+
ok = stdlib.legacy.is_writable(file);
2015
else
21-
ok = arrayfun(fun, file);
16+
ok = stdlib.native.is_writable(file);
2217
end
2318

2419
end

+stdlib/private/hbackend.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
end
7070
case {'is_symlink', 'read_symlink'}
7171
if stdlib.matlabOlderThan('R2024b'), continue, end
72-
case {'get_permissions', 'set_permissions', 'is_readable', 'is_writable'}
72+
case {'get_permissions', 'set_permissions'}
7373
if stdlib.matlabOlderThan('R2025a'), continue, end
7474
end
7575

example/+javafun/is_readable.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#isReadable(java.nio.file.Path)
2-
% java.nio.file.Files is about 10x slower than fileattrib
3-
% file = stdlib.absolute(file, "", false);
4-
% ok = java.nio.file.Files.isReadable(javaPathObject(file));
51
function y = is_readable(p)
6-
y = javaFileObject(p).canRead();
2+
3+
y = java.io.File(p).canRead();
4+
75
end

example/+javafun/is_writable.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
%% JAVA.IS_WRITABLE is a filepath writable
2+
13
function y = is_writable(p)
24

35
% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/Files.html#isWritable(java.nio.file.Path)
4-
% java.nio.file.Files java is about 10x slower than fileattrib
5-
% needs absolute()
6+
% java.nio.file.Files java is about 10x slower than fileattrib and needs absolute()
67
% file = stdlib.absolute(file, "", false);
78
% ok = java.nio.file.Files.isWritable(javaPathObject(file));
89

9-
y = javaFileObject(p).canWrite();
10+
y = java.io.File(p).canWrite();
1011
end

test/TestExists.m

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
{"", false}
1212
}
1313
% on CI matlabroot can be writable!
14-
fname = {'is_readable', 'is_writable'}
15-
backend = init_backend({'java', 'native', 'legacy'}, 'native', ~isMATLABReleaseOlderThan('R2025a'))
16-
backend_ps = init_backend({'python', 'sys'})
14+
backend = init_backend({'python', 'sys'})
1715
end
1816

1917
methods(TestClassSetup)
@@ -32,29 +30,42 @@ function test_exists(tc, Ps)
3230
end
3331

3432

35-
function test_is_rw(tc, Ps, backend, fname)
36-
h = str2func("stdlib." + fname);
33+
function test_is_readable(tc, Ps)
34+
r = stdlib.is_readable(Ps{1});
35+
tc.verifyEqual(r, Ps{2})
36+
end
3737

38-
r = h(Ps{1}, backend);
38+
function test_is_writable(tc, Ps)
39+
r = stdlib.is_writable(Ps{1});
3940
tc.verifyEqual(r, Ps{2})
4041
end
4142

4243

43-
function test_is_rw_array(tc, backend, fname)
44-
h = str2func("stdlib." + fname);
44+
function test_is_readable_array(tc)
45+
tc.assumeFalse(stdlib.matlabOlderThan('R2025a'))
46+
in = [".", tempname(), mfilename('fullpath') + ".m"];
47+
out = [true, false, true];
48+
49+
r = stdlib.is_readable(in);
50+
tc.verifyEqual(r, out)
51+
end
52+
53+
54+
function test_is_writable_array(tc)
55+
tc.assumeFalse(stdlib.matlabOlderThan('R2025a'))
4556
in = [".", tempname(), mfilename('fullpath') + ".m"];
4657
out = [true, false, true];
4758

48-
r = h(in, backend);
59+
r = stdlib.is_writable(in);
4960
tc.verifyEqual(r, out)
5061
end
5162

5263

53-
function test_is_char_device(tc, backend_ps)
64+
function test_is_char_device(tc, backend)
5465
% /dev/stdin may not be available on CI systems
5566
n = stdlib.null_file();
5667

57-
tc.verifyTrue(stdlib.is_char_device(n, backend_ps), n)
68+
tc.verifyTrue(stdlib.is_char_device(n, backend), n)
5869
end
5970

6071
end

0 commit comments

Comments
 (0)