Skip to content

Commit 96de66c

Browse files
committed
shell fallback is_symlink
1 parent 0dd2573 commit 96de66c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

+stdlib/+sys/is_symlink.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function ok = is_symlink(p)
2+
3+
if ispc()
4+
[s, m] = system(sprintf('pwsh -command "(Get-Item -Path %s).Attributes"', p));
5+
ok = s == 0 && contains(m, 'ReparsePoint');
6+
else
7+
[s, ~] = system(sprintf('test -L %s', p));
8+
ok = s == 0;
9+
end
10+
11+
end

+stdlib/is_symlink.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
try
99
ok = isSymbolicLink(p);
10+
return
1011
catch e
1112
switch e.identifier
1213
case "MATLAB:UndefinedFunction"
@@ -16,11 +17,6 @@
1617
ok = java.nio.file.Files.isSymbolicLink(javaPathObject(stdlib.absolute(p)));
1718
elseif stdlib.has_python()
1819
ok = stdlib.python.is_symlink(p);
19-
elseif isunix()
20-
ok = system(sprintf('test -L %s', p)) == 0;
21-
elseif ispc()
22-
[s, m] = system(sprintf('pwsh -command "(Get-Item -Path %s).Attributes"', p));
23-
ok = s == 0 && contains(m, 'ReparsePoint');
2420
end
2521
case "Octave:undefined-function"
2622
% use lstat() to work with a broken symlink, like Matlab isSymbolicLink
@@ -30,6 +26,10 @@
3026
end
3127
end
3228

29+
if ~ok
30+
ok = stdlib.sys.is_symlink(p);
31+
end
32+
3333
end
3434

3535

0 commit comments

Comments
 (0)