Skip to content

Commit 1160051

Browse files
committed
GR-17515: switch to using TruffleFile tempFile API
1 parent 7b2ae14 commit 1160051

File tree

3 files changed

+10
-103
lines changed

3 files changed

+10
-103
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OSError;
3131
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
3232
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
33-
import static com.oracle.graal.python.util.TempFileUtils.getRandomFilePath;
3433
import static com.oracle.truffle.api.TruffleFile.CREATION_TIME;
3534
import static com.oracle.truffle.api.TruffleFile.IS_DIRECTORY;
3635
import static com.oracle.truffle.api.TruffleFile.IS_REGULAR_FILE;
@@ -923,8 +922,6 @@ int dupOvf(PInt fd, PInt fd2) {
923922
@GenerateNodeFactory
924923
@TypeSystemReference(PythonArithmeticTypes.class)
925924
public abstract static class OpenNode extends PythonFileNode {
926-
@Child private SequenceStorageNodes.ToByteArrayNode toByteArrayNode;
927-
928925
private final BranchProfile gotException = BranchProfile.create();
929926

930927
@Specialization(guards = {"isNoValue(mode)", "isNoValue(dir_fd)"})
@@ -939,16 +936,17 @@ Object openMode(VirtualFrame frame, Object pathArg, int flags, int fileMode, @Su
939936
String pathname = cast.execute(frame, pathArg);
940937
Set<StandardOpenOption> options = flagsToOptions(flags);
941938
FileAttribute<Set<PosixFilePermission>>[] attributes = modeToAttributes(fileMode);
942-
TruffleFile truffleFile;
943939
try {
944940
SeekableByteChannel fc;
941+
TruffleFile truffleFile = getContext().getPublicTruffleFileRelaxed(pathname, PythonLanguage.DEFAULT_PYTHON_EXTENSIONS);
945942
if (options.contains(StandardOpenOption.DELETE_ON_CLOSE)) {
946-
// TODO: (cbas) remove patch once the TruffleFile API supports temp file
947-
// creation -> GR-17515
948-
pathname = getRandomFilePath(pathname, options, getContext().getEnv());
949-
getContext().registerShutdownHook(new FileDeleteShutdownHook(pathname));
943+
truffleFile = getContext().getEnv().createTempFile(truffleFile, null, null);
944+
options.remove(StandardOpenOption.CREATE_NEW);
945+
options.remove(StandardOpenOption.DELETE_ON_CLOSE);
946+
options.add(StandardOpenOption.CREATE);
947+
getContext().registerShutdownHook(new FileDeleteShutdownHook(truffleFile));
950948
}
951-
truffleFile = getContext().getPublicTruffleFileRelaxed(pathname, PythonLanguage.DEFAULT_PYTHON_EXTENSIONS);
949+
952950
fc = truffleFile.newByteChannel(options, attributes);
953951
return getResources().open(truffleFile, fc);
954952
} catch (NoSuchFileException e) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/FileDeleteShutdownHook.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@
4646
import com.oracle.truffle.api.TruffleFile;
4747

4848
public class FileDeleteShutdownHook implements ShutdownHook {
49-
private final String path;
49+
private final TruffleFile truffleFile;
5050

51-
public FileDeleteShutdownHook(String path) {
52-
this.path = path;
51+
public FileDeleteShutdownHook(TruffleFile truffleFile) {
52+
this.truffleFile = truffleFile;
5353
}
5454

5555
@Override
5656
public void call(PythonContext context) {
57-
TruffleFile truffleFile = context.getEnv().getPublicTruffleFile(path);
5857
try {
5958
truffleFile.delete();
6059
} catch (IOException ignored) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/TempFileUtils.java

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)