Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/io/file_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,24 @@ Error FileAccess::reopen(const String &p_path, int p_mode_flags) {
Ref<FileAccess> FileAccess::open(const String &p_path, int p_mode_flags, Error *r_error) {
//try packed data first

Error err = OK;
Ref<FileAccess> ret;
if (!(p_mode_flags & WRITE) && !(p_mode_flags & SKIP_PACK) && PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled()) {
ret = PackedData::get_singleton()->try_open_path(p_path);
if (ret.is_valid()) {
err = ret->get_error();
if (r_error) {
*r_error = OK;
*r_error = err;
}
if (err != OK) {
ret.unref();
}
return ret;
Comment on lines +171 to 174
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (err != OK) {
ret.unref();
}
return ret;
if (err == OK) {
return ret;
}

It should behave the same as if nullptr is returned, and try to fall back to raw file outside pack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is correct behavior. If PackedData::get_singleton()->try_open_path returns a FileAccess object, that means that the path is in PackedData and thus the canonical file location is in the pack. If trying to open that file in the pack returned an error, it means that there's something catastrophically wrong with our environment (wrong encryption key, the pck got deleted in the middle of running, etc.) and we should fail here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should at least be consistent, so maybe:

  • check if pack has file using PackedData::get_singleton()->has_path
    • if found, try loading and fail if try_open_path return nullptr or returned file has error set.
    • if not found, try using filesystem.

Copy link
Member

@bruvzg bruvzg Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or get_error check can be moved to the try_open_path and it can return nullptr if error is set (to avoid double file map lookup).

}
}

ret = create_for_path(p_path);
Error err = ret->open_internal(p_path, p_mode_flags & ~SKIP_PACK);
err = ret->open_internal(p_path, p_mode_flags & ~SKIP_PACK);

if (r_error) {
*r_error = err;
Expand Down
10 changes: 7 additions & 3 deletions core/io/file_access_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ void FileAccessPack::set_big_endian(bool p_big_endian) {
}

Error FileAccessPack::get_error() const {
if (eof) {
if (encryption_error) {
return encryption_error;
} else if (f.is_null()) {
return ERR_FILE_CANT_OPEN;
} else if (eof) {
return ERR_FILE_EOF;
}
return OK;
Expand Down Expand Up @@ -494,8 +498,8 @@ FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFil
key.write[i] = script_encryption_key[i];
}

Error err = fae->open_and_parse(f, key, FileAccessEncrypted::MODE_READ, false);
ERR_FAIL_COND_MSG(err, vformat("Can't open encrypted pack-referenced file '%s'.", String(pf.pack)));
encryption_error = fae->open_and_parse(f, key, FileAccessEncrypted::MODE_READ, false);
ERR_FAIL_COND_MSG(encryption_error, vformat("Can't open encrypted pack-referenced file '%s'.", String(pf.pack)));
f = fae;
off = 0;
}
Expand Down
1 change: 1 addition & 0 deletions core/io/file_access_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class FileAccessPack : public FileAccess {

mutable uint64_t pos;
mutable bool eof;
Error encryption_error = OK;
uint64_t off;

Ref<FileAccess> f;
Expand Down