Skip to content

Commit aafa1a3

Browse files
committed
filesystem_type: choose_method
1 parent e5ac4d1 commit aafa1a3

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

+stdlib/+dotnet/filesystem_type.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
function t = filesystem_type(p)
44

5-
if ~stdlib.exists(p)
5+
if stdlib.exists(p)
6+
t = string(System.IO.DriveInfo(stdlib.absolute(p)).DriveFormat);
7+
% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.driveformat
8+
else
69
t = string.empty;
7-
return
810
end
911

10-
t = string(System.IO.DriveInfo(stdlib.absolute(p)).DriveFormat);
11-
% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.driveformat
12-
1312
end

+stdlib/+java/filesystem_type.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
function t = filesystem_type(p)
22

3-
if ~stdlib.exists(p)
3+
if stdlib.exists(p)
4+
t = string(javaMethod("getFileStore", "java.nio.file.Files", javaPathObject(p)).type);
5+
else
46
t = string.empty;
5-
return
67
end
78

8-
t = string(javaMethod("getFileStore", "java.nio.file.Files", javaPathObject(p)).type);
9-
109
end

+stdlib/filesystem_type.m

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
%
33
% example outputs: NTFS, ext4, apfs, ...
44

5-
function t = filesystem_type(p)
6-
7-
if stdlib.has_java()
8-
t = stdlib.java.filesystem_type(p);
9-
elseif stdlib.has_dotnet()
10-
t = stdlib.dotnet.filesystem_type(p);
11-
elseif stdlib.python.has_psutil()
12-
t = stdlib.python.filesystem_type(p);
13-
else
14-
t = stdlib.sys.filesystem_type(p);
5+
function t = filesystem_type(file, method)
6+
arguments
7+
file {mustBeTextScalar}
8+
method (1,:) string = ["java", "dotnet", "python", "sys"]
159
end
1610

11+
fun = choose_method(method, "filesystem_type");
12+
13+
t = fun(file);
14+
1715
end

test/TestDisk.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
disk_ac_fun = {'sys', 'dotnet', 'java', 'python'}
1313
disk_ac_name = {'disk_available', 'disk_capacity'}
1414
hl_fun = {'java', 'python'}
15-
fst_fun = {@stdlib.filesystem_type, @stdlib.sys.filesystem_type, @stdlib.dotnet.filesystem_type, @stdlib.java.filesystem_type, @stdlib.python.filesystem_type}
15+
fst_fun = {'sys', 'dotnet', 'java', 'python'}
1616
owner_fun = {@stdlib.get_owner, @stdlib.sys.get_owner, @stdlib.dotnet.get_owner, @stdlib.java.get_owner, @stdlib.python.get_owner}
1717
end
1818

@@ -59,14 +59,18 @@ function test_hard_link_count(tc, hl_fun)
5959

6060

6161
function test_filesystem_type(tc, Ps, fst_fun)
62-
is_capable(tc, fst_fun)
63-
64-
t = fst_fun(Ps);
62+
tc.assertNotEmpty(which("stdlib." + fst_fun + ".filesystem_type"))
63+
try
64+
t = stdlib.filesystem_type(Ps, fst_fun);
65+
catch e
66+
tc.verifyEqual(e.identifier, 'stdlib:choose_method:NameError', e.message)
67+
return
68+
end
6569
tc.verifyClass(t, 'string')
6670

67-
6871
if stdlib.exists(Ps)
6972
tc.assumeFalse(isempty(t) && tc.CI, "Some CI block viewing their filesystem type")
73+
tc.assertNotEmpty(t)
7074
tc.verifyGreaterThan(strlength(t), 0)
7175
else
7276
tc.verifyEmpty(t)

0 commit comments

Comments
 (0)