Skip to content

Commit b9aab1c

Browse files
committed
read_symlink: prefer native
1 parent 3fbfa4f commit b9aab1c

File tree

5 files changed

+14
-27
lines changed

5 files changed

+14
-27
lines changed

+stdlib/+native/read_symlink.m

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

+stdlib/Backend.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@
111111
if stdlib.matlabOlderThan('R2024b') || ispc()
112112
continue
113113
end
114-
case {'is_symlink', 'read_symlink'}
115-
if stdlib.matlabOlderThan('R2024b'), continue, end
116114
case {'get_permissions', 'set_permissions'}
117115
if stdlib.matlabOlderThan('R2025a'), continue, end
118116
end

+stdlib/read_symlink.m

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,22 @@
1616
backend (1,:) string = ["native", "java", "dotnet", "python", "sys"]
1717
end
1818

19-
o = stdlib.Backend(mfilename(), backend);
2019

21-
if isscalar(file)
22-
r = o.func(file);
23-
else
24-
r = arrayfun(o.func, file);
20+
if ismember('native', backend) || stdlib.strempty(backend)
21+
try
22+
[ok, r] = isSymbolicLink(file);
23+
r(~ok) = "";
24+
b = "native";
25+
return
26+
catch e
27+
if e.identifier ~= "MATLAB:UndefinedFunction"
28+
rethrow(e)
29+
end
30+
end
2531
end
2632

33+
o = stdlib.Backend(mfilename(), backend);
2734
b = o.backend;
28-
35+
r = o.func(file);
2936

3037
end

example/BenchmarkSymlink.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
methods (TestParameterDefinition, Static)
1616
function [is_backend, rs_backend] = setupBackend()
1717
is_backend = cellstr(["native", init_backend('is_symlink')]);
18-
rs_backend = init_backend('read_symlink');
18+
rs_backend = cellstr(["native", init_backend('read_symlink')]);
1919
end
2020
end
2121

test/TestSymlink.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ function test_read_symlink(tc, B_read_symlink)
6464
end
6565

6666

67-
function test_read_symlink_array(tc, B_read_symlink)
68-
r = stdlib.read_symlink([tc.link, mfilename() + ".m"], B_read_symlink);
69-
exp = [tc.target, ""];
70-
tc.verifyClass(r, 'string')
71-
tc.verifyEqual(r, exp, "failed to detect own link")
72-
end
73-
74-
7567
function test_create_symlink(tc, B_create_symlink)
7668
tc.applyFixture(matlab.unittest.fixtures.SuppressedWarningsFixture(["MATLAB:io:filesystem:symlink:TargetNotFound","MATLAB:io:filesystem:symlink:FileExists"]))
7769

0 commit comments

Comments
 (0)