Skip to content

Commit 6d0b245

Browse files
committed
Fake inode IDs for files.
1 parent c88ed96 commit 6d0b245

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-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
@@ -513,9 +513,17 @@ Object stat(String path, boolean followSymlinks) {
513513
} catch (IOException e) {
514514
size = 0;
515515
}
516+
TruffleFile canonical;
517+
try {
518+
canonical = f.getCanonicalFile();
519+
} catch (IOException e) {
520+
// best effort
521+
canonical = f.getAbsoluteFile();
522+
}
523+
int inode = getContext().getResources().getInodeId(canonical.getPath());
516524
return factory().createTuple(new Object[]{
517525
mode,
518-
0, // ino
526+
inode, // ino
519527
0, // dev
520528
0, // nlink
521529
uid,

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

Lines changed: 18 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
@@ -47,6 +47,8 @@
4747
import java.util.ArrayList;
4848
import java.util.Collections;
4949
import java.util.List;
50+
import java.util.Map;
51+
import java.util.concurrent.ConcurrentHashMap;
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 ConcurrentHashMap<>();
8590
}
8691

8792
@TruffleBoundary(allowInlining = true)
@@ -198,4 +203,16 @@ 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+
int inodeId;
210+
if (!inodes.containsKey(canonical)) {
211+
inodeId = inodeCnt++;
212+
inodes.put(canonical, inodeId);
213+
} else {
214+
inodeId = inodes.get(canonical);
215+
}
216+
return inodeId;
217+
}
201218
}

0 commit comments

Comments
 (0)