Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FileSystem & FIleSystemProtocol to allow custom path prefixes (custom://) #98544

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

TML233
Copy link
Contributor

@TML233 TML233 commented Oct 26, 2024

closes godotengine/godot-proposals#11032
closes godotengine/godot-proposals#6307

This PR is a refactor of the Godot FileAccess system. It adds FileSystem and FileSystemProtocol to manage file path prefixes.

FileAccess access type and create_funcs are removed now. Different FileAccess types only deals with their targeted file source now, which means different platform's OS FileAccess now only handles paths that are in the os filesystem. They don't need to handle res:// user:// anymore, in fact, they don't even know about other protocols now. Platforms now implement their own OS protocol and OS FileAccess and register the os protocol to the FileSystem.

Current-file-unrelated and current-directory-unrelated methods like file_exists(path) and get_modified_time(path) are also moved to FileSystemProtocol. The original implementation instantiates a FileAccess, calls the method and immediately throws it away. This change can theoretically improve the performance with simple file operations.

DirAccess can be a simple wrapper of FileSystemProtocol.

By pre-defining some FileAccessProtocols that remaps paths, users can easily register a protocol prefix that remaps file paths.

Issues

(Fixed) gdscript://

Solution

As far as I can tell, gdscript://object_id.gd represents a gdscript instance in memory.
To prevent stepping in old code, gdscript protocol is reserved. It fails all accesses silently.

Descripton

Introduced by #71197
This is the reason that GDScript test fails. It expects hardcoded console output. During the test, GDScript system requires a resource load for the file path prefixed gdscript://, which would silently fail and return false in the old FileAccess implementation. But in FileSystem, an error message of Unknown filesystem protocol gdscript generates, thus failing the test.
I don't think muting the error message is a good approach, if anyone adds a gdscript protocol, GDScript system would break because of this.

Todo

  • Add FileSystem & FileSystemProtocol
  • Move current-file-unrelated methods of FileAccess to FileSystemProtocol
  • Add proper thread-safe locks
  • Add globalize_path
  • Remove first two merges that are unrelated to this PR.
  • Move current-directory-unrelated methods of DirAccess to FileSystemProtocol
  • Write documents

Move hard-coded protocols to FileSystemProtocol

os:// and pipe:// are implemented and registered by different OS platforms.

  • res://
  • user://
  • uid://

Platform supports

Create FileSystemProtocolOS and FileSystemProtocolPipe.
Cleanup FileAccessPlatform and FileAccessPlatformPipe.
Add OS_Platform::initialize_filesystem().
Remove previous FileAccess::make_default calls from OS_Platform::initialize()

  • Windows
  • Linux
  • Android

Future Tasks

  • Add FileAccessProtocolRemap
  • Expose FileSystemProtocol to GDVirtual

@TML233 TML233 changed the title Add FileSystem & FIleSystemProtocol Add FileSystem & FIleSystemProtocol to allow custom path prefixes (custom://) Oct 26, 2024
@timothyqiu timothyqiu added this to the 4.x milestone Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants