Skip to content

Commit 5cdb414

Browse files
committed
homedir,absolute_path: require Java
1 parent 7178b53 commit 5cdb414

File tree

7 files changed

+14
-44
lines changed

7 files changed

+14
-44
lines changed

+stdlib/+fileio/absolute_path.m

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@
2525
% REQUIRES path to exist, while java method does not.
2626
% abspath = builtin('_canonicalizepath', abspath);
2727

28-
try
29-
abspath = string(java.io.File(abspath).getCanonicalPath());
30-
catch excp
31-
if excp.identifier == "MATLAB:undefinedVarOrClass"
32-
% Java is not available, so return unmodified path
33-
return
34-
else
35-
error("stdlib:fileio:absolute_path", "%s is not a canonicalizable path. %s", abspath, excp.message)
36-
end
37-
end
28+
abspath = string(java.io.File(abspath).getCanonicalPath());
3829

3930
end % function

+stdlib/+fileio/extract_zstd.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ function extract_zstd(archive, out_dir)
22

33
arguments
44
archive (1,1) string {mustBeFile}
5-
out_dir (1,1) string
5+
out_dir (1,1) string {mustBeFolder}
66
end
77

88
archive = stdlib.fileio.absolute_path(archive);
99
out_dir = stdlib.fileio.absolute_path(out_dir);
1010

11-
assert(isfolder(out_dir), "%s is not a folder", out_dir)
12-
1311
exe = stdlib.fileio.which("cmake");
1412
if isempty(exe)
1513
extract_zstd_bin(archive, outdir)

+stdlib/+fileio/homedir.m

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,8 @@
77
return
88
end
99

10-
try
11-
home = string(java.lang.System.getProperty("user.home"));
12-
catch excp
13-
% if Java not available use env vars, else error
14-
if excp.identifier ~= "MATLAB:undefinedVarOrClass"
15-
error("stdlib:fileio:homedir", excp.message)
16-
end
17-
18-
if ispc
19-
home = getenv('USERPROFILE');
20-
else
21-
home = getenv('HOME');
22-
end
23-
end
10+
home = string(java.lang.System.getProperty("user.home"));
2411

2512
h = home;
2613

27-
end
14+
end

+stdlib/+fileio/is_absolute_path.m

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
function isabs = is_absolute_path(apath)
22

33
arguments
4-
apath string
4+
apath string {mustBeScalarOrEmpty}
55
end
66

7-
% leave expanduser() here to work like C++ filesystem::path::is_absolute()
8-
apath = stdlib.fileio.expanduser(apath);
9-
10-
if ispc
11-
i = strlength(apath) < 3;
12-
isabs(i) = false;
13-
14-
hasDrive = cell2mat(isstrprop(extractBefore(apath(~i), 2), "alpha", "ForceCellOutput", true));
15-
isabs(~i) = hasDrive & extractBetween(apath(~i), 2,2) == ":" & ...
16-
(extractBetween(apath(~i), 3,3) == "/" | extractBetween(apath(~i), 3,3) == "\");
17-
else
18-
isabs = startsWith(apath, "/");
7+
if isempty(apath)
8+
isabs = logical.empty();
9+
return
1910
end
2011

12+
% expanduser() here to work like C++ filesystem::path::is_absolute()
13+
isabs = java.io.File(stdlib.fileio.expanduser(apath)).isAbsolute();
14+
2115
end

+stdlib/+fileio/makedir.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ function makedir(direc)
1313

1414
mkdir(direc);
1515

16-
assert(isfolder(direc), "stdlib:fileio:makedir:IOError", 'not a directory %s', direc)
16+
mustBeFolder(direc)
1717

1818
end

+stdlib/+sys/subprocess_run.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
end
1616

1717
if ~isempty(opt.cwd)
18+
mustBeFolder(opt.cwd)
1819
cwd = stdlib.fileio.absolute_path(opt.cwd);
19-
assert(isfolder(cwd), "subprocess_run: %s is not a folder", cwd)
2020
oldcwd = pwd;
2121
cd(cwd)
2222
end

+stdlib/is_absolute_path.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
% os.path.isabs("/foo/../bar") == True
77

88
arguments
9-
apath string
9+
apath string {mustBeScalarOrEmpty}
1010
end
1111

1212
isabs = stdlib.fileio.is_absolute_path(apath);

0 commit comments

Comments
 (0)