Skip to content

Commit f6808cb

Browse files
committed
use java if available
1 parent 103ee41 commit f6808cb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

+stdlib/samepath.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
%% SAMEPATH is path the same
2+
% optional: java
23
%
34
% true if inputs resolve to same path.
45
% Both paths must exist.
@@ -16,9 +17,6 @@
1617
path2 {mustBeTextScalar}
1718
end
1819

19-
% simpler our way than
20-
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#isSameFile(java.nio.file.Path,java.nio.file.Path)
21-
2220
y = stdlib.exists(path1) && stdlib.exists(path2);
2321

2422
if ~y, return; end
@@ -30,8 +28,15 @@
3028
y = e1 == 0 && e2 == 0 && ...
3129
r1.ino == r2.ino && r1.dev == r2.dev;
3230

31+
elseif stdlib.has_java()
32+
% https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/nio/file/Files.html#isSameFile(java.nio.file.Path,java.nio.file.Path)
33+
34+
y = java.nio.file.Files.isSameFile(javaPathObject(path1), javaPathObject(path2));
35+
3336
else
37+
3438
y = strcmp(stdlib.canonical(path1), stdlib.canonical(path2));
39+
3540
end
3641

3742
%!assert(samepath(".", "."))

0 commit comments

Comments
 (0)