30
30
import static com .oracle .graal .python .runtime .exception .PythonErrorType .OSError ;
31
31
import static com .oracle .graal .python .runtime .exception .PythonErrorType .TypeError ;
32
32
import static com .oracle .graal .python .runtime .exception .PythonErrorType .ValueError ;
33
- import static com .oracle .graal .python .util .TempFileUtils .getRandomFilePath ;
34
33
import static com .oracle .truffle .api .TruffleFile .CREATION_TIME ;
35
34
import static com .oracle .truffle .api .TruffleFile .IS_DIRECTORY ;
36
35
import static com .oracle .truffle .api .TruffleFile .IS_REGULAR_FILE ;
@@ -923,8 +922,6 @@ int dupOvf(PInt fd, PInt fd2) {
923
922
@ GenerateNodeFactory
924
923
@ TypeSystemReference (PythonArithmeticTypes .class )
925
924
public abstract static class OpenNode extends PythonFileNode {
926
- @ Child private SequenceStorageNodes .ToByteArrayNode toByteArrayNode ;
927
-
928
925
private final BranchProfile gotException = BranchProfile .create ();
929
926
930
927
@ Specialization (guards = {"isNoValue(mode)" , "isNoValue(dir_fd)" })
@@ -939,16 +936,17 @@ Object openMode(VirtualFrame frame, Object pathArg, int flags, int fileMode, @Su
939
936
String pathname = cast .execute (frame , pathArg );
940
937
Set <StandardOpenOption > options = flagsToOptions (flags );
941
938
FileAttribute <Set <PosixFilePermission >>[] attributes = modeToAttributes (fileMode );
942
- TruffleFile truffleFile ;
943
939
try {
944
940
SeekableByteChannel fc ;
941
+ TruffleFile truffleFile = getContext ().getPublicTruffleFileRelaxed (pathname , PythonLanguage .DEFAULT_PYTHON_EXTENSIONS );
945
942
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 ));
950
948
}
951
- truffleFile = getContext (). getPublicTruffleFileRelaxed ( pathname , PythonLanguage . DEFAULT_PYTHON_EXTENSIONS );
949
+
952
950
fc = truffleFile .newByteChannel (options , attributes );
953
951
return getResources ().open (truffleFile , fc );
954
952
} catch (NoSuchFileException e ) {
0 commit comments