Skip to content

Commit ea3ee80

Browse files
committed
hash: empty if not exist file
1 parent b58c0d4 commit ea3ee80

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

+stdlib/file_checksum.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
method (1,1) string
1616
end
1717

18-
assert(~stdlib.is_url(file), "file_checksum does not accept URLs")
18+
hash = [];
19+
20+
if stdlib.is_url(file), return, end
1921

2022
if strcmp(method, "sha256") || strcmp(method, "SHA256")
2123
method = "SHA-256";
@@ -30,7 +32,7 @@
3032
end
3133

3234
fid = fopen(file, 'r');
33-
assert(fid > 0, "could not open file %s", file)
35+
if fid < 1, return, end
3436

3537
while ~feof(fid)
3638
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/security/MessageDigest.html#update(byte)

test/TestHash.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ function test_hash_text(tc)
6565

6666
end
6767

68+
69+
function test_hash_empty(tc)
70+
71+
tc.verifyEmpty(stdlib.file_checksum("file:///", "sha256"))
72+
tc.verifyEmpty(stdlib.file_checksum("", "sha256"))
73+
74+
end
75+
6876
end
6977

7078
end

0 commit comments

Comments
 (0)