Skip to content

Commit 74cc349

Browse files
committed
shell fallback get_owner
1 parent ad7b909 commit 74cc349

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

+stdlib/+python/get_owner.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
function n = get_owner(p)
22

3-
n = string(py.str(py.pathlib.Path(p).owner()));
3+
try
4+
n = string(py.str(py.pathlib.Path(p).owner()));
5+
catch e
6+
warning(e.identifier, "get_owner(%s) failed: %s", p, e.message);
7+
n = string.empty;
8+
end
49

510
end

+stdlib/+sys/get_owner.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function o = get_owner(p)
2+
3+
o = string.empty;
4+
5+
if ispc()
6+
cmd = "pwsh -c (Get-Acl -Path '" + p + "').Owner";
7+
elseif ismac()
8+
cmd = "stat -f %Su " + p;
9+
else
10+
cmd = "stat -c %U " + p;
11+
end
12+
13+
[s, o] = system(cmd);
14+
if s == 0
15+
o = strip(o);
16+
end
17+
18+
end

+stdlib/get_owner.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929
end
3030

31+
if strempty(n)
32+
n = stdlib.sys.get_owner(p);
33+
end
34+
3135
end
3236

3337
%!assert(!isempty(get_owner(pwd)))

test/TestDisk.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,12 @@ function test_device(tc)
7373

7474

7575
function test_inode(tc)
76-
tc.assumeTrue(stdlib.has_python() || (isunix() && stdlib.java_api() >= 11))
7776

7877
tc.verifyEqual(stdlib.inode("."), stdlib.inode(pwd()))
7978
end
8079

8180

8281
function test_owner(tc)
83-
tc.assumeTrue((~ispc() && stdlib.has_python()) || stdlib.has_java())
8482

8583
s = stdlib.get_owner(".");
8684

0 commit comments

Comments
 (0)