Skip to content

Commit 2fc520c

Browse files
committed
python: more robust
1 parent 2371135 commit 2fc520c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

+stdlib/+python/is_mount.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
% https://docs.python.org/3/library/os.path.html#os.path.ismount
44

55
function y = is_mount(filepath)
6-
arguments
7-
filepath (1,1) string
8-
end
96

107
y = logical.empty;
11-
if ~stdlib.exists(filepath), return, end
8+
9+
p = py.pathlib.Path(filepath);
10+
if ~p.exists(), return, end
1211

1312
% some Python on CI needs this. Didn't replicate on local Windows PC.
14-
if ispc() && strcmp(filepath, stdlib.root_name(filepath)) && ~endsWith(filepath, "/" | filesep)
13+
if ispc() && strcmp(filepath, string(p.drive)) && ~endsWith(filepath, "/" | filesep)
1514
y = false;
1615
return
1716
end
1817

1918
try %#ok<TRYNC>
20-
y = py.os.path.ismount(filepath);
19+
y = py.os.path.ismount(p);
2120
end
2221

2322
end

+stdlib/+python/read_symlink.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
function r = read_symlink(file)
2-
arguments
3-
file (1,1) string
4-
end
52

63
r = "";
74

8-
if ~stdlib.is_symlink(file), return, end
5+
p = py.pathlib.Path(file);
6+
if ~p.is_symlink(), return, end
97

108
% https://docs.python.org/3/library/pathlib.html#pathlib.Path.readlink
119
try
12-
r = string(py.os.readlink(file));
10+
r = string(py.str(p.readlink()));
1311
if ispc() && startsWith(r, '\\?\')
1412
r = extractAfter(r, '\\?\');
1513
end

0 commit comments

Comments
 (0)