Skip to content

Commit efbb1df

Browse files
committed
inode shell fallback
1 parent 3974447 commit efbb1df

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

+stdlib/+python/inode.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function i = inode(p)
2+
3+
try
4+
i = uint64(int64(py.os.stat(p).st_ino));
5+
% int64 first is for Matlab <= R2022a
6+
catch e
7+
warning(e.identifier, "%s", e.message)
8+
i = [];
9+
end

+stdlib/+sys/device.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
function i = device(p)
22

3+
i = [];
34

45
if ispc()
5-
cmd = "powershell -Command (Get-CimInstance -ClassName Win32_Volume -Filter 'DriveLetter = \"" + p(1) + "\"').DeviceID";
6+
c0 = 'powershell -Command "(Get-CimInstance -ClassName Win32_Volume -Filter \"DriveLetter = ''';
7+
c1 = stdlib.root_name(stdlib.resolve(p));
8+
c2 = '''\").SerialNumber"';
9+
cmd = strcat(c0, c1, c2);
610
elseif ismac()
711
cmd = "stat -f %d " + p;
8-
elseif isunix()
12+
else
913
cmd = "stat -c %d " + p;
1014
end
1115

@@ -15,4 +19,6 @@
1519
i = str2double(m);
1620
end
1721

22+
i = uint64(i);
23+
1824
end

+stdlib/+sys/inode.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function i = inode(m)
2+
3+
i = [];
4+
5+
if ispc()
6+
cmd = "fsutil file queryfileid " + m;
7+
elseif ismac()
8+
cmd = "stat -f %i " + m;
9+
else
10+
cmd = "stat -c %i " + m;
11+
end
12+
13+
[s, m] = system(cmd);
14+
if s == 0
15+
i = str2double(m);
16+
end
17+
18+
i = uint64(i);
19+
20+
end

+stdlib/inode.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
i = [];
1111

1212
if stdlib.has_python()
13-
i = uint64(int64(py.os.stat(p).st_ino)); % int64 first is for Matlab <= R2022a
13+
i = stdlib.python.inode(p);
1414
elseif isunix() && stdlib.java_api() >= 11
1515
% Java 1.8 is buggy in some corner cases, so we require at least 11.
1616
opt = javaMethod("values", "java.nio.file.LinkOption");
1717
i = javaMethod("getAttribute", "java.nio.file.Files", javaPathObject(p), "unix:ino", opt);
18-
elseif stdlib.isoctave()
19-
[s, err] = stat(p);
20-
if err == 0
21-
i = s.ino;
22-
end
18+
end
19+
20+
if isempty(i)
21+
i = stdlib.sys.inode(m);
2322
end
2423

2524
end

0 commit comments

Comments
 (0)