Skip to content

Commit 7960ee4

Browse files
committed
owner: simplify
1 parent f27c794 commit 7960ee4

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

+stdlib/+java/get_owner.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
function n = get_owner(p)
22

3-
if ~stdlib.exists(p)
4-
n = string.empty;
5-
return
6-
end
3+
n = string.empty;
4+
if ~stdlib.exists(p), return, end
75

86
% 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...)
97
% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/LinkOption.html
@@ -13,8 +11,7 @@
1311

1412
n = string(javaMethod("getOwner", "java.nio.file.Files", javaPathObject(p), opt));
1513
catch e
16-
warning(e.identifier, "%s", e.message)
17-
n = string.empty;
14+
warning(e.identifier, "get_owner(%s) failed: %s", p, e.message)
1815
end
1916

2017
end

+stdlib/+python/get_owner.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
function n = get_owner(p)
22

3-
if ~stdlib.exists(p)
4-
n = string.empty;
5-
return
6-
end
3+
n = string.empty;
4+
if ~stdlib.exists(p), return, end
75

86
try
97
n = string(py.str(py.pathlib.Path(p).owner()));
108
catch e
119
warning(e.identifier, "get_owner(%s) failed: %s", p, e.message);
12-
n = string.empty;
1310
end
1411

1512
end

+stdlib/+sys/get_owner.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
function o = get_owner(p)
22

3-
if ~stdlib.exists(p)
4-
o = string.empty;
5-
return
6-
end
3+
o = string.empty;
4+
if ~stdlib.exists(p), return, end
75

86
if ispc()
97
cmd = "pwsh -c (Get-Acl -Path '" + p + "').Owner";
@@ -13,11 +11,9 @@
1311
cmd = "stat -c %U " + p;
1412
end
1513

16-
[s, o] = system(cmd);
14+
[s, m] = system(cmd);
1715
if s == 0
18-
o = string(strip(o));
19-
else
20-
o = string.empty;
16+
o = string(strip(m));
2117
end
2218

2319
end

0 commit comments

Comments
 (0)