Skip to content

Commit 4d0a648

Browse files
committed
filesystem_type: robust
1 parent 6a11a1d commit 4d0a648

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

+stdlib/+python/filesystem_type.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
t = '';
44

5+
try
56
% important for heuristic matching
6-
p = py.str(file);
7-
if ~py.os.path.exists(p)
8-
return
9-
end
7+
p = py.str(file);
8+
if ~py.os.path.exists(p)
9+
return
10+
end
1011

11-
p = py.os.path.abspath(p);
12+
p = py.os.path.abspath(p);
1213

1314
% https://psutil.readthedocs.io/en/stable/index.html?highlight=disk_partitions#psutil.disk_partitions
14-
try
15+
1516
for part = py.psutil.disk_partitions()
1617
prt = part{1};
1718
if p.startswith(prt.mountpoint)

+stdlib/filesystem_type.m

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,35 @@
66
% * file: path to check
77
% * backend: backend to use
88
%%% Outputs
9-
% * t: filesystem type
9+
% * r: filesystem type
1010
% * b: backend used
1111

12-
function [t, b] = filesystem_type(file, backend)
12+
function [r, b] = filesystem_type(file, backend)
1313
arguments
1414
file
1515
backend (1,:) string = ["java", "dotnet", "python", "sys"]
1616
end
1717

18-
o = stdlib.Backend(mfilename(), backend);
19-
t = o.func(file);
20-
b = o.backend;
18+
r = '';
19+
20+
for b = backend
21+
switch b
22+
case "java"
23+
r = stdlib.java.filesystem_type(file);
24+
case "dotnet"
25+
r = stdlib.dotnet.filesystem_type(file);
26+
case "python"
27+
if stdlib.matlabOlderThan('R2022a'), continue, end
28+
r = stdlib.python.filesystem_type(file);
29+
case "sys"
30+
r = stdlib.sys.filesystem_type(file);
31+
otherwise
32+
error("stdlib:filesystem_type:ValueError", "Unknown backend: %s", b)
33+
end
34+
35+
if ~isempty(r)
36+
return
37+
end
38+
end
2139

2240
end

test/TestDisk.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ function test_hard_link_count(tc, B_hard_link_count)
100100

101101

102102
function test_filesystem_type(tc, Ps, B_filesystem_type)
103-
t = stdlib.filesystem_type(Ps, B_filesystem_type);
103+
[t, b] = stdlib.filesystem_type(Ps, B_filesystem_type);
104+
tc.assertEqual(char(b), B_filesystem_type)
104105
tc.verifyClass(t, 'char')
105106

106107
if ~stdlib.exists(Ps)

test/TestSys.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,17 @@ function test_cpu_arch(tc)
102102
end
103103

104104
function test_ram_total(tc, B_ram_total)
105-
t = stdlib.ram_total(B_ram_total);
105+
[t, b] = stdlib.ram_total(B_ram_total);
106+
tc.assertEqual(char(b), B_ram_total)
106107
tc.verifyClass(t, 'uint64')
107108
tc.verifyGreaterThan(t, 0)
108109
end
109110

110111

111112
function test_ram_free(tc, B_ram_free)
112113
% don't verify less than or equal to total due to shaky system measurements'
113-
f = stdlib.ram_free(B_ram_free);
114+
[f, b] = stdlib.ram_free(B_ram_free);
115+
tc.assertEqual(char(b), B_ram_free)
114116

115117
tc.verifyClass(f, 'uint64')
116118
if B_ram_free == "python" && ~stdlib.python.has_psutil()

0 commit comments

Comments
 (0)