1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
46
46
import java .nio .channels .Pipe ;
47
47
import java .util .ArrayList ;
48
48
import java .util .Collections ;
49
+ import java .util .HashMap ;
49
50
import java .util .List ;
51
+ import java .util .Map ;
50
52
51
53
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
52
54
import com .oracle .truffle .api .TruffleFile ;
@@ -65,6 +67,8 @@ public class PosixResources {
65
67
private final List <Channel > files ;
66
68
private final List <String > filePaths ;
67
69
private final List <Process > children ;
70
+ private final Map <String , Integer > inodes ;
71
+ private int inodeCnt = 0 ;
68
72
69
73
public PosixResources () {
70
74
files = Collections .synchronizedList (new ArrayList <>());
@@ -82,6 +86,7 @@ public PosixResources() {
82
86
files .add (null );
83
87
files .add (null );
84
88
files .add (null );
89
+ inodes = new HashMap <>();
85
90
}
86
91
87
92
@ TruffleBoundary (allowInlining = true )
@@ -198,4 +203,18 @@ public int waitpid(int pid) throws ArrayIndexOutOfBoundsException, InterruptedEx
198
203
children .set (pid , null );
199
204
return exitStatus ;
200
205
}
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
+ }
201
220
}
0 commit comments