Skip to content

Commit 320af4d

Browse files
committed
symlink .dotnet own subfunction
1 parent ea28d4f commit 320af4d

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

+stdlib/is_symlink.m

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@
1111
switch e.identifier
1212
case "MATLAB:UndefinedFunction"
1313
if stdlib.has_dotnet()
14-
if stdlib.dotnet_api() >= 6
15-
ok = ~isempty(System.IO.FileInfo(p).LinkTarget);
16-
else
17-
attr = string(System.IO.File.GetAttributes(p).ToString());
18-
% https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributes
19-
% ReparsePoint is for Linux, macOS, and Windows
20-
ok = contains(attr, 'ReparsePoint');
21-
end
14+
ok = is_symlink_dotnet(p);
2215
elseif stdlib.has_java()
2316
ok = java.nio.file.Files.isSymbolicLink(javaPathObject(stdlib.absolute(p)));
2417
elseif stdlib.has_python()
@@ -37,6 +30,28 @@
3730
end
3831

3932

33+
function y = is_symlink_dotnet(p)
34+
35+
try
36+
if stdlib.dotnet_api() >= 6
37+
y = ~isempty(System.IO.FileInfo(p).LinkTarget);
38+
else
39+
attr = string(System.IO.File.GetAttributes(p).ToString());
40+
% https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributes
41+
% ReparsePoint is for Linux, macOS, and Windows
42+
y = contains(attr, 'ReparsePoint');
43+
end
44+
catch e
45+
switch e.identifier
46+
case {'MATLAB:NET:CLRException:CreateObject', 'MATLAB:NET:CLRException:MethodInvoke'}
47+
y = false;
48+
otherwise, rethrow(e)
49+
end
50+
end
51+
52+
end
53+
54+
4055
%!test
4156
%! if !ispc
4257
%! p = tempname();

0 commit comments

Comments
 (0)