|
6 | 6 | % * link: path to create link at |
7 | 7 | %%% Outputs |
8 | 8 | % * ok: true if successful |
9 | | -% |
10 | | -% Ref: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#createSymbolicLink(java.nio.file.Path,java.nio.file.Path,java.nio.file.attribute.FileAttribute...) |
11 | 9 |
|
12 | 10 | function ok = create_symlink(target, link) |
13 | 11 | arguments |
|
20 | 18 | createSymbolicLink(link, target); |
21 | 19 | ok = true; |
22 | 20 | catch e |
23 | | - if strcmp(e.identifier, "MATLAB:io:filesystem:symlink:NeedsAdminPerms") || ... |
24 | | - strcmp(e.identifier, 'MATLAB:UndefinedFunction') |
| 21 | + switch e.identifier |
| 22 | + case {"MATLAB:io:filesystem:symlink:NeedsAdminPerms", "MATLAB:UndefinedFunction"} |
25 | 23 | % windows requires RunAsAdmin |
26 | 24 | % https://www.mathworks.com/help/releases/R2024b/matlab/ref/createsymboliclink.html |
27 | 25 | % ok = java.nio.file.Files.createSymbolicLink(java.io.File(link).toPath(), java.io.File(target).toPath()); |
28 | 26 | % Matlab Java doesn't recognize the optional argument omitted. |
29 | 27 | % see example/Filesystem.java for this working in plain Java. |
30 | 28 | % see example/javaCreateSymbolicLink.m for a non-working attempt in Matlab. |
31 | | - |
32 | | - warning(e.identifier, "buildtool mex \n%s", e.message) |
33 | | - |
34 | | - ok = false; |
35 | | - elseif strcmp(e.identifier, "Octave:undefined-function") |
36 | | - [err, msg] = symlink(target, link); |
37 | | - ok = err == 0; |
38 | | - if ~ok |
39 | | - warning("create_symlink: %s", msg) |
40 | | - end |
41 | | - else |
42 | | - warning(e.identifier, "%s", e.message) |
43 | | - ok = false; |
| 29 | + warning(e.identifier, "buildtool mex \n%s", e.message) |
| 30 | + ok = false; |
| 31 | + case "Octave:undefined-function" |
| 32 | + err = symlink(target, link); |
| 33 | + ok = err == 0; |
| 34 | + otherwise |
| 35 | + warning(e.identifier, "%s", e.message) |
| 36 | + ok = false; |
44 | 37 | end |
45 | 38 | end |
46 | 39 |
|
|
0 commit comments