Skip to content

Commit 81ec7cc

Browse files
committed
read_symlink: always string class
1 parent fcaa3cd commit 81ec7cc

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

+stdlib/read_symlink.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
%% READ_SYMLINK read symbolic link
22
%
33
% empty string if path is not a symlink
4+
% always of string class in Matlab
45

56
function r = read_symlink(p)
67
arguments
@@ -10,7 +11,7 @@
1011

1112
try
1213
[ok, r] = isSymbolicLink(p);
13-
if ~ok, r = ''; end
14+
if ~ok, r = string.empty; end
1415
catch e
1516
switch e.identifier
1617
case "Octave:undefined-function", r = readlink(p);
@@ -23,16 +24,12 @@
2324
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#readSymbolicLink(java.nio.file.Path)
2425
r = java.nio.file.Files.readSymbolicLink(javaPathObject(r)).string;
2526
else
26-
r = '';
27+
r = string.empty;
2728
end
2829
otherwise, rethrow(e)
2930
end
3031
end
3132

32-
if isstring(p)
33-
r = string(r);
34-
end
35-
3633
end
3734

3835
%!test

test/TestSymlink.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ function setup_symlink(tc)
1616

1717
tc.tempDir = tc.createTemporaryFolder();
1818

19-
tc.link = fullfile(tc.tempDir, "my.lnk");
19+
tc.link = fullfile(tc.tempDir, 'my.lnk');
2020

21-
tc.target = mfilename("fullpath") + ".m";
21+
tc.target = strcat(mfilename("fullpath"), '.m');
2222

2323
tc.assumeTrue(stdlib.create_symlink(tc.target, tc.link), ...
2424
"failed to create test link " + tc.link)
@@ -36,15 +36,17 @@ function test_is_symlink(tc, p)
3636

3737
function test_read_symlink(tc)
3838

39-
tc.verifyEqual(stdlib.read_symlink(""), "")
40-
tc.verifyEqual(stdlib.read_symlink(''), '')
41-
tc.verifyEqual(stdlib.read_symlink(tempname), '')
42-
tc.verifyEqual(stdlib.read_symlink(tc.target), "")
39+
tc.verifyEmpty(stdlib.read_symlink(""))
40+
tc.verifyEmpty(stdlib.read_symlink(''))
41+
tc.verifyEmpty(stdlib.read_symlink(tempname))
42+
tc.verifyEmpty(stdlib.read_symlink(tc.target))
43+
4344

4445
t = stdlib.read_symlink(tc.link);
45-
tc.verifyNotEmpty(t)
46-
tc.verifyClass(t, 'string')
47-
tc.verifyEqual(tc.target, t)
46+
47+
targ = string(tc.target);
48+
49+
tc.verifyEqual(targ, t)
4850

4951
end
5052

0 commit comments

Comments
 (0)