Skip to content

Commit 24dc8f5

Browse files
committed
get_owner: handle non-existing path
1 parent 7151e9e commit 24dc8f5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

+stdlib/get_owner.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
%% GET_OWNER owner of file or directory
2-
2+
%
3+
%%% Inputs
4+
% * p: path to examine
5+
%%% Outputs
6+
% * n: owner, or empty if path does not exist
37
function n = get_owner(p)
48
arguments
59
p (1,1) string
@@ -8,6 +12,9 @@
812
% 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...)
913
% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/LinkOption.html
1014

15+
n = "";
16+
if ~stdlib.exists(p), return, end
17+
1118
op = javaPathObject(p);
1219
opt = javaLinkOption();
1320

@@ -20,3 +27,4 @@
2027
end
2128

2229
%!assert(!isempty(get_owner(pwd)))
30+
%!assert(isempty(get_owner(tempname)))

test/TestJava.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ function test_filesystem_type(tc)
2020

2121
function test_owner(tc)
2222
owner = stdlib.get_owner('.');
23-
L = strlength(owner);
24-
tc.verifyGreaterThan(L, 0, "expected non-empty username")
23+
tc.verifyGreaterThan(strlength(owner), 0, "expected non-empty username")
24+
25+
owner = stdlib.get_owner(tempname);
26+
tc.verifyEqual(strlength(owner), 0, "expected empty owner")
27+
2528
end
2629

2730

0 commit comments

Comments
 (0)