Skip to content

Commit

Permalink
remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed May 11, 2023
1 parent 993a54f commit 9b8a868
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 30 deletions.
10 changes: 4 additions & 6 deletions +stdlib/+fileio/md5sum.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
file (1,1) string {mustBeFile}
end

file = stdlib.fileio.expanduser(file);

if ismac
[stat,hash] = system("md5 -r " + file);
[stat, hash] = system("md5 -r " + file);
elseif isunix
[stat,hash] = system("md5sum " + file);
[stat, hash] = system("md5sum " + file);
elseif ispc
[stat,hash] = system("CertUtil -hashfile " + file + " MD5");
[stat, hash] = system("CertUtil -hashfile " + file + " MD5");
else
error("no sha256sum method for your OS")
end

assert(stat == 0, hash)
assert(stat == 0, hash, "failed to compute md5sum of " + file)

hash = regexp(hash,'^\w{32}','match','once','lineanchors');
hash = string(hash);
Expand Down
12 changes: 5 additions & 7 deletions +stdlib/+fileio/sha256sum.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
file (1,1) string {mustBeFile}
end

file = stdlib.fileio.expanduser(file);

if ismac
[stat,hash] = system("shasum --algorithm 256 --binary " + file);
[stat, hash] = system("shasum --algorithm 256 --binary " + file);
elseif isunix
[stat,hash] = system("sha256sum --binary " + file);
[stat, hash] = system("sha256sum --binary " + file);
elseif ispc
[stat,hash] = system("CertUtil -hashfile " + file + " SHA256");
[stat, hash] = system("CertUtil -hashfile " + file + " SHA256");
else
error("no md5sum method for your OS")
error("no sha256sum method for your OS")
end

assert(stat == 0, hash)
assert(stat == 0, hash, "failed to compute SHA256 hash of " + file)

hash = regexp(hash,'^\w{64}','match','once','lineanchors');
hash = string(hash);
Expand Down
2 changes: 1 addition & 1 deletion +stdlib/+hdf5nc/h5ndims.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
return
end

dsi = h5info(stdlib.fileio.expanduser(file), variable).Dataspace;
dsi = h5info(file, variable).Dataspace;
if dsi.Type == "scalar"
frank = 0;
else
Expand Down
2 changes: 1 addition & 1 deletion +stdlib/+hdf5nc/h5size.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
variable (1,1) string {mustBeNonzeroLengthText}
end

dsi = h5info(stdlib.fileio.expanduser(file), variable).Dataspace;
dsi = h5info(file, variable).Dataspace;
if dsi.Type == "scalar"
fsize = [];
else
Expand Down
4 changes: 2 additions & 2 deletions +stdlib/+hdf5nc/h5variables.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
names = string.empty;

if isempty(group) || strlength(group) == 0
finf = h5info(stdlib.fileio.expanduser(file));
finf = h5info(file);
else
finf = h5info(stdlib.fileio.expanduser(file), group);
finf = h5info(file, group);
end

ds = finf.Datasets;
Expand Down
2 changes: 1 addition & 1 deletion +stdlib/+hdf5nc/ncndims.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
return
end

dsi = ncinfo(stdlib.fileio.expanduser(file), variable);
dsi = ncinfo(file, variable);
if isempty(dsi.Dimensions)
frank = 0;
else
Expand Down
2 changes: 1 addition & 1 deletion +stdlib/+hdf5nc/ncsize.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
variable (1,1) string {mustBeNonzeroLengthText}
end

dsi = ncinfo(stdlib.fileio.expanduser(file), variable);
dsi = ncinfo(file, variable);
if isempty(dsi.Dimensions)
fsize = [];
else
Expand Down
4 changes: 2 additions & 2 deletions +stdlib/+hdf5nc/ncvariables.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
names = string.empty;

if isempty(group) || strlength(group) == 0
finf = ncinfo(stdlib.fileio.expanduser(file));
finf = ncinfo(file);
else
finf = ncinfo(stdlib.fileio.expanduser(file), group);
finf = ncinfo(file, group);
end

ds = finf.Variables(:);
Expand Down
8 changes: 2 additions & 6 deletions +stdlib/+sys/diskfree.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
function freebytes = diskfree(direc)
%% diskfree(direc)
% returns disk free space in bytes
% example: diskfree('~')
% example: diskfree('/')
arguments
direc (1,1) string
direc (1,1) string {mustBeFolder}
end

direc = stdlib.fileio.expanduser(direc);

assert(isfolder(direc), '%s is not a folder', direc)

freebytes = java.io.File(direc).getUsableSpace;

end
4 changes: 2 additions & 2 deletions +stdlib/+test/TestIntg.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function test_checkRAM(tc)
function test_diskfree(tc)
tc.assumeTrue(usejava("jvm"), "Java required for path_tail")

tc.assertTrue(isnumeric(stdlib.sys.diskfree('~')))
tc.assertTrue(stdlib.sys.diskfree('~') > 0, 'diskfree')
tc.assertTrue(isnumeric(stdlib.sys.diskfree('/')))
tc.assertTrue(stdlib.sys.diskfree('/') > 0, 'diskfree')
end

function test_memory(tc)
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Matlab standard library
# Standard library for Matlab

[![DOI](https://zenodo.org/badge/273830124.svg)](https://zenodo.org/badge/latestdoi/273830124)
[![View matlab-hdf5 on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/78673-matlab-hdf5)
Expand Down

0 comments on commit 9b8a868

Please sign in to comment.