Skip to content

Commit 54bf68a

Browse files
committed
use R2025a setPermissions
1 parent c6e7c33 commit 54bf68a

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

+stdlib/set_permissions.m

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%% SET_PERMISSIONS set path permissions
2-
% requires: mex
2+
% optional: mex
33
%
44
%%% Inputs
55
% * path (1,1) string
@@ -8,12 +8,37 @@
88
% * executable (1,1) int (-1 remove execute permission, 0 no change, 1 add execute permission)
99
%%% Outputs
1010
% * ok (1,1) logical
11-
%
12-
% This function is written in C++ using STL <filesystem>
13-
%
14-
% TODO: R2025a final release add setPermissions
15-
% https://www.mathworks.com/help/releases/R2025a/matlab/ref/matlab.io.filesystementrypermissions.setpermissions.html
1611

17-
function set_permissions(~, ~, ~, ~)
18-
error("buildtool mex")
12+
function ok = set_permissions(path, readable, writable, executable)
13+
arguments
14+
path (1,1) string {mustBeFile}
15+
readable (1,1) int8
16+
writable (1,1) int8
17+
executable (1,1) int8
18+
end
19+
20+
ok = false;
21+
22+
try
23+
p = filePermissions(path);
24+
catch e
25+
switch e.identifier
26+
case "MATLAB:UndefinedFunction", error("buildtool mex")
27+
case "MATLAB:io:filesystem:filePermissions:CannotFindLocation", return
28+
otherwise, rethrow(e)
29+
end
30+
end
31+
32+
ok = true;
33+
34+
if readable ~= 0
35+
ok = ok && setPermissions(p, "Readable", readable > 0);
36+
end
37+
if writable ~= 0
38+
ok = ok && setPermissions(p, "Writable", writable > 0);
39+
end
40+
if executable ~= 0
41+
ok = ok && setPermissions(p, "Executable", executable > 0);
42+
end
43+
1944
end

0 commit comments

Comments
 (0)