Skip to content

Commit fc4924c

Browse files
committed
add is_dev_drive()
1 parent e67084e commit fc4924c

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

+stdlib/+python/is_dev_drive.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function y = is_dev_drive(fpath)
2+
% https://github.com/python/cpython/blob/9ee0214b5dd982ac9fbe18dcce0e8787456e29af/Modules/posixmodule.c#L4916
3+
try
4+
y = py.os.path.isdevdrive(fpath);
5+
catch
6+
y = false;
7+
end
8+
9+
end

+stdlib/+sys/is_dev_drive.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function [y, cmd] = is_dev_drive(fpath)
2+
arguments
3+
fpath (1,1) string
4+
end
5+
6+
y = false;
7+
cmd = '';
8+
9+
10+
if ispc()
11+
cmd = sprintf('fsutil devdrv query ''%s''', fpath);
12+
[s, m] = system(cmd);
13+
if s == 0
14+
y = contains(m, ["This is a trusted developer volume", "this developer volume"]);
15+
else
16+
y = logical.empty;
17+
end
18+
end
19+
end

+stdlib/Backend.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
if ispc(), continue, end
8181
case 'is_admin'
8282
if ispc() || stdlib.matlabOlderThan('R2024a'), continue, end
83+
case 'is_dev_drive'
84+
pyv = stdlib.python_version();
85+
if any(pyv(1:2) < [3, 12]), continue, end
8386
end
8487
case 'native'
8588

+stdlib/is_dev_drive.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%% IS_DEV_DRIVE is path on a Windows Dev Drive developer volume
2+
3+
function [y, b] = is_dev_drive(fpath, backend)
4+
arguments
5+
fpath (1,1) string
6+
backend (1,:) string = ["python", "sys"]
7+
end
8+
9+
o = stdlib.Backend(mfilename(), backend);
10+
y = o.func(fpath);
11+
b = o.backend;
12+
13+
end

test/TestDisk.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
B_filesystem_type
1717
B_owner
1818
B_device
19+
B_is_dev_drive
1920
end
2021

2122
methods (TestParameterDefinition, Static)
22-
function [B_disk, B_is_removable, B_is_mount, B_hard_link_count, B_filesystem_type, B_owner, B_device] = setupBackends()
23+
function [B_disk, B_is_removable, B_is_mount, B_hard_link_count, B_filesystem_type, B_owner, B_device, B_is_dev_drive] = setupBackends()
2324
B_disk = init_backend("disk_available");
2425
B_is_removable = init_backend("is_removable");
2526
B_is_mount = init_backend("is_mount");
2627
B_hard_link_count = init_backend("hard_link_count");
2728
B_filesystem_type = init_backend("filesystem_type");
2829
B_owner = init_backend("get_owner");
2930
B_device = init_backend("device");
31+
B_is_dev_drive = init_backend('is_dev_drive');
3032
end
3133
end
3234

@@ -109,6 +111,11 @@ function test_filesystem_type(tc, Ps, B_filesystem_type)
109111
end
110112

111113

114+
function test_is_dev_drive(tc, B_is_dev_drive)
115+
tc.verifyClass(stdlib.is_dev_drive(pwd(), B_is_dev_drive), 'logical')
116+
end
117+
118+
112119
function test_remove_file(tc)
113120

114121
f = tempname();

0 commit comments

Comments
 (0)