Skip to content

Commit b88548c

Browse files
committed
{get,set}_permissions: simpilfy, streamline
1 parent a27707f commit b88548c

File tree

11 files changed

+56
-65
lines changed

11 files changed

+56
-65
lines changed
File renamed without changes.

+stdlib/+legacy/get_permissions.m

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

+stdlib/+legacy/is_exe.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
if ~isfile(file), return, end
1313

14-
a = file_attributes(file);
14+
a = stdlib.legacy.file_attributes(file);
1515
y = a.UserExecute || a.GroupExecute || a.OtherExecute;
1616

1717
end

+stdlib/+legacy/is_readable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
end
55

66
if stdlib.exists(file)
7-
a = file_attributes(file);
7+
a = stdlib.legacy.file_attributes(file);
88
y = a.UserRead || a.GroupRead || a.OtherRead;
99
else
1010
y = false;

+stdlib/+legacy/is_writable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
end
55

66
if stdlib.exists(file)
7-
a = file_attributes(file);
7+
a = stdlib.legacy.file_attributes(file);
88
y = a.UserWrite || a.GroupWrite || a.OtherWrite;
99
else
1010
y = false;

+stdlib/+native/get_permissions.m

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

+stdlib/Backend.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@
102102
pyv = stdlib.python_version();
103103
if any(pyv(1:2) < [3, 12]), continue, end
104104
end
105-
case 'native'
106-
107-
switch functionName
108-
case {'get_permissions', 'set_permissions'}
109-
if stdlib.matlabOlderThan('R2025a'), continue, end
110-
end
111105
end
112106

113107
if ~isempty(which(sprintf('%s.%s.%s', self.namespace, m, functionName)))

+stdlib/get_permissions.m

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,30 @@
44
%
55
%%% inputs
66
% * file: path to check
7-
% * backend: backend to use
87
%%% Outputs
98
% * p: permissions string
109
% * b: backend used
1110

12-
function [perm, b] = get_permissions(file, backend)
11+
function [perm, b] = get_permissions(file)
1312
arguments
1413
file (1,1) string
15-
backend (1,:) string = ["native", "legacy"]
1614
end
1715

18-
o = stdlib.Backend(mfilename(), backend);
19-
perm = o.func(file);
20-
b = o.backend;
16+
perm = '';
17+
b = '';
18+
19+
if stdlib.exists(file)
20+
try
21+
perm = perm2char(filePermissions(file));
22+
b = 'native';
23+
catch e
24+
if e.identifier ~= "MATLAB:UndefinedFunction"
25+
rethrow(e)
26+
end
27+
28+
perm = perm2char(stdlib.legacy.file_attributes(file));
29+
b = 'legacy';
30+
end
31+
end
2132

2233
end
File renamed without changes.

+stdlib/set_permissions.m

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
% * readable (-1 remove read permission, 0 no change, 1 add read permission)
66
% * writable (-1 remove write permission, 0 no change, 1 add write permission)
77
% * executable (-1 remove execute permission, 0 no change, 1 add execute permission)
8-
% * backend: backend to use
98
%%% Outputs
109
% * ok (1,1) logical
1110
% * b: backend used
1211

13-
function [ok, b] = set_permissions(file, readable, writable, executable, backend)
12+
function [ok, b] = set_permissions(file, readable, writable, executable)
1413
arguments
1514
file (1,1) string
1615
readable (1,1) {mustBeInteger}
1716
writable (1,1) {mustBeInteger}
1817
executable (1,1) {mustBeInteger}
19-
backend (1,:) string = ["native", "legacy"]
2018
end
2119

22-
o = stdlib.Backend(mfilename(), backend);
20+
try
21+
ok = stdlib.native.set_permissions(file, readable, writable, executable);
22+
b = 'native';
23+
catch e
24+
if e.identifier ~= "MATLAB:UndefinedFunction"
25+
rethrow(e)
26+
end
2327

24-
ok = o.func(file, readable, writable, executable);
25-
b = o.backend;
28+
ok = stdlib.legacy.set_permissions(file, readable, writable, executable);
29+
b = 'legacy';
30+
end
2631

2732
end

0 commit comments

Comments
 (0)