Skip to content

Commit 53b1233

Browse files
committed
filesystem_type: more robust, don't require java on Windows
1 parent 4bbca69 commit 53b1233

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

+stdlib/filesystem_type.m

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
%% FILESYSTEM_TYPE tell type of filesystem
2-
% requires: java
2+
% optional: java
33
%
4-
% example outputs: ntfs, ext4, apfs, ...
5-
%
6-
% if empty output or error, try specifying the drive root
7-
% like "/" or "C:/"
4+
% example outputs: NTFS, ext4, apfs, ...
85

96
function t = filesystem_type(p)
107
arguments
11-
p {mustBeTextScalar} = ''
8+
p {mustBeTextScalar}
129
end
1310

14-
op = javaPathObject(p);
11+
t = "";
12+
if ~stdlib.exists(p), return, end
1513

16-
if stdlib.isoctave()
17-
t = javaMethod("getFileStore", "java.nio.file.Files", op).type;
14+
if ispc()
15+
t = string(System.IO.DriveInfo(stdlib.absolute(p)).DriveFormat);
1816
else
19-
t = java.nio.file.Files.getFileStore(op).type.string;
20-
end
17+
op = javaPathObject(p);
2118

19+
if stdlib.isoctave()
20+
t = javaMethod("getFileStore", "java.nio.file.Files", op).type;
21+
else
22+
t = java.nio.file.Files.getFileStore(op).type.string;
23+
end
2224
end
2325

2426
%!assert(!isempty(filesystem_type(pwd)))

test/TestDisk.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,21 @@ function test_disk_capacity(tc, Ps)
3333
end
3434
end
3535

36+
37+
function test_filesystem_type(tc, Ps)
38+
39+
tc.assumeTrue(ispc() || stdlib.has_java())
40+
41+
s = stdlib.filesystem_type(Ps);
42+
tc.verifyClass(s, 'string')
43+
L = strlength(s);
44+
45+
if stdlib.exists(Ps)
46+
tc.verifyGreaterThan(L, 0)
47+
else
48+
tc.verifyEqual(L, 0)
49+
end
50+
end
51+
3652
end
3753
end

test/TestJava.m

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,6 @@ function test_owner(tc, Ps)
4040

4141
methods(Test, TestTags="java")
4242

43-
function test_filesystem_type(tc, Ps)
44-
45-
s = stdlib.filesystem_type(Ps);
46-
tc.verifyClass(s, 'string')
47-
L = strlength(s);
48-
49-
if strlength(Ps) == 0 || stdlib.exists(Ps)
50-
tc.verifyGreaterThan(L, 0)
51-
else
52-
tc.verifyEqual(L, 0)
53-
end
54-
end
55-
5643
function test_username(tc)
5744
u = stdlib.get_username();
5845
tc.verifyGreaterThan(strlength(u), 0)

0 commit comments

Comments
 (0)