Skip to content

Commit 63c6916

Browse files
committed
shell fallback get_owner
shell fallback filesystem_type
1 parent 0c04aad commit 63c6916

File tree

7 files changed

+54
-9
lines changed

7 files changed

+54
-9
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/device.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
if ispc()
66
c0 = 'powershell -Command "(Get-CimInstance -ClassName Win32_Volume -Filter \"DriveLetter = ''';
7-
c1 = stdlib.root_name(stdlib.resolve(p));
7+
c1 = stdlib.root_name(stdlib.absolute(p));
88
c2 = '''\").SerialNumber"';
99
cmd = strcat(c0, c1, c2);
1010
elseif ismac()

+stdlib/+sys/filesystem_type.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function t = filesystem_type(p)
2+
3+
if ispc()
4+
dl = extractBefore(stdlib.absolute(p), 2);
5+
cmd = "pwsh -c (Get-Volume -DriveLetter " + dl + ").FileSystem";
6+
elseif ismac()
7+
cmd = "df -aHY " + p + " | awk 'NR==2 {print $2}'";
8+
else
9+
cmd = "df -T " + p + " | awk 'NR==2 {print $2}'";
10+
end
11+
12+
[s, t] = system(cmd);
13+
if s == 0
14+
t = strip(t);
15+
else
16+
t = "";
17+
end
18+
19+
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+
if ispc()
4+
cmd = "pwsh -c (Get-Acl -Path '" + p + "').Owner";
5+
elseif ismac()
6+
cmd = "stat -f %Su " + p;
7+
else
8+
cmd = "stat -c %U " + p;
9+
end
10+
11+
[s, o] = system(cmd);
12+
if s == 0
13+
o = strip(o);
14+
else
15+
o = string.empty;
16+
end
17+
18+
end

+stdlib/filesystem_type.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
% example outputs: NTFS, ext4, apfs, ...
44

55
function t = filesystem_type(p)
6-
arguments
7-
p {mustBeTextScalar}
8-
end
6+
97

108
t = "";
119
if ~stdlib.exists(p), return, end
@@ -17,6 +15,10 @@
1715
t = javaMethod("getFileStore", "java.nio.file.Files", javaPathObject(p)).type;
1816
end
1917

18+
if strempty(p)
19+
t = stdlib.sys.filesystem_type(p);
20+
end
21+
2022
try %#ok<*TRYNC>
2123
t = string(t);
2224
end

+stdlib/get_owner.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
p {mustBeTextScalar}
1111
end
1212

13+
n = string.empty;
1314

1415
if ~ispc() && stdlib.has_python()
1516
n = stdlib.python.get_owner(p);
@@ -28,6 +29,10 @@
2829

2930
end
3031

32+
if strempty(n)
33+
n = stdlib.sys.get_owner(p);
34+
end
35+
3136
end
3237

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

test/TestDisk.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ function test_hard_link_count(tc)
4848

4949
function test_filesystem_type(tc, Ps)
5050

51-
tc.assumeTrue(stdlib.has_dotnet() || stdlib.has_java())
52-
5351
s = stdlib.filesystem_type(Ps);
5452
tc.verifyClass(s, 'string')
5553
L = strlength(s);
@@ -73,14 +71,12 @@ function test_device(tc)
7371

7472

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

7875
tc.verifyEqual(stdlib.inode("."), stdlib.inode(pwd()))
7976
end
8077

8178

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

8581
s = stdlib.get_owner(".");
8682

0 commit comments

Comments
 (0)