Skip to content

Commit e5c9f1e

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

File tree

13 files changed

+64
-79
lines changed

13 files changed

+64
-79
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/+legacy/set_permissions.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
executable (1,1) {mustBeInteger}
77
end
88

9-
ok = false;
10-
11-
if ~stdlib.exists(file), return, end
129

1310
mode = '';
1411
% mode is space-delimited
@@ -32,7 +29,7 @@
3229
mode = [mode ' -x'];
3330
end
3431

35-
if isempty(mode)
32+
if isempty(mode) && stdlib.exists(file)
3633
ok = true;
3734
return
3835
end

+stdlib/+native/get_permissions.m

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

+stdlib/+native/set_permissions.m

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,7 @@
66
executable (1,1) {mustBeInteger}
77
end
88

9-
ok = false;
10-
11-
if ~stdlib.exists(file), return, end
12-
13-
try
14-
p = filePermissions(file);
15-
catch
16-
ok = logical.empty;
17-
return
18-
end
9+
p = filePermissions(file);
1910

2011
k = string.empty;
2112
v = logical.empty;

+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

0 commit comments

Comments
 (0)