Skip to content

Commit f275833

Browse files
committed
[GR-13570] [GH-50] Provide inode IDs for files.
PullRequest: graalpython/385
2 parents a889a52 + deb4dbc commit f275833

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,17 @@ Object stat(String path, boolean followSymlinks) {
503503
} catch (IOException e) {
504504
size = 0;
505505
}
506+
TruffleFile canonical;
507+
try {
508+
canonical = f.getCanonicalFile();
509+
} catch (IOException | SecurityException e) {
510+
// best effort
511+
canonical = f.getAbsoluteFile();
512+
}
513+
int inode = getContext().getResources().getInodeId(canonical.getPath());
506514
return factory().createTuple(new Object[]{
507515
mode,
508-
0, // ino
516+
inode, // ino
509517
0, // dev
510518
0, // nlink
511519
uid,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixResources.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -46,7 +46,9 @@
4646
import java.nio.channels.Pipe;
4747
import java.util.ArrayList;
4848
import java.util.Collections;
49+
import java.util.HashMap;
4950
import java.util.List;
51+
import java.util.Map;
5052

5153
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5254
import com.oracle.truffle.api.TruffleFile;
@@ -65,6 +67,8 @@ public class PosixResources {
6567
private final List<Channel> files;
6668
private final List<String> filePaths;
6769
private final List<Process> children;
70+
private final Map<String, Integer> inodes;
71+
private int inodeCnt = 0;
6872

6973
public PosixResources() {
7074
files = Collections.synchronizedList(new ArrayList<>());
@@ -82,6 +86,7 @@ public PosixResources() {
8286
files.add(null);
8387
files.add(null);
8488
files.add(null);
89+
inodes = new HashMap<>();
8590
}
8691

8792
@TruffleBoundary(allowInlining = true)
@@ -198,4 +203,18 @@ public int waitpid(int pid) throws ArrayIndexOutOfBoundsException, InterruptedEx
198203
children.set(pid, null);
199204
return exitStatus;
200205
}
206+
207+
@TruffleBoundary(allowInlining = true)
208+
public int getInodeId(String canonical) {
209+
synchronized (inodes) {
210+
int inodeId;
211+
if (!inodes.containsKey(canonical)) {
212+
inodeId = inodeCnt++;
213+
inodes.put(canonical, inodeId);
214+
} else {
215+
inodeId = inodes.get(canonical);
216+
}
217+
return inodeId;
218+
}
219+
}
201220
}

0 commit comments

Comments
 (0)