Skip to content

Commit 1e2c7bd

Browse files
committed
add inode(). improve samepath test
1 parent f6808cb commit 1e2c7bd

File tree

5 files changed

+80
-7
lines changed

5 files changed

+80
-7
lines changed

+stdlib/device.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
%% DEVICE filesystem device index of path
2+
% requires: java
3+
% Windows always returns 0, Unix returns device number.
4+
5+
function i = device(path)
6+
arguments
7+
path {mustBeTextScalar}
8+
end
9+
10+
if stdlib.exists(path)
11+
if stdlib.isoctave()
12+
[s, err] = stat(path);
13+
if err == 0
14+
i = s.dev;
15+
end
16+
else
17+
i = java.nio.file.Files.getAttribute(javaPathObject(path), "unix:dev", javaLinkOption());
18+
end
19+
else
20+
i = [];
21+
end
22+
23+
end

+stdlib/inode.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
%% INODE filesystem inode of path
2+
% requires: java
3+
% Windows always returns 0, Unix returns inode number.
4+
5+
function i = inode(path)
6+
arguments
7+
path {mustBeTextScalar}
8+
end
9+
10+
i = [];
11+
12+
if stdlib.exists(path)
13+
if stdlib.isoctave()
14+
[s, err] = stat(path);
15+
if err == 0
16+
i = s.ino;
17+
end
18+
else
19+
i = java.nio.file.Files.getAttribute(javaPathObject(path), "unix:ino", javaLinkOption());
20+
end
21+
else
22+
i = [];
23+
end
24+
25+
end

Readme_java.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Get the Java version:
3636
stdlib.java_version()
3737
```
3838

39-
From before Matlab R2019b to at least Matlab R2024b, the Matlab factory Java version is 1.8, which is adequate for all Matlab-stdlib functionality.
39+
From before Matlab R2019b to at least Matlab R2025a, the Matlab factory Java version is 1.8, which is adequate for all Matlab-stdlib functionality.
4040

4141
If desired (not used by Matlab-stdlib), one can use non-factory Java classes in
4242
[Matlab](](https://www.mathworks.com/help/matlab/matlab_external/static-path-of-java-class-path.html))
@@ -74,6 +74,12 @@ Tell Matlab to use this JDK from the Matlab console by:
7474
jenv("/path/to/jdk-17/Contents/Home")
7575
```
7676

77+
Or for the Amazon Corretto JDK 11 on macOS:
78+
79+
```matlab
80+
jenv("/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home/")
81+
```
82+
7783
To
7884
[revert back to the factory JRE](https://www.mathworks.com/help/matlab/ref/matlab_jenv.html)
7985
if Matlab can't start or has problems, from system Terminal (not within Matlab):

test/TestFileImpure.m

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
p_is_writable = {{pwd(), true}, {"not-exists", false}, {"", false}};
55

66
p_same = {...
7-
{"","", false}, ...
8-
{tempname(), tempname(), false}, ...
9-
{"..", "./..", true}, ...
10-
{"..", pwd() + "/..", true}}
7+
{"..", "./.."}, ...
8+
{"..", pwd() + "/.."}}
119

1210
ph = {{0, '"stdin"'}, {1, '"stdout"'}, {2, '"stderr"'}, {fopen(tempname()), ''}}
1311

@@ -46,8 +44,13 @@ function test_makedir(tc)
4644

4745
%%
4846
function test_samepath(tc, p_same)
49-
tc.verifyEqual(stdlib.samepath(p_same{1}, p_same{2}), p_same{3}, ...
50-
"samepath(" + p_same{1} + "," + p_same{2} + ")")
47+
tc.verifyTrue(stdlib.samepath(p_same{1}, p_same{2}))
48+
end
49+
50+
function test_samepath_notexist(tc)
51+
tc.verifyFalse(stdlib.samepath("", ""))
52+
t = tempname();
53+
tc.verifyFalse(stdlib.samepath(t, t))
5154
end
5255

5356

test/TestJava.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ function java_required(tc)
1313

1414
methods(Test)
1515

16+
function test_inode(tc)
17+
tc.assumeFalse(ispc(), "not for Windows")
18+
19+
tc.verifyEqual(stdlib.inode("."), stdlib.inode(pwd()))
20+
tc.verifyEmpty(stdlib.inode(tempname))
21+
end
22+
23+
24+
function test_device(tc)
25+
tc.assumeFalse(ispc(), "not for Windows")
26+
27+
tc.verifyEqual(stdlib.device("."), stdlib.device(pwd()))
28+
tc.verifyEmpty(stdlib.device(tempname))
29+
end
30+
31+
1632
function test_filesystem_type(tc, Ps)
1733

1834
s = stdlib.filesystem_type(Ps);

0 commit comments

Comments
 (0)