Skip to content

Commit 7b650a3

Browse files
committed
device: shell fallback
1 parent 1c9b0d2 commit 7b650a3

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

+stdlib/private/device_dotnet.m renamed to +stdlib/+dotnet/device.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
function i = device_dotnet(path)
1+
function i = device(path)
22

3+
i = [];
34

45
h = NET.addAssembly('System.Management');
56

+stdlib/+sys/device.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function i = device(p)
2+
3+
4+
if ispc()
5+
cmd = "powershell -Command (Get-CimInstance -ClassName Win32_Volume -Filter 'DriveLetter = \"" + p(1) + "\"').DeviceID";
6+
elseif ismac()
7+
cmd = "stat -f %d " + p;
8+
elseif isunix()
9+
cmd = "stat -c %d " + p;
10+
end
11+
12+
13+
[s, m] = system(cmd);
14+
if s == 0
15+
i = str2double(m);
16+
end
17+
18+
end

+stdlib/device.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
if stdlib.has_python()
1111
i = stdlib.python.device(p);
1212
elseif ispc() && stdlib.has_dotnet()
13-
i = device_dotnet(p);
14-
elseif stdlib.isoctave()
15-
[s, err] = stat(p);
16-
if err == 0
17-
i = s.dev;
18-
end
13+
i = stdlib.dotnet.device(p);
1914
elseif isunix() && stdlib.java_api() >= 11
2015
% Java 1.8 is buggy in some corner cases, so we require at least 11.
2116
opt = javaMethod("values", "java.nio.file.LinkOption");
2217
i = java.nio.file.Files.getAttribute(javaPathObject(p), "unix:dev", opt);
2318
end
2419

20+
if isempty(i)
21+
i = stdlib.sys.device(p);
22+
end
23+
24+
i = uint64(i);
25+
2526
end
2627

2728
%!assert(device(pwd) >= 0);

test/TestDisk.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ function test_filesystem_type(tc, Ps)
6464

6565
function test_device(tc)
6666

67-
tc.assumeTrue(stdlib.has_python() || (ispc() && stdlib.has_dotnet()) || (isunix() && stdlib.java_api() >= 11))
68-
6967
if ispc()
7068
tc.verifyGreaterThan(stdlib.device(pwd()), 0)
7169
else

0 commit comments

Comments
 (0)