Skip to content

Commit fb7fcd0

Browse files
committed
is_readable improve test coverage
1 parent e4271c2 commit fb7fcd0

File tree

12 files changed

+89
-78
lines changed

12 files changed

+89
-78
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_exe.m

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
1-
function y = is_exe(p)
1+
function y = is_exe(file)
22

3-
y = isfile(p);
3+
y = isfile(file);
44

55
if ispc()
6-
y = y && stdlib.native.has_windows_executable_suffix(p);
6+
y = y && stdlib.native.has_windows_executable_suffix(file);
77
end
88

99
if ~y, return, end
1010

11-
12-
if ~isMATLABReleaseOlderThan('R2025a')
13-
14-
if isunix
15-
props = ["UserExecute", "GroupExecute", "OtherExecute"];
16-
else
17-
props = "Readable";
18-
end
19-
20-
t = getPermissions(filePermissions(p), props);
21-
22-
y = any(t{1, :});
23-
11+
if isunix
12+
props = ["UserExecute", "GroupExecute", "OtherExecute"];
2413
else
14+
props = "Readable";
15+
end
2516

26-
a = stdlib.native.file_attributes(p);
27-
y = a.UserExecute || a.GroupExecute || a.OtherExecute;
17+
t = getPermissions(filePermissions(file), props);
2818

29-
end
19+
y = any(t{1, :});
3020

3121
end

+stdlib/+native/is_exe_legacy.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function y = is_exe_legacy(file)
2+
3+
y = isfile(file);
4+
5+
if ispc()
6+
y = y && stdlib.native.has_windows_executable_suffix(file);
7+
end
8+
9+
if ~y, return, end
10+
11+
a = stdlib.native.file_attributes(file);
12+
y = a.UserExecute || a.GroupExecute || a.OtherExecute;
13+
14+
end

+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/+native/is_writable.m

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44

55
if ~stdlib.exists(p), return, end
66

7-
if ~isMATLABReleaseOlderThan('R2025a')
8-
9-
props = "Writable";
10-
if isunix
11-
props = [props, "GroupWrite", "OtherWrite"];
12-
end
7+
props = "Writable";
8+
if isunix
9+
props = [props, "GroupWrite", "OtherWrite"];
10+
end
1311

14-
t = getPermissions(filePermissions(p), props);
15-
y = any(t{1, :});
12+
t = getPermissions(filePermissions(p), props);
13+
y = any(t{1, :});
1614

17-
else
18-
a = stdlib.native.file_attributes(p);
19-
y = a.UserWrite || a.GroupWrite || a.OtherWrite;
2015
end
21-
22-
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function y = is_writable_legacy(file)
2+
3+
if stdlib.exists(file)
4+
a = stdlib.native.file_attributes(file);
5+
y = a.UserWrite || a.GroupWrite || a.OtherWrite;
6+
else
7+
y = false;
8+
end
9+
10+
end

+stdlib/is_readable.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
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)
8+
function y = is_readable(file)
99
arguments
10-
p {mustBeTextScalar}
10+
file {mustBeTextScalar}
1111
end
1212

1313
if stdlib.has_java()
14-
y = stdlib.java.is_readable(p);
14+
y = stdlib.java.is_readable(file);
15+
elseif isMATLABReleaseOlderThan('R2025a')
16+
y = stdlib.native.is_readable_legacy(file);
1517
else
16-
y = stdlib.native.is_readable(p);
18+
y = stdlib.native.is_readable(file);
1719
end
1820

19-
2021
end

+stdlib/is_writable.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
%% IS_WRITABLE is path writable
22
%
33
%%% Inputs
4-
% p: string array of file paths
4+
% file: path to file or folder
55
%% Outputs
6-
% ok: logical array of the same size as p, true if file is writable
6+
% ok: true if file is writable
77

8-
function y = is_writable(p)
8+
function y = is_writable(file)
99
arguments
10-
p {mustBeTextScalar}
10+
file {mustBeTextScalar}
1111
end
1212

1313
if stdlib.has_java()
14-
y = stdlib.java.is_writable(p);
14+
y = stdlib.java.is_writable(file);
15+
elseif isMATLABReleaseOlderThan('R2025a')
16+
y = stdlib.native.is_writable_legacy(file);
1517
else
16-
y = stdlib.native.is_writable(p);
18+
y = stdlib.native.is_writable(file);
1719
end
1820

1921
end

+stdlib/proximate_to.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
%% PROXIMATE_TO relative path to base
22
%
33
%%% Inputs
4-
% * base {mustBeTextScalar}
5-
% * other {mustBeTextScalar}
4+
% * base: directory to which the other path should be relative
5+
% * other: path to be made relative
66
%%% Outputs
7-
% * rel {mustBeTextScalar}
7+
% * rel: relative path from base to other
88

99
function rel = proximate_to(base, other)
10-
arguments
11-
base {mustBeTextScalar}
12-
other {mustBeTextScalar}
13-
end
1410

1511
rel = stdlib.relative_to(base, other);
1612
if stdlib.strempty(rel)

0 commit comments

Comments
 (0)