Skip to content

Commit d39aba1

Browse files
committed
create_symlink: faster native
1 parent b9aab1c commit d39aba1

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

+stdlib/+native/create_symlink.m

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

+stdlib/Backend.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@
105105
case 'native'
106106

107107
switch functionName
108-
case 'create_symlink'
109-
% Some Windows R2025a give error 'MATLAB:io:filesystem:symlink:NeedsAdminPerms'
110-
% 25.1.0.2973910 (R2025a) Update 1 gave this error for example.
111-
if stdlib.matlabOlderThan('R2024b') || ispc()
112-
continue
113-
end
114108
case {'get_permissions', 'set_permissions'}
115109
if stdlib.matlabOlderThan('R2025a'), continue, end
116110
end

+stdlib/create_symlink.m

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
%%% Outputs
77
% * ok: true if successful
88
% * b: backend used
9+
%
10+
% Some Windows Matlab R2025a give error 'MATLAB:io:filesystem:symlink:NeedsAdminPerms'
11+
% For example, Matlab 25.1.0.2973910 R2025a Update 1 gave this error.
912

1013
function [ok, b] = create_symlink(target, link, backend)
1114
arguments
@@ -14,8 +17,28 @@
1417
backend (1,:) string = ["native", "dotnet", "python", "sys"]
1518
end
1619

20+
21+
if ismember('native', backend) || stdlib.strempty(backend)
22+
try
23+
createSymbolicLink(link, target);
24+
ok = true;
25+
b = "native";
26+
return
27+
catch e
28+
switch e.identifier
29+
case {'MATLAB:UndefinedFunction', 'MATLAB:io:filesystem:symlink:NeedsAdminPerms'}
30+
% pass through to stdlib.Backend
31+
case {'MATLAB:io:filesystem:symlink:FileExists', 'MATLAB:io:filesystem:symlink:TargetNotFound'}
32+
ok = false;
33+
return
34+
otherwise
35+
rethrow(e)
36+
end
37+
end
38+
end
39+
1740
o = stdlib.Backend(mfilename(), backend);
41+
b = o.backend;
1842
ok = o.func(target, link);
1943

20-
b = o.backend;
2144
end

test/TestSymlink.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
methods (TestParameterDefinition, Static)
2222
function [B_create_symlink, B_read_symlink, B_is_symlink] = setupBackends()
23-
B_create_symlink = init_backend("create_symlink");
24-
B_read_symlink = init_backend("read_symlink");
25-
B_is_symlink = init_backend("is_symlink");
23+
B_create_symlink = cellstr(["native", init_backend("create_symlink")]);
24+
B_read_symlink = cellstr(["native", init_backend("read_symlink")]);
25+
B_is_symlink = cellstr(["native", init_backend("is_symlink")]);
2626
end
2727
end
2828

0 commit comments

Comments
 (0)