Skip to content

Commit e53a9ee

Browse files
committed
test, backend: more efficient, robust
1 parent 363f758 commit e53a9ee

25 files changed

+158
-200
lines changed

+stdlib/+dotnet/create_symlink.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
end
1010

1111
% https://learn.microsoft.com/en-us/dotnet/api/system.io.file.createsymboliclink
12-
try
12+
try %#ok<TRYNC>
1313
System.IO.File.CreateSymbolicLink(link, target);
1414
ok = true;
15-
catch e
16-
warning(e.identifier, "%s", e.message)
1715
end
1816

1917
end

+stdlib/+dotnet/read_symlink.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
%% DOTNET.READ_SYMLINK resolve the symbolic links of a filepath
22

3-
function r = read_symlink(p)
3+
function r = read_symlink(file)
44

55
try
6-
h = System.IO.FileInfo(p);
6+
h = System.IO.FileInfo(file);
77
r = string(h.LinkTarget);
88
% on Unix, this can be empty if the file is not a symlink
9+
if isempty(r)
10+
r = "";
11+
end
912
catch
1013
r = "";
1114
end
1215

13-
if isempty(r)
14-
r = "";
15-
end
16-
1716
end

+stdlib/+java/device.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
% Java 1.8 benefits from the absolute() for stability
77
% seen on older Matlab versions on HPC
88

9-
i = java.nio.file.Files.getAttribute(jp, 'unix:dev', opt);
9+
try
10+
i = java.nio.file.Files.getAttribute(jp, 'unix:dev', opt);
11+
catch
12+
i = [];
13+
end
1014

1115
i = uint64(i);
1216
end

+stdlib/+java/hard_link_count.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
function c = hard_link_count(p)
22

33
opt = java.nio.file.LinkOption.values();
4-
c = java.nio.file.Files.getAttribute(javaPathObject(p), "unix:nlink", opt);
5-
6-
end
4+
try
5+
c = java.nio.file.Files.getAttribute(javaPathObject(p), "unix:nlink", opt);
6+
catch
7+
c = [];
8+
end
9+
end

+stdlib/+java/inode.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
% Java 1.8 benefits from the absolute() for stability--it's not an issue
77
% on every computer.
88

9-
i = java.nio.file.Files.getAttribute(jp, "unix:ino", opt);
9+
try
10+
i = java.nio.file.Files.getAttribute(jp, "unix:ino", opt);
11+
catch
12+
i = [];
13+
end
1014

1115
i = uint64(i);
1216
end

+stdlib/+python/cpu_load.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
L = double(L(1));
88
end
99

10-
11-
1210
end

+stdlib/+python/filesystem_type.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22

33
t = '';
44

5+
% important for heuristic matching
56
if ~stdlib.exists(p)
67
return
78
end
89

910
pr = stdlib.absolute(p);
1011

11-
try
12+
try %#ok<TRYNC>
1213
for part = py.psutil.disk_partitions(p)
1314
prt = part{1};
1415
if startsWith(pr, char(prt.mountpoint))
1516
t = char(prt.fstype);
1617
return
1718
end
1819
end
19-
catch e
20-
warning(e.identifier, "filesystem_type(%s) failed: %s", p, e.message);
2120
end
2221

2322
end

+stdlib/+python/get_owner.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function n = get_owner(p)
22

3-
if stdlib.exists(p)
3+
try
44
n = string(py.str(py.pathlib.Path(p).owner()));
5-
else
5+
catch
66
n = "";
77
end
88

+stdlib/+sys/samepath.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
function y = samepath(path1, path2)
22

3-
assert(~ispc(), "Unix-like only")
4-
53
y = false;
64

75
if ~stdlib.exists(path1) || ~stdlib.exists(path2)
86
return
97
end
108

9+
if ispc()
10+
y = stdlib.sys.device(path1) == stdlib.sys.device(path2) && ...
11+
stdlib.sys.inode(path1) == stdlib.sys.inode(path2);
12+
return
13+
end
14+
15+
1116
if ismac()
1217
flag = '-f';
1318
else

+stdlib/canonical.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
backend (1,:) string = ["native", "legacy"]
2222
end
2323

24-
[fun, b] = hbackend(backend, "canonical", 'R2024a');
24+
[fun, b] = hbackend(backend, "canonical");
2525

2626
if isscalar(p) || b == "native"
2727
c = fun(p, strict);

0 commit comments

Comments
 (0)