File tree Expand file tree Collapse file tree 4 files changed +38
-24
lines changed Expand file tree Collapse file tree 4 files changed +38
-24
lines changed Original file line number Diff line number Diff line change 1+ function y = is_readable(p )
2+
3+ y = javaObject(" java.io.File" , p ).canRead();
4+
5+ end
Original file line number Diff line number Diff line change 1+ function y = is_readable(p )
2+
3+ y = false ;
4+
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 = t .Readable ;
16+
17+ else
18+
19+ a = file_attributes_legacy(p );
20+ y = a .UserRead || a .GroupRead || a .OtherRead ;
21+
22+ end
23+
24+ end
Original file line number Diff line number Diff line change 55%% Outputs
66% ok: logical array of the same size as p, true if file is readable
77
8- function ok = is_readable(p )
8+ function y = is_readable(p )
99arguments
10- p string
10+ p { mustBeTextScalar }
1111end
1212
13- ok(size(p )) = false ;
14-
15- i = stdlib .exists(p );
16-
17- if ~any(i ), return , end
18-
19- if ~isMATLABReleaseOlderThan(' R2025a' )
20-
21- props = " Readable" ;
22- if isunix
23- props = [props , " GroupRead" , " OtherRead" ];
24- end
25-
26- t = getPermissions(filePermissions(p(i )), props );
27- ok(i ) = any(t{: ,: }, 2 );
28-
13+ if stdlib .has_java()
14+ y = stdlib .java .is_readable(p );
2915else
30-
31- a = file_attributes_legacy(p );
32- ok = a .UserRead || a .GroupRead || a .OtherRead ;
33-
16+ y = stdlib .native .is_readable(p );
3417end
3518
19+
3620end
Original file line number Diff line number Diff line change 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}
1112end
1213
1314methods (TestClassSetup )
@@ -25,8 +26,8 @@ function test_exists(tc, Ps)
2526end
2627
2728
28- function test_is_readable(tc , Ps )
29- ok = stdlib .is_readable (Ps{1 });
29+ function test_is_readable(tc , Ps , isr_fun )
30+ ok = isr_fun (Ps{1 });
3031tc .verifyEqual(ok , Ps{2 }, Ps{1 })
3132end
3233
You can’t perform that action at this time.
0 commit comments