Skip to content

Commit df610b2

Browse files
committed
test:hard_link_count: python fallback
1 parent 85e69f7 commit df610b2

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

+stdlib/hard_link_count.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%% HARD_LINK_COUNT get the number of hard links to a file
2-
% requires: java
2+
%
33
%
44
% Ref:
55
% * https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#getPosixFileAttributes(java.nio.file.Path,java.nio.file.LinkOption...)
@@ -12,12 +12,14 @@
1212

1313
c = [];
1414

15-
if stdlib.isoctave()
15+
if stdlib.has_python()
16+
c = uint64(py.pathlib.Path(p).stat().st_nlink);
17+
elseif stdlib.isoctave()
1618
[s, err] = stat(p);
1719
if err == 0
1820
c = s.nlink;
1921
end
20-
elseif isunix()
22+
elseif isunix() && stdlib.has_java()
2123
opt = javaMethod("values", "java.nio.file.LinkOption");
2224
c = java.nio.file.Files.getAttribute(javaPathObject(p), "unix:nlink", opt);
2325
end

+stdlib/inode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%% INODE filesystem inode of path
2-
% requires: java
2+
%
33
% Windows always returns 0, Unix returns inode number.
44

55
function i = inode(path)

test/TestDisk.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ function test_disk_capacity(tc, Ps)
3434
end
3535

3636

37+
function test_hard_link_count(tc)
38+
tc.assumeTrue(stdlib.has_python() || (isunix() && stdlib.has_java()))
39+
fn = mfilename("fullpath") + ".m";
40+
41+
tc.verifyGreaterThanOrEqual(stdlib.hard_link_count(fn), 1)
42+
end
43+
44+
3745
function test_filesystem_type(tc, Ps)
3846

3947
tc.assumeTrue(stdlib.has_dotnet() || stdlib.has_java())

test/TestJava.m

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@ function test_java_api(tc)
2121
end
2222

2323

24-
function test_hard_link_count(tc)
25-
fn = mfilename("fullpath") + ".m";
26-
27-
if ispc
28-
tc.verifyEmpty(stdlib.hard_link_count(fn))
29-
else
30-
tc.verifyGreaterThanOrEqual(stdlib.hard_link_count(fn), 1)
31-
end
32-
end
33-
34-
3524
function test_cpu_load(tc)
3625
tc.verifyGreaterThanOrEqual(stdlib.cpu_load(), 0)
3726
end

0 commit comments

Comments
 (0)