Skip to content

Commit dac2000

Browse files
committed
symlink: use new internal functions if available
1 parent ae86459 commit dac2000

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

+stdlib/+fileio/create_symlink.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
link (1,1) string
88
end
99

10+
if isMATLABReleaseOlderThan("R2024b")
1011
% import java.io.File
1112
% import java.nio.file.Files
1213
% ok = Files.createSymbolicLink(File(link).toPath(), File(target).toPath());
@@ -18,7 +19,8 @@
1819
end
1920

2021
if ispc
21-
cmd = "pwsh -c " + '"' + "New-Item -ItemType SymbolicLink -Path " + link + " -Target " + target + '"';
22+
cmd = "pwsh -c " + '"' + "New-Item -ItemType SymbolicLink -Path " + link + ...
23+
" -Target " + target + '"';
2224
else
2325
cmd = "ln -s " + target + " " + link;
2426
end
@@ -28,4 +30,15 @@
2830

2931
ok = stat == 0;
3032

33+
else
34+
35+
try
36+
createSymbolicLink(link, target);
37+
ok = true;
38+
catch
39+
ok = false;
40+
end
41+
42+
end
43+
3144
end

+stdlib/+fileio/is_symlink.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
p (1,1) string
77
end
88

9-
import java.io.File
10-
import java.nio.file.Files
11-
12-
% must be absolute path
13-
f = File(stdlib.fileio.absolute_path(p)).toPath();
14-
ok = Files.isSymbolicLink(f);
9+
if isMATLABReleaseOlderThan("R2024b")
10+
% must be absolute path
11+
ok = java.nio.file.Files.isSymbolicLink(java.io.File(stdlib.fileio.absolute_path(p)).toPath());
12+
else
13+
ok = isSymbolicLink(p);
14+
end
1515

1616
end

0 commit comments

Comments
 (0)