Skip to content

Commit 4594dad

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

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

+stdlib/inode.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
if stdlib.exists(path)
11+
i = java.nio.file.Files.getAttribute(javaPathObject(path), "unix:ino", javaLinkOption());
12+
else
13+
i = [];
14+
end
15+
16+
end

test/TestFileImpure.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
p_same = {...
77
{"","", false}, ...
8-
{tempname(), tempname(), false}, ...
98
{"..", "./..", true}, ...
109
{"..", pwd() + "/..", true}}
1110

@@ -44,12 +43,24 @@ function test_makedir(tc)
4443
rmdir(d)
4544
end
4645

46+
function test_inode(tc)
47+
tc.assumeFalse(ispc(), "not for Windows")
48+
49+
tc.verifyEqual(stdlib.inode("."), stdlib.inode(pwd()))
50+
tc.verifyEmpty(stdlib.inode(tempname))
51+
end
52+
4753
%%
4854
function test_samepath(tc, p_same)
4955
tc.verifyEqual(stdlib.samepath(p_same{1}, p_same{2}), p_same{3}, ...
5056
"samepath(" + p_same{1} + "," + p_same{2} + ")")
5157
end
5258

59+
function test_samepath_notexist(tc)
60+
t = tempname();
61+
tc.verifyFalse(stdlib.samepath(t, t))
62+
end
63+
5364

5465
function test_get_pid(tc)
5566
pid = stdlib.get_pid();

0 commit comments

Comments
 (0)