Skip to content

Commit 00b08e9

Browse files
committed
dedupe
1 parent 19585a4 commit 00b08e9

35 files changed

+113
-120
lines changed

+stdlib/+dotnet/filesystem_type.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
%% DOTNET.FILESYSTEM_TYPE type of the partition e.g. NTFS, ext4, ...
22

3-
function t = filesystem_type(p)
3+
function t = filesystem_type(file)
44

5-
if stdlib.exists(p)
6-
t = char(System.IO.DriveInfo(stdlib.absolute(p)).DriveFormat);
5+
if stdlib.exists(file)
6+
t = char(System.IO.DriveInfo(stdlib.absolute(file)).DriveFormat);
77
% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.driveformat
88
else
99
t = '';

+stdlib/+java/device.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
function i = device(p)
1+
function i = device(file)
22

33
opt = javaMethod("values", "java.nio.file.LinkOption");
4-
i = uint64(javaMethod("getAttribute", "java.nio.file.Files", javaPathObject(p), "unix:dev", opt));
4+
p = javaPathObject(file);
5+
i = java.nio.file.Files.getAttribute(p, "unix:dev", opt);
56

7+
i = uint64(i);
68
end

+stdlib/+java/disk_available.m

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

3-
f = uint64(javaObject("java.io.File", d).getUsableSpace());
3+
i = java.io.File(file).getUsableSpace();
44

5+
i = uint64(i);
56
end

+stdlib/+java/file_checksum.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
fid = fopen(file, 'r');
1313
assert(fid > 1, "could not open file %s", file)
1414

15-
inst = javaMethod("getInstance", "java.security.MessageDigest", hash_method);
15+
inst = java.security.MessageDigest.getInstance(hash_method);
1616
while ~feof(fid)
1717
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/security/MessageDigest.html#update(byte)
1818
inst.update(fread(fid, file_chunk, '*uint8'));

+stdlib/+java/filesystem_type.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
function t = filesystem_type(p)
1+
function t = filesystem_type(file)
22

3-
if stdlib.exists(p)
4-
t = char(javaMethod("getFileStore", "java.nio.file.Files", javaPathObject(p)).type);
3+
if stdlib.exists(file)
4+
t = char(java.nio.file.Files.getFileStore(javaPathObject(file)).type);
55
else
66
t = '';
77
end

+stdlib/+java/set_modtime.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
%% JAVA.SET_MODTIME set the modification time of a filepath
22

3-
function ok = set_modtime(p, t)
3+
function ok = set_modtime(file, t)
44

55
utc = convertTo(datetime(t, 'TimeZone', "UTC"), "posixtime");
66

7-
ok = javaObject("java.io.File", p).setLastModified(int64(utc) * 1000);
7+
ok = javaObject("java.io.File", file).setLastModified(int64(utc) * 1000);
88

99
end

+stdlib/+native/create_symlink.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
function ok = create_symlink(target, link)
22

3-
if stdlib.exists(target) && ~stdlib.exists(link)
3+
try
44
createSymbolicLink(link, target);
55
ok = true;
6-
else
7-
ok = false;
6+
catch e
7+
switch e.identifier
8+
case {'MATLAB:io:filesystem:symlink:FileExists', 'MATLAB:io:filesystem:symlink:TargetNotFound'}, ok = false;
9+
otherwise, rethrow(e)
10+
end
811
end
912

1013
end

+stdlib/+python/device.m

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

33
i = 0;
44

55
try
6-
i = int64(py.os.stat(p).st_dev);
6+
i = int64(py.os.stat(file).st_dev);
77
% int64 first is for Matlab <= R2022a
88
catch e
99
if ~contains(e.message, "FileNotFoundError")
10-
warning(e.identifier, "device(%s) failed: %s", p, e.message)
10+
warning(e.identifier, "device(%s) failed: %s", file, e.message)
1111
end
1212
end
1313

+stdlib/+python/disk_available.m

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

3-
f = uint64(0);
4-
5-
if ~stdlib.exists(p), return, end
6-
7-
try
8-
di = py.shutil.disk_usage(p);
9-
f = uint64(int64(di.free));
10-
% int64 first is for Matlab <= R2022a
11-
catch e
12-
warning(e.identifier, "disk_available(%s) failed: %s", p, e.message);
13-
end
3+
i = disk_usage(file, 'free');
144

155
end

+stdlib/+python/disk_capacity.m

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

3-
f = uint64(0);
4-
5-
if ~stdlib.exists(p), return, end
6-
7-
try
8-
di = py.shutil.disk_usage(p);
9-
f = int64(di.total);
10-
% int64 first is for Matlab <= R2022a
11-
catch e
12-
warning(e.identifier, "disk_capacity(%s) failed: %s", p, e.message);
13-
end
14-
15-
f = uint64(f);
3+
i = disk_usage(file, 'total');
164

175
end

0 commit comments

Comments
 (0)