File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 p {mustBeTextScalar }
88end
99
10- r = " " ;
1110
1211try
13- [ok , t ] = isSymbolicLink(p );
14- if ~ok , return , end
12+ [~ , r ] = isSymbolicLink(p );
1513catch e
1614 switch e .identifier
17- case " Octave:undefined-function" , t = readlink(p );
15+ case " Octave:undefined-function" , r = readlink(p );
1816 case " MATLAB:UndefinedFunction"
19- if ~stdlib .is_symlink(p )
20- return
17+ if stdlib .is_symlink(p )
18+ % must be absolute path
19+ % must not be .canonical or symlink is gobbled!
20+ r = stdlib .absolute(p , " " , false );
21+
22+ % https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#readSymbolicLink(java.nio.file.Path)
23+ r = java .nio.file.Files.readSymbolicLink(javaPathObject(r )).string;
24+ else
25+ r = string(missing );
2126 end
22-
23- % must be absolute path
24- % must not be .canonical or symlink is gobbled!
25- r = stdlib .absolute(p , " " , false );
26-
27- % https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#readSymbolicLink(java.nio.file.Path)
28- t = java .nio.file.Files.readSymbolicLink(javaPathObject(r ));
2927 otherwise , rethrow(e )
3028 end
3129end
3230
33- r = stdlib .posix(t );
34-
3531end
3632
3733% !test
Original file line number Diff line number Diff line change @@ -17,9 +17,9 @@ function setup_symlink(tc)
1717
1818tc.tempDir = tc .createTemporaryFolder();
1919
20- tc.link = tc .tempDir + " / my.lnk" ;
20+ tc.link = fullfile( tc .tempDir, " my.lnk" ) ;
2121
22- tc.target = stdlib .posix( mfilename(" fullpath" ) + " .m" ) ;
22+ tc.target = mfilename(" fullpath" ) + " .m" ;
2323
2424tc .assumeTrue(stdlib .create_symlink(tc .target, tc .link), ...
2525 " failed to create test link " + tc .link)
@@ -36,10 +36,11 @@ function test_is_symlink(tc, p)
3636
3737
3838function test_read_symlink(tc )
39+ import matlab .unittest .constraints .HasMissing
3940
40- tc .verifyEqual (stdlib .read_symlink(" " ), " " )
41- tc .verifyEqual (stdlib .read_symlink(" not-exist" ), " " )
42- tc .verifyEqual (stdlib .read_symlink(tc .target), " " )
41+ tc .verifyThat (stdlib .read_symlink(" " ), HasMissing )
42+ tc .verifyThat (stdlib .read_symlink(" not-exist" ), HasMissing )
43+ tc .verifyThat (stdlib .read_symlink(tc .target), HasMissing )
4344
4445t = stdlib .read_symlink(tc .link);
4546tc .verifyNotEmpty(t )
You can’t perform that action at this time.
0 commit comments