-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Replace File/Directory with FileAccess/DirAccess #65271
The head ref may contain hidden characters: "FirAccess\u{1F332}"
Conversation
f4ad741
to
b6655ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that for now there is no error handling for the static methods.
I guess we can just add thread local get_last_error()
method, returning Array
won't be too intuitive for the users, and the error codes aren't too verbose to be useful.
eb69559
to
e701c2f
Compare
For the error, I think you could do something like |
modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs
Outdated
Show resolved
Hide resolved
28ba715
to
f6b22f2
Compare
The |
I totally forgot about |
@KoBeWi |
GDREGISTER_ABSTRACT_CLASS(FileAccess); | ||
GDREGISTER_ABSTRACT_CLASS(DirAccess); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't those be virtual instead of abstract?
They can be instantiated so (pure) abstract doesn't seem correct to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what's the difference. Does virtual also prevent manual instantiation?
I checked how we use abstract and TreeItem is abstract, but you can instantiate it too. Same with SceneTreeTimer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah so we want to forbid FileAccess.new()
to force using a create method?
Then abstract might work indeed, but it feels to me like it's exploiting the wrong concept to expose a class which is not abstract nor virtual but just means to be non-instantiable directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, abstract is good in this case, if we want to provide something towards the future, in this case it will work out better as FileAccessExtension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
I discussed with @reduz, @KoBeWi and @Faless the fact that this breaks compatibility significantly with 3.x / previous 4.0 builds as File
and Directory
in the scripting API will now be exposed as FileAccess
and DirAccess
(like they werehe already internally in C++ code).
The compat breakage is of course unfortunate, but we agreed that it's better as:
- It's the internal name and it's more consistent (those objects don't represent files or directories themselves, but the access to them).
- Even without that name change, this PR breaks compatibility as
Directory.open()
andFile.open()
are now static methods, so users will need to fix their code anyway and this makes it more obvious than a potential silent failure from misusing the new API.
Thanks! |
IMO, I think
And for another reason, in OTHER: make such method like |
The new is actually The old File/Directory were wrappers that used FileAccess/DirAccess under the hood. This PR just strips the wrapping layer and exposes FileAccess/DirAccess directly; the "new" classes just use the core name (changing it is a big deal, because it's used ~2700 times in the engine code, so that would be a lot of changes). Also the new names are more accurate, because you are not creating "File" or "Directory", you are just accessing them from the filesystem. And as I mentioned, the new classes are used a bit differently (no more open/close), so new names signify that. |
I don't want to complain but I don't understand the need for a change like this. Godot is supposed to be in beta now yet this is a pretty significant breaking change. there is a lot of script that will need to change with this.. it's not just a rename. the change also touched a lot of src files which of course invalidates all any previous testing during the alpha stage for those. this breaks style with other classes like ConfigFile. and with regards to "names are more accurate", who thought that's the case in the first place. using new() is perfectly consistent with how all classes work in GDScirpt... this new form with the auto new is really not. Now if this was needed for something that doesn't seem to be described here, well fine. I think though then that these PRs should include a little blurb explaining the reasoning for the change. |
The reason why this PR was created is that the previous Directory/File classes were a workaround for lack of static method bind support in GDScript. This is now possible, so we can get rid of most of the core bind file (which, as you can see in the changes here, just duplicates the methods of original classes and forwards them to a new class). The FileAccess/DirAccess are the only classes that required compatibility breaking, so they were the first ones to be replaced (unfortunately this PR didn't make it before beta1). This is a breaking change, but not something that can't be fixed easily. Replacing it in my (rather big) project took me ~20 minutes. The API is mostly the same, the only thing that changed is how you create the objects. Also some of the methods are now static, so you can get rid of code like |
Ah! ok, thanks for the reply and I appreciate the explanation. totally get it now. |
The documentation hasn't been updated. DirAccess says to use new() which doesn't work.
|
@@ -234,7 +234,7 @@ ZipArchive::~ZipArchive() { | |||
packages.clear(); | |||
} | |||
|
|||
Error FileAccessZip::_open(const String &p_path, int p_mode_flags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when this was renamed to open_internal()
, the _open()
call below was left in place, which ends up calling FileAccess::_open()
, which becomes an infinite recursion and causes a stack overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by #66485.
@KoBeWi This would have been caught if _open
was made private, which I think it could be. I see a few more underscore-prefixed methods public in DirAccess
and FileAccess
, I would suggest doing another pass on those to see what needs to be public and what can be made private or protected.
This PR removes Fille/Directory from core bind and binds FileAccess/DirAccess instead.
The "new" classes have almost the same API as the old ones, but there are some changes. Most notable changes are
open()
being static and lack ofclose()
method. I updated the docs to reflect that.