Skip to content

Commit 0011c48

Browse files
committed
is_admin: optional python
1 parent 17fcc20 commit 0011c48

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

+stdlib/is_admin.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44
function y = is_admin()
55

66

7-
if stdlib.isoctave()
7+
if stdlib.has_python()
8+
if isunix()
9+
y = py.os.getuid() == 0;
10+
else
11+
shell32 = py.ctypes.WinDLL('shell32');
12+
13+
% this is a key step vs. simply py.ctypes.windll.shell32.IsUserAnAdmin()
14+
f = py.getattr(shell32, 'IsUserAnAdmin');
15+
16+
y = logical(f());
17+
end
18+
elseif stdlib.isoctave()
819
y = getuid() == 0;
920
elseif ispc() && stdlib.has_dotnet()
1021
% com.sun.security.auth.module.NTSystem().getGroupIDs();

buildfile.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,17 @@ function build_exe(context)
262262

263263
srcs = {
264264
"src/remove.cpp", ...
265-
["src/is_admin.cpp", "src/admin_fs.cpp"] ...
266-
"src/is_char_device.cpp", ...
267265
["src/normalize.cpp", normal], ...
268266
"src/disk_available.cpp", ...
269267
"src/disk_capacity.cpp", ...
270268
"src/set_permissions.cpp", ...
271269
};
272270

271+
if ~stdlib.has_python() || build_all
272+
srcs{end+1} = "src/is_char_device.cpp";
273+
srcs{end+1} = ["src/is_admin.cpp", "src/admin_fs.cpp"];
274+
end
275+
273276
if (isMATLABReleaseOlderThan("R2024b") && ~stdlib.has_dotnet()) || build_all
274277
srcs{end+1} = ["src/is_symlink.cpp", win, sym];
275278
end

0 commit comments

Comments
 (0)