Skip to content

Commit 3151fe7

Browse files
committed
owner: python also
1 parent 577bddc commit 3151fe7

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

+stdlib/get_owner.m

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
%% GET_OWNER owner of file or directory
2-
% requires: java
32
%
43
%%% Inputs
54
% * p: path to examine
65
%%% Outputs
76
% * n: owner, or empty if path does not exist
7+
88
function n = get_owner(p)
99
arguments
1010
p {mustBeTextScalar}
1111
end
1212

13+
14+
if ~ispc() && stdlib.has_python()
15+
16+
n = string(py.str(py.pathlib.Path(p).owner()));
17+
18+
elseif stdlib.has_java()
1319
% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/Files.html#getOwner(java.nio.file.Path,java.nio.file.LinkOption...)
1420
% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/LinkOption.html
1521

16-
opt = javaMethod("values", "java.nio.file.LinkOption");
22+
opt = javaMethod("values", "java.nio.file.LinkOption");
23+
24+
n = javaMethod("getOwner", "java.nio.file.Files", javaPathObject(p), opt).toString();
25+
% .toString() needed for Octave
1726

18-
n = javaMethod("getOwner", "java.nio.file.Files", javaPathObject(p), opt).toString();
19-
% .toString() needed for Octave
27+
try %#ok<*TRYNC>
28+
n = string(n);
29+
end
2030

21-
try %#ok<*TRYNC>
22-
n = string(n);
2331
end
2432

2533
end

test/TestDisk.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,15 @@ function test_inode(tc)
6868
tc.verifyEqual(stdlib.inode("."), stdlib.inode(pwd()))
6969
end
7070

71+
72+
function test_owner(tc)
73+
tc.assumeTrue((~ispc() && stdlib.has_python()) || stdlib.has_java())
74+
75+
s = stdlib.get_owner(".");
76+
77+
tc.verifyClass(s, 'string')
78+
tc.verifyGreaterThan(strlength(s), 0)
79+
end
80+
7181
end
7282
end

test/TestJava.m

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
11
classdef TestJava < matlab.unittest.TestCase
22

3-
properties (TestParameter)
4-
Ps = {"."}
5-
end
6-
7-
8-
methods (Test, TestTags=["java", "unix"])
9-
10-
11-
function test_owner(tc, Ps)
12-
13-
s = stdlib.get_owner(Ps);
14-
tc.verifyClass(s, 'string')
15-
L = strlength(s);
16-
17-
if stdlib.exists(Ps)
18-
tc.verifyGreaterThan(L, 0)
19-
else
20-
tc.verifyEqual(L, 0)
21-
end
22-
end
23-
24-
end
25-
263

274
methods(Test, TestTags="java")
285

0 commit comments

Comments
 (0)