Skip to content

Commit c58482e

Browse files
committed
filesystem_type: functionalize, test
1 parent 49e6442 commit c58482e

File tree

6 files changed

+37
-21
lines changed

6 files changed

+37
-21
lines changed

+stdlib/+dotnet/filesystem_type.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function t = filesystem_type(p)
2+
3+
if ~stdlib.exists(p)
4+
t = string.empty;
5+
return
6+
end
7+
8+
t = string(System.IO.DriveInfo(stdlib.absolute(p)).DriveFormat);
9+
% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.driveformat
10+
11+
end

+stdlib/+java/filesystem_type.m

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

3+
if ~stdlib.exists(p)
4+
t = string.empty;
5+
return
6+
end
7+
38
t = string(javaMethod("getFileStore", "java.nio.file.Files", javaPathObject(p)).type);
49

510
end

+stdlib/+python/filesystem_type.m

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

3-
t = string.empty;
3+
if ~stdlib.exists(p)
4+
t = string.empty;
5+
return
6+
end
47

58
pr = stdlib.absolute(p);
69

+stdlib/+sys/filesystem_type.m

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

3+
if ~stdlib.exists(p)
4+
t = string.empty;
5+
return
6+
end
7+
38
if ispc()
49
dl = extractBefore(stdlib.absolute(p), 2);
510
cmd = "pwsh -c (Get-Volume -DriveLetter " + dl + ").FileSystem";
@@ -11,9 +16,9 @@
1116

1217
[s, t] = system(cmd);
1318
if s == 0
14-
t = strip(t);
19+
t = string(strip(t));
1520
else
16-
t = "";
21+
t = string.empty;
1722
end
1823

1924
end

+stdlib/filesystem_type.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
function t = filesystem_type(p)
66

77

8-
t = "";
9-
if ~stdlib.exists(p), return, end
8+
t = string.empty;
109

1110
if stdlib.has_dotnet()
12-
t = System.IO.DriveInfo(stdlib.absolute(p)).DriveFormat;
13-
% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.driveformat
11+
t = stdlib.dotnet.filesystem_type(p);
1412
elseif stdlib.has_java()
1513
t = stdlib.java.filesystem_type(p);
1614
elseif stdlib.has_python()
@@ -21,10 +19,4 @@
2119
t = stdlib.sys.filesystem_type(p);
2220
end
2321

24-
try %#ok<*TRYNC>
25-
t = string(t);
2622
end
27-
28-
end
29-
30-
%!assert(!isempty(filesystem_type(pwd)))

test/TestDisk.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
device_fun = {@stdlib.device, @stdlib.sys.device, @stdlib.java.device, @stdlib.python.device}
1111
disk_available_fun = {@stdlib.disk_available, @stdlib.sys.disk_available, @stdlib.dotnet.disk_available, @stdlib.java.disk_available, @stdlib.python.disk_available}
1212
disk_capacity_fun = {@stdlib.disk_capacity, @stdlib.sys.disk_capacity, @stdlib.dotnet.disk_capacity, @stdlib.java.disk_capacity, @stdlib.python.disk_capacity}
13+
fst_fun = {@stdlib.filesystem_type, @stdlib.sys.filesystem_type, @stdlib.dotnet.filesystem_type, @stdlib.java.filesystem_type, @stdlib.python.filesystem_type}
1314
owner_fun = {@stdlib.get_owner, @stdlib.sys.get_owner, @stdlib.dotnet.get_owner, @stdlib.java.get_owner, @stdlib.python.get_owner}
1415
end
1516

@@ -49,19 +50,18 @@ function test_hard_link_count(tc)
4950
end
5051

5152

52-
function test_filesystem_type(tc, Ps)
53+
function test_filesystem_type(tc, Ps, fst_fun)
54+
is_capable(tc, fst_fun)
5355

54-
s = stdlib.filesystem_type(Ps);
55-
tc.verifyClass(s, 'string')
56-
L = strlength(s);
57-
58-
tc.assumeFalse(isempty(L) && tc.CI, "Some CI block viewing their filesystem type")
56+
t = fst_fun(Ps);
57+
tc.verifyClass(t, 'string')
5958

59+
tc.assumeFalse(isempty(t) && tc.CI, "Some CI block viewing their filesystem type")
6060

6161
if stdlib.exists(Ps)
62-
tc.verifyGreaterThan(L, 0)
62+
tc.verifyGreaterThan(strlength(t), 0)
6363
else
64-
tc.verifyEqual(L, 0)
64+
tc.verifyEmpty(t)
6565
end
6666
end
6767

0 commit comments

Comments
 (0)