Skip to content

Commit c1dce42

Browse files
committed
some CI are shaky, use try-catch more efficient
1 parent f7f3d81 commit c1dce42

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

+stdlib/+java/filesystem_type.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
%% JAVA.FILESYSTEM_TYPE
2+
%
3+
% if stdlib.exists() was not adequate here, as on some CI systems, say Windows with Matlab
4+
% R2025a, despite the same setup on a laptop working.
5+
% stdlib.exists() was true, the Java function threw java.nio.file.NoSuchFileException.
6+
%
7+
% this try-catch is faster and more robust
8+
19
function t = filesystem_type(file)
210

3-
if stdlib.exists(file)
11+
t = '';
12+
if ~strlength(file), return, end
13+
14+
try %#ok<TRYNC>
415
t = char(java.nio.file.Files.getFileStore(javaPathObject(file)).type);
5-
else
6-
t = '';
716
end
817

918
end

+stdlib/+java/get_owner.m

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
%% JAVA.GET_OWNER get owner of file
2+
%
3+
%% JAVA.FILESYSTEM_TYPE
4+
%
5+
% if stdlib.exists() was not adequate here, as on some CI systems, say Windows with Matlab
6+
% R2025a, despite the same setup on a laptop working.
7+
% stdlib.exists() was true, the Java function threw java.nio.file.NoSuchFileException.
8+
%
9+
% this try-catch is faster and more robust
210

3-
function n = get_owner(p)
11+
function n = get_owner(file)
412

513
% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/Files.html#getOwner(java.nio.file.Path,java.nio.file.LinkOption...)
614
% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/LinkOption.html
715

8-
if stdlib.exists(p)
9-
opt = java.nio.file.LinkOption.values();
10-
n = char(java.nio.file.Files.getOwner(javaPathObject(p), opt));
11-
else
12-
n = '';
13-
end
16+
n = "";
17+
if ~strlength(file), return, end
1418

1519
try %#ok<TRYNC>
16-
n = string(n);
20+
opt = java.nio.file.LinkOption.values();
21+
n = string(java.nio.file.Files.getOwner(javaPathObject(file), opt));
1722
end
1823

1924
end

test/TestDisk.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ function test_remove_file(tc)
126126

127127

128128
function test_inode_device(tc, java_python_sys, id_name)
129-
n = "stdlib." + java_python_sys + "." + id_name;
129+
130130
h = str2func("stdlib." + id_name);
131-
tc.assertNotEmpty(which(n))
132131

133132
try
134133
ip = h(pwd(), java_python_sys);
135134
tc.verifyClass(ip, 'uint64')
136135
tc.verifyGreaterThan(ip, 0)
136+
137137
tc.verifyEqual(h(".", java_python_sys), ip)
138138
catch e
139139
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)

0 commit comments

Comments
 (0)