Skip to content

Commit 5257277

Browse files
committed
device, inode, ram, disk: return empty on failure as sentinel
1 parent c7e2f00 commit 5257277

File tree

18 files changed

+71
-38
lines changed

18 files changed

+71
-38
lines changed

+stdlib/+dotnet/disk_available.m

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

33
function f = disk_available(p)
44

5-
f = uint64(0);
5+
f = uint64([]);
66

77
if ~stdlib.exists(p), return, end
88

+stdlib/+dotnet/disk_capacity.m

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

33
function f = disk_capacity(d)
44

5-
f = uint64(0);
5+
f = uint64([]);
66

77
if ~stdlib.exists(d), return, end
88

+stdlib/+java/device.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
function i = device(file)
22

3+
i = uint64([]);
4+
if ~stdlib.exists(file), return, end
5+
36
opt = java.nio.file.LinkOption.values();
47

58
jp = javaPathObject(stdlib.absolute(file));
69
% Java 1.8 benefits from the absolute() for stability
710
% seen on older Matlab versions on HPC
811

9-
try
12+
try %#ok<TRYNC>
1013
i = java.nio.file.Files.getAttribute(jp, 'unix:dev', opt);
11-
catch
12-
i = [];
1314
end
1415

1516
i = uint64(i);

+stdlib/+java/disk_available.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
function i = disk_available(file)
22

33
i = java.io.File(file).getUsableSpace();
4+
if i < 1
5+
i = [];
6+
end
47

58
i = uint64(i);
69
end

+stdlib/+java/disk_capacity.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
function f = disk_capacity(d)
1+
function i = disk_capacity(d)
22

3-
f = uint64(java.io.File(d).getTotalSpace());
3+
i = java.io.File(d).getTotalSpace();
4+
if i < 1
5+
i = [];
6+
end
47

8+
i = uint64(i);
59
end

+stdlib/+java/inode.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
function i = inode(file)
22

3+
i = uint64([]);
4+
if ~stdlib.exists(file), return, end
5+
36
opt = java.nio.file.LinkOption.values();
47

58
jp = javaPathObject(stdlib.absolute(file));
69
% Java 1.8 benefits from the absolute() for stability--it's not an issue
710
% on every computer.
811

9-
try
12+
try %#ok<TRYNC>
1013
i = java.nio.file.Files.getAttribute(jp, "unix:ino", opt);
11-
catch
12-
i = [];
1314
end
1415

1516
i = uint64(i);

+stdlib/+python/device.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
function i = device(file)
22

3-
i = 0;
4-
53
try
64
i = int64(py.os.stat(file).st_dev);
75
% int64 first is for Matlab <= R2022a
86
catch e
97
if ~contains(e.message, "FileNotFoundError")
108
warning(e.identifier, "device(%s) failed: %s", file, e.message)
119
end
10+
i = [];
1211
end
1312

1413
i = uint64(i);

+stdlib/+python/inode.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
function i = inode(p)
22

3-
i = 0;
4-
53
try
64
i = int64(py.os.stat(p).st_ino);
75
% int64 first is for Matlab <= R2022a
86
catch e
97
if ~contains(e.message, "FileNotFoundError")
108
warning(e.identifier, "inode(%s) failed: %s", p, e.message)
119
end
10+
i = [];
1211
end
1312

1413
i = uint64(i);

+stdlib/+python/is_mount.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
function y = is_mount(filepath)
66

7+
y = logical.empty;
8+
if ~stdlib.exists(filepath), return, end
9+
710
% some Python on CI needs this. Didn't replicate on local Windows PC.
811
if ispc() && strcmp(filepath, stdlib.root_name(filepath)) && ~endsWith(filepath, ["/", "\"])
912
y = false;
@@ -12,9 +15,6 @@
1215

1316
try
1417
y = py.os.path.ismount(filepath);
15-
catch e
16-
warning(e.identifier, "Python is_mount failed: %s", e.message);
17-
y = false;
1818
end
1919

2020
end

+stdlib/+python/private/disk_usage.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
case 'free', i = u.free;
88
otherwise, error('stdlib:python:disk_usage:valueError', 'unknown disk_usage property %s', v)
99
end
10-
10+
1111
i = int64(i);
1212
% int64 first is for Matlab <= R2022a
1313
catch
14-
i = 0;
14+
i = [];
1515
end
1616

1717
i = uint64(i);
18-
end
18+
end

0 commit comments

Comments
 (0)