File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 22% optional: mex
33
44function ok = is_symlink(p )
5+ arguments
6+ p {mustBeTextScalar }
7+ end
58
69try
710 ok = isSymbolicLink(p );
811catch e
912 switch e .identifier
10- case " MATLAB:UndefinedFunction" , ok = java .nio .file .Files .isSymbolicLink(javaPathObject(stdlib .absolute(p )));
13+ case " MATLAB:UndefinedFunction"
14+ if stdlib .has_dotnet()
15+ ok = is_symlink_dotnet(p );
16+ elseif stdlib .has_java()
17+ ok = java .nio .file .Files .isSymbolicLink(javaPathObject(stdlib .absolute(p )));
18+ else
19+ rethrow(e )
20+ end
1121 case " Octave:undefined-function"
1222 % use lstat() to work with a broken symlink, like Matlab isSymbolicLink
1323 [s , err ] = lstat(p );
1828
1929end
2030
31+
32+ function ok = is_symlink_dotnet(p )
33+
34+ try
35+ ok = ~isempty(System .IO .FileInfo(p ).LinkTarget);
36+ catch e
37+ if strcmp(e .identifier , " MATLAB:noSuchMethodOrField" )
38+ attr = string(System .IO .File .GetAttributes(p ).ToString());
39+ % https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributesN
40+ % ReparsePoint is for Linux, macOS, and Windows
41+ ok = contains(attr , ' ReparsePoint' );
42+ else
43+ rethrow(e )
44+ end
45+ end
46+
47+ end
48+
2149% !test
2250% ! if !ispc
2351% ! p = tempname();
You can’t perform that action at this time.
0 commit comments