Skip to content

Commit 7d20e17

Browse files
committed
owner: return char
1 parent 52e0f19 commit 7d20e17

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

+stdlib/+dotnet/get_owner.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
function o = get_owner(p)
44

5-
if ~stdlib.exists(p)
6-
o = string.empty;
7-
return
8-
end
9-
105
% This is not yet possible with .NET on Unix, even with .NET 10.
116
% It would require Pinvoke or external Mono.Unix
127

@@ -17,12 +12,15 @@
1712

1813
if isfolder(p)
1914
fsec = System.IO.Directory.GetAccessControl(p);
20-
else
15+
elseif isfile(p)
2116
fsec = System.IO.File.GetAccessControl(p);
17+
else
18+
o = '';
19+
return
2220
end
2321

2422
owner = fsec.GetOwner(ntAccountType);
2523

26-
o = string(owner.Value);
24+
o = char(owner.ToString());
2725

2826
end

+stdlib/+java/get_owner.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
function n = get_owner(p)
1+
%% JAVA.GET_OWNER get owner of file
22

3-
n = string.empty;
4-
if ~stdlib.exists(p), return, end
3+
function n = get_owner(p)
54

65
% 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...)
76
% https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/LinkOption.html
87

8+
n = '';
9+
if ~stdlib.exists(p)
10+
return
11+
end
12+
13+
914
try
1015
opt = javaMethod("values", "java.nio.file.LinkOption");
1116

12-
n = string(javaMethod("getOwner", "java.nio.file.Files", javaPathObject(p), opt));
17+
n = char(javaMethod("getOwner", "java.nio.file.Files", javaPathObject(p), opt));
1318
catch e
1419
warning(e.identifier, "get_owner(%s) failed: %s", p, e.message)
1520
end

+stdlib/+python/get_owner.m

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

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

68
try
7-
n = string(py.str(py.pathlib.Path(p).owner()));
9+
n = char(py.str(py.pathlib.Path(p).owner()));
810
catch e
911
warning(e.identifier, "get_owner(%s) failed: %s", p, e.message)
1012
end

+stdlib/+sys/get_owner.m

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

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

68
if ispc()
7-
cmd = sprintf('pwsh -c (Get-Acl -Path "%s").Owner', p);
9+
cmd = sprintf('pwsh -c "if($x=Get-Acl -Path ''%s'') {$x.Owner}"', p);
810
elseif ismac()
911
cmd = sprintf('stat -f %%Su "%s"', p);
1012
else
@@ -13,7 +15,7 @@
1315

1416
[s, m] = system(cmd);
1517
if s == 0
16-
o = string(strip(m));
18+
o = strip(m);
1719
end
1820

1921
end

test/TestDisk.m

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
properties (TestParameter)
88
Ps = {".", "", "/", getenv("SystemDrive"), "not-exist"}
9-
Po = {mfilename("fullpath") + ".m", pwd(), ".", "", tempname()}
9+
Po = {mfilename("fullpath") + ".m", pwd(), ".", "", "not-exist"}
1010
id_fun = {'sys', 'java', 'python'}
1111
id_name = {"inode", "device"}
12-
disk_ac_fun = {'sys', 'dotnet', 'java', 'python'}
12+
all_fun = {'sys', 'dotnet', 'java', 'python'}
1313
disk_ac_name = {'disk_available', 'disk_capacity'}
1414
hl_fun = {'java', 'python'}
15-
fst_fun = {'sys', 'dotnet', 'java', 'python'}
1615
is_remove = {'dotnet', 'sys'}
1716
py_sys = {'python', 'sys'}
1817
end
@@ -26,13 +25,13 @@ function pkg_path(tc)
2625

2726
methods (Test)
2827

29-
function test_disk_ac(tc, Ps, disk_ac_fun, disk_ac_name)
30-
n = "stdlib." + disk_ac_fun + "." + disk_ac_name;
28+
function test_disk_ac(tc, Ps, all_fun, disk_ac_name)
29+
n = "stdlib." + all_fun + "." + disk_ac_name;
3130
h = str2func("stdlib." + disk_ac_name);
3231
tc.assertNotEmpty(which(n))
3332

3433
try
35-
r = h(Ps, disk_ac_fun);
34+
r = h(Ps, all_fun);
3635
if stdlib.exists(Ps)
3736
tc.verifyGreaterThanOrEqual(r, 0)
3837
else
@@ -93,10 +92,10 @@ function test_hard_link_count(tc, hl_fun)
9392
end
9493

9594

96-
function test_filesystem_type(tc, Ps, fst_fun)
97-
tc.assertNotEmpty(which("stdlib." + fst_fun + ".filesystem_type"))
95+
function test_filesystem_type(tc, Ps, all_fun)
96+
tc.assertNotEmpty(which("stdlib." + all_fun + ".filesystem_type"))
9897
try
99-
t = stdlib.filesystem_type(Ps, fst_fun);
98+
t = stdlib.filesystem_type(Ps, all_fun);
10099
catch e
101100
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
102101
return
@@ -146,17 +145,17 @@ function test_inode_device(tc, id_fun, id_name)
146145
end
147146

148147

149-
function test_owner(tc, Po, fst_fun)
150-
tc.assertNotEmpty(which("stdlib." + fst_fun + ".get_owner"))
148+
function test_owner(tc, Po, all_fun)
149+
tc.assertNotEmpty(which("stdlib." + all_fun + ".get_owner"))
151150

152151
try
153-
o = stdlib.get_owner(Po, fst_fun);
152+
o = stdlib.get_owner(Po, all_fun);
154153
catch e
155154
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
156155
return
157156
end
158157

159-
tc.verifyClass(o, 'string')
158+
tc.verifyClass(o, 'char')
160159

161160
if stdlib.exists(Po)
162161
tc.verifyGreaterThan(strlength(o), 0)

0 commit comments

Comments
 (0)