You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds OS::get_temp_dir(), FileAccess::create_temp(), and DirAccess::create_temp() functions (the PR originally spelled tmp instead of temp), for all the supported platforms.
The concept of temporary files and directories
There's already OS.get_cache_dir(), why do we need temporary files?
Temporary files and cache files are really similar, but they are distinct.
Cache files
Temporary files
Can be deleted at any time by the user
✅
✅
Can be deleted at any time by the OS
❌
✅
Purpose
Persistent temporary files, usually can be expected to be there the next time, useful after creation.
Volatile temporary files, usually not needed after use.
Example
Generated thumbnail icons.
One-time write to a file to get the binary data of it.
So this is why Godot should support and provide an API for this special kind of files.
Methods
OS.get_temp_dir()
This function returns the global OS temporary dir for the application. It may be the root /tmp directory for most of the Unix/Linux systems, but for other platforms, it is the temporary dir given by the OS.
If no such thing as a temporary directory exist for the OS (ie. the Android platform), a directory inside the cache directory is chosen.
This PR adds
OS::get_temp_dir(),FileAccess::create_temp(), andDirAccess::create_temp()functions (the PR originally spelledtmpinstead oftemp), for all the supported platforms.The concept of temporary files and directories
Temporary files and cache files are really similar, but they are distinct.
So this is why Godot should support and provide an API for this special kind of files.
Methods
OS.get_temp_dir()This function returns the global OS temporary dir for the application. It may be the root
/tmpdirectory for most of the Unix/Linux systems, but for other platforms, it is the temporary dir given by the OS.If no such thing as a temporary directory exist for the OS (ie. the Android platform), a directory inside the cache directory is chosen.
FileAccess.create_temp(int mode_flags, String prefix = "", String extension = "", bool keep = false)This static function returns a
FileAccessobject with a temporary file open.For sorting purposes, you can set
prefixto the name of your project, just to be able to quickly debug temporary files if needed.As ResourceLoaders usually detect the type of the file with the extension, you can pass a custom extension to add to the file name.
And if you set
keepto true, the file will not get cleaned up when theFileAccessinstance will be freed.DirAccess.create_temp(String prefix = "", bool keep = false)This static function returns a
DirAccessobject with a temporary directory open. Useful if you need temporary named files and directories.prefixandkeepexist such as inFileAccess.create_temp().If
keepis false, it will recursively delete the contents of the temporary directory when theDirAccessinstance will be freed.