Skip to content

Commit 8cc1c8f

Browse files
committed
apply argument validation for clarity
time penalty is miniscule
1 parent 3438444 commit 8cc1c8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+279
-91
lines changed

+stdlib/+dotnet/create_symlink.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
%% DOTNET.CREATE_SYMLINK create symbolic link to target
22

33
function ok = create_symlink(target, link)
4+
arguments
5+
target (1,1) string
6+
link (1,1) string
7+
end
48

59
ok = false;
610

+stdlib/+dotnet/disk_available.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
%% DOTNET.DISK_AVAILABLE find the disk space available to the user
22

3-
function f = disk_available(p)
3+
function f = disk_available(file)
4+
arguments
5+
file (1,1) string
6+
end
47

58
f = uint64([]);
69

7-
if ~stdlib.exists(p), return, end
10+
if ~stdlib.exists(file), return, end
811

9-
f = uint64(System.IO.DriveInfo(stdlib.absolute(p)).AvailableFreeSpace());
12+
f = uint64(System.IO.DriveInfo(stdlib.absolute(file)).AvailableFreeSpace());
1013
% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.availablefreespace
1114
end

+stdlib/+dotnet/disk_capacity.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
%% DOTNET.DISK_CAPACITY find the overall disk capacity visible to user
22

3-
function f = disk_capacity(d)
3+
function f = disk_capacity(file)
4+
arguments
5+
file (1,1) string
6+
end
47

58
f = uint64([]);
69

7-
if ~stdlib.exists(d), return, end
10+
if ~stdlib.exists(file), return, end
811

9-
f = uint64(System.IO.DriveInfo(stdlib.absolute(d)).TotalSize());
12+
f = uint64(System.IO.DriveInfo(stdlib.absolute(file)).TotalSize());
1013
% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.totalsize
1114

1215
end

+stdlib/+dotnet/file_checksum.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
% Ref: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/security/MessageDigest.html#getInstance(java.lang.String)
44

55
function hash = file_checksum(file, hash_method)
6+
arguments
7+
file (1,1) string
8+
hash_method (1,1) string
9+
end
610

711
if any(strcmp(hash_method, {'sha256', 'SHA256'}))
812
hash_method = "SHA-256";

+stdlib/+dotnet/filesystem_type.m

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

33
function t = filesystem_type(file)
4+
arguments
5+
file (1,1) string
6+
end
47

58
if stdlib.exists(file)
69
t = char(System.IO.DriveInfo(stdlib.absolute(file)).DriveFormat);

+stdlib/+dotnet/get_owner.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
%% DOTNET.GET_OWNER get the owner of a filepath
22

3-
function o = get_owner(p)
3+
function o = get_owner(file)
4+
arguments
5+
file (1,1) string
6+
end
47

58
% This is not yet possible with .NET on Unix, even with .NET 10.
69
% It would require Pinvoke or external Mono.Unix
@@ -12,10 +15,10 @@
1215
return
1316
end
1417

15-
if isfolder(p)
16-
fsec = System.IO.Directory.GetAccessControl(p);
17-
elseif isfile(p)
18-
fsec = System.IO.File.GetAccessControl(p);
18+
if isfolder(file)
19+
fsec = System.IO.Directory.GetAccessControl(file);
20+
elseif isfile(file)
21+
fsec = System.IO.File.GetAccessControl(file);
1922
else
2023
o = "";
2124
return

+stdlib/+dotnet/is_removable.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
% Ref: https://learn.microsoft.com/en-us/dotnet/api/system.io.drivetype
44

55
function y = is_removable(filepath)
6+
arguments
7+
filepath (1,1) string
8+
end
69

710
if stdlib.exists(filepath)
811
fmt = System.IO.DriveInfo(stdlib.absolute(filepath)).DriveType;

+stdlib/+dotnet/is_symlink.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
%% DOTNET.IS_SYMLINK check if a file is a symbolic link
22

3-
function y = is_symlink(p)
3+
function y = is_symlink(file)
4+
arguments
5+
file (1,1) string
6+
end
47

58
try
69
if stdlib.dotnet_api() >= 6
7-
y = ~isempty(System.IO.FileInfo(p).LinkTarget);
10+
y = ~isempty(System.IO.FileInfo(file).LinkTarget);
811
else
9-
attr = string(System.IO.File.GetAttributes(p).ToString());
12+
attr = string(System.IO.File.GetAttributes(file).ToString());
1013
% https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributes
1114
% ReparsePoint is for Linux, macOS, and Windows
1215
y = contains(attr, 'ReparsePoint');

+stdlib/+dotnet/read_symlink.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
%% DOTNET.READ_SYMLINK resolve the symbolic links of a filepath
22

33
function r = read_symlink(file)
4+
arguments
5+
file (1,1) string
6+
end
47

58
try
69
h = System.IO.FileInfo(file);

+stdlib/+java/device.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
function i = device(file)
2+
arguments
3+
file (1,1) string
4+
end
25

36
i = uint64([]);
47
if ~stdlib.exists(file), return, end

0 commit comments

Comments
 (0)