Narrow FileAccess scope to prevent deadlocks.

This commit is contained in:
bruvzg 2022-04-12 10:12:40 +03:00
parent 5974e1432e
commit 4bf99f4af2
29 changed files with 511 additions and 459 deletions

View File

@ -1088,7 +1088,7 @@ void File::flush() {
void File::close() {
ERR_FAIL_COND_MSG(f.is_null(), "File must be opened.");
f = Ref<FileAccess>();
f.unref();
}
bool File::is_open() const {

View File

@ -275,6 +275,7 @@ String DirAccess::get_full_path(const String &p_path, AccessType p_access) {
Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
//printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data());
Error err;
{
Ref<FileAccess> fsrc = FileAccess::open(p_from, FileAccess::READ, &err);
ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to open " + p_from);
@ -297,6 +298,7 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
fdst->store_8(fsrc->get_8());
}
}
if (err == OK && p_chmod_flags != -1) {
err = FileAccess::set_unix_permissions(p_to, p_chmod_flags);

View File

@ -105,7 +105,7 @@ Ref<FileAccess> FileAccess::open(const String &p_path, int p_mode_flags, Error *
*r_error = err;
}
if (err != OK) {
ret = Ref<FileAccess>();
ret.unref();
}
return ret;

View File

@ -63,7 +63,7 @@ Error FileAccessCompressed::open_after_magic(Ref<FileAccess> p_base) {
cmode = (Compression::Mode)f->get_32();
block_size = f->get_32();
if (block_size == 0) {
f = Ref<FileAccess>();
f.unref();
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Can't open compressed file '" + p_base->get_path() + "' with block size 0, it is corrupted.");
}
read_total = f->get_32();
@ -106,7 +106,7 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
f = FileAccess::open(p_path, p_mode_flags, &err);
if (err != OK) {
//not openable
f = Ref<FileAccess>();
f.unref();
return err;
}
@ -126,7 +126,7 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
rmagic[4] = 0;
err = ERR_FILE_UNRECOGNIZED;
if (magic != rmagic || (err = open_after_magic(f)) != OK) {
f = Ref<FileAccess>();
f.unref();
return err;
}
}
@ -180,7 +180,7 @@ void FileAccessCompressed::close() {
buffer.clear();
read_blocks.clear();
}
f = Ref<FileAccess>();
f.unref();
}
bool FileAccessCompressed::is_open() const {

View File

@ -122,9 +122,7 @@ void FileAccessEncrypted::close() {
_release();
file->close();
file = Ref<FileAccess>();
file.unref();
}
void FileAccessEncrypted::release() {
@ -134,7 +132,7 @@ void FileAccessEncrypted::release() {
_release();
file = Ref<FileAccess>();
file.unref();
}
void FileAccessEncrypted::_release() {

View File

@ -227,14 +227,20 @@ Error FileAccessPack::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessPack::close() {
f->close();
f.unref();
}
bool FileAccessPack::is_open() const {
if (f.is_valid()) {
return f->is_open();
} else {
return false;
}
}
void FileAccessPack::seek(uint64_t p_position) {
ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use.");
if (p_position > pf.size) {
eof = true;
} else {
@ -262,6 +268,7 @@ bool FileAccessPack::eof_reached() const {
}
uint8_t FileAccessPack::get_8() const {
ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use.");
if (pos >= pf.size) {
eof = true;
return 0;
@ -272,6 +279,7 @@ uint8_t FileAccessPack::get_8() const {
}
uint64_t FileAccessPack::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V_MSG(f.is_null(), -1, "File must be opened before use.");
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
if (eof) {
@ -295,6 +303,8 @@ uint64_t FileAccessPack::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
}
void FileAccessPack::set_big_endian(bool p_big_endian) {
ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use.");
FileAccess::set_big_endian(p_big_endian);
f->set_big_endian(p_big_endian);
}

View File

@ -148,7 +148,7 @@ void RotatedFileLogger::clear_old_backups() {
}
void RotatedFileLogger::rotate_file() {
file = Ref<FileAccess>();
file.unref();
if (FileAccess::exists(base_path)) {
if (max_files > 1) {

View File

@ -216,7 +216,7 @@ Error PCKPacker::flush(bool p_verbose) {
Ref<FileAccess> src = FileAccess::open(files[i].src_path, FileAccess::READ);
uint64_t to_write = files[i].size;
fae = Ref<FileAccess>();
fae.unref();
Ref<FileAccess> ftmp = file;
if (files[i].encrypted) {
fae.instantiate();
@ -253,7 +253,7 @@ Error PCKPacker::flush(bool p_verbose) {
printf("\n");
}
file = Ref<FileAccess>();
file.unref();
memdelete_arr(buf);
return OK;

View File

@ -789,7 +789,7 @@ Error ResourceLoaderBinary::load() {
resource_cache.push_back(res);
if (main) {
f = Ref<FileAccess>();
f.unref();
resource = res;
resource->set_as_translation_remapped(translation_remapped);
error = OK;
@ -868,7 +868,7 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p
fac.instantiate();
error = fac->open_after_magic(f);
if (error != OK) {
f = Ref<FileAccess>();
f.unref();
ERR_FAIL_MSG("Failed to open binary resource file: " + local_path + ".");
}
f = fac;
@ -876,7 +876,7 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p
} else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
// Not normal.
error = ERR_FILE_UNRECOGNIZED;
f = Ref<FileAccess>();
f.unref();
ERR_FAIL_MSG("Unrecognized binary resource file: " + local_path + ".");
}
@ -901,7 +901,7 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p
print_bl("format: " + itos(ver_format));
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
f = Ref<FileAccess>();
f.unref();
ERR_FAIL_MSG(vformat("File '%s' can't be loaded, as it uses a format version (%d) or engine version (%d.%d) which are not supported by your engine version (%s).",
local_path, ver_format, ver_major, ver_minor, VERSION_BRANCH));
}
@ -978,6 +978,7 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p
if (f->eof_reached()) {
error = ERR_FILE_CORRUPT;
f.unref();
ERR_FAIL_MSG("Premature end of file (EOF): " + local_path + ".");
}
}
@ -994,7 +995,7 @@ String ResourceLoaderBinary::recognize(Ref<FileAccess> p_f) {
fac.instantiate();
error = fac->open_after_magic(f);
if (error != OK) {
f = Ref<FileAccess>();
f.unref();
return "";
}
f = fac;
@ -1002,7 +1003,7 @@ String ResourceLoaderBinary::recognize(Ref<FileAccess> p_f) {
} else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
// Not normal.
error = ERR_FILE_UNRECOGNIZED;
f = Ref<FileAccess>();
f.unref();
return "";
}
@ -1016,7 +1017,7 @@ String ResourceLoaderBinary::recognize(Ref<FileAccess> p_f) {
uint32_t ver_format = f->get_32();
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
f = Ref<FileAccess>();
f.unref();
return "";
}

View File

@ -220,7 +220,7 @@ Error ResourceUID::update_cache() {
}
}
if (f != nullptr) {
if (f.is_valid()) {
f->seek(0);
f->store_32(cache_entries); //update amount of entries
}

View File

@ -201,14 +201,14 @@ void OS::print_all_resources(String p_to_file) {
Error err;
_OSPRF = FileAccess::open(p_to_file, FileAccess::WRITE, &err);
if (err != OK) {
_OSPRF = Ref<FileAccess>();
_OSPRF.unref();
ERR_FAIL_MSG("Can't print all resources to file: " + String(p_to_file) + ".");
}
}
ObjectDB::debug_objects(_OS_printres);
_OSPRF = Ref<FileAccess>();
_OSPRF.unref();
}
void OS::print_resources_in_use(bool p_short) {

View File

@ -377,6 +377,7 @@ void CreateDialog::_confirmed() {
return;
}
{
Ref<FileAccess> f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::WRITE);
if (f.is_valid()) {
f->store_line(selected_item);
@ -387,6 +388,7 @@ void CreateDialog::_confirmed() {
}
}
}
}
// To prevent, emitting an error from the transient window (shader dialog for example) hide this dialog before emitting the "create" signal.
hide();
@ -645,6 +647,7 @@ void CreateDialog::_save_and_update_favorite_list() {
favorites->clear();
TreeItem *root = favorites->create_item();
{
Ref<FileAccess> f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites." + base_type), FileAccess::WRITE);
if (f.is_valid()) {
for (int i = 0; i < favorite_list.size(); i++) {
@ -664,6 +667,7 @@ void CreateDialog::_save_and_update_favorite_list() {
ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(name, icon_fallback));
}
}
}
emit_signal(SNAME("favorites_updated"));
}

View File

@ -1142,6 +1142,10 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
Error err = export_project_files(p_preset, p_debug, _save_pack_file, &pd, _add_shared_object);
// Close temp file.
pd.f.unref();
ftmp.unref();
if (err != OK) {
DirAccess::remove_file_or_error(tmppath);
ERR_PRINT("Failed to export project files");
@ -1301,6 +1305,8 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
f->store_buffer(buf, got);
}
ftmp.unref(); // Close temp file.
if (p_embed) {
// Ensure embedded data ends at a 64-bit multiple
uint64_t embed_end = f->get_position() - embed_pos + 12;

View File

@ -218,6 +218,7 @@ void EditorFileSystem::_scan_filesystem() {
String project = ProjectSettings::get_singleton()->get_resource_path();
String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(CACHE_FILE_NAME);
{
Ref<FileAccess> f = FileAccess::open(fscache, FileAccess::READ);
bool first = true;
@ -284,6 +285,7 @@ void EditorFileSystem::_scan_filesystem() {
}
}
}
}
String update_cache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_update4");
@ -1700,6 +1702,8 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
for (const KeyValue<String, Map<StringName, Variant>> &E : source_file_options) {
const String &file = E.key;
String base_path = ResourceFormatImporter::get_singleton()->get_import_base_path(file);
Vector<String> dest_paths;
{
Ref<FileAccess> f = FileAccess::open(file + ".import", FileAccess::WRITE);
ERR_FAIL_COND_V_MSG(f.is_null(), ERR_FILE_CANT_OPEN, "Cannot open import file '" + file + ".import'.");
@ -1715,8 +1719,6 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
f->store_line("type=\"" + importer->get_resource_type() + "\"");
}
Vector<String> dest_paths;
if (err == OK) {
String path = base_path + "." + importer->get_save_extension();
f->store_line("path=\"" + path + "\"");
@ -1760,8 +1762,10 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
VariantWriter::write_to_string(v, value);
f->store_line(base + "=" + value);
}
}
// Store the md5's of the various files. These are stored separately so that the .import files can be version controlled.
{
Ref<FileAccess> md5s = FileAccess::open(base_path + ".md5", FileAccess::WRITE);
ERR_FAIL_COND_V_MSG(md5s.is_null(), ERR_FILE_CANT_OPEN, "Cannot open MD5 file '" + base_path + ".md5'.");
@ -1769,6 +1773,7 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
if (dest_paths.size()) {
md5s->store_line("dest_md5=\"" + FileAccess::get_multiple_md5(dest_paths) + "\"\n");
}
}
EditorFileSystemDirectory *fs = nullptr;
int cpos = -1;
@ -1914,6 +1919,8 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
//as import is complete, save the .import file
Vector<String> dest_paths;
{
Ref<FileAccess> f = FileAccess::open(p_file + ".import", FileAccess::WRITE);
ERR_FAIL_COND_MSG(f.is_null(), "Cannot open file from path '" + p_file + ".import'.");
@ -1935,8 +1942,6 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
f->store_line("uid=\"" + ResourceUID::get_singleton()->id_to_text(uid) + "\""); //store in readable format
Vector<String> dest_paths;
if (err == OK) {
if (importer->get_save_extension().is_empty()) {
//no path
@ -2000,8 +2005,10 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
VariantWriter::write_to_string(params[base], value);
f->store_line(base + "=" + value);
}
}
// Store the md5's of the various files. These are stored separately so that the .import files can be version controlled.
{
Ref<FileAccess> md5s = FileAccess::open(base_path + ".md5", FileAccess::WRITE);
ERR_FAIL_COND_MSG(md5s.is_null(), "Cannot open MD5 file '" + base_path + ".md5'.");
@ -2009,6 +2016,7 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName
if (dest_paths.size()) {
md5s->store_line("dest_md5=\"" + FileAccess::get_multiple_md5(dest_paths) + "\"\n");
}
}
//update modified times, to avoid reimport
fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file);

View File

@ -263,28 +263,31 @@ void EditorResourcePreview::_iterate() {
if (tsize != thumbnail_size) {
cache_valid = false;
f.unref();
} else if (last_modtime != modtime) {
String last_md5 = f->get_line();
String md5 = FileAccess::get_md5(item.path);
f.unref();
if (last_md5 != md5) {
cache_valid = false;
} else {
//update modified time
f = FileAccess::open(file, FileAccess::WRITE);
if (f.is_null()) {
Ref<FileAccess> f2 = FileAccess::open(file, FileAccess::WRITE);
if (f2.is_null()) {
// Not returning as this would leave the thread hanging and would require
// some proper cleanup/disabling of resource preview generation.
ERR_PRINT("Cannot create file '" + file + "'. Check user write permissions.");
} else {
f->store_line(itos(thumbnail_size));
f->store_line(itos(has_small_texture));
f->store_line(itos(modtime));
f->store_line(md5);
f2->store_line(itos(thumbnail_size));
f2->store_line(itos(has_small_texture));
f2->store_line(itos(modtime));
f2->store_line(md5);
}
}
} else {
f.unref();
}
if (cache_valid) {

View File

@ -514,7 +514,7 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_
}
f->store_buffer(data.ptr(), data.size());
f.unref(); // close file.
#ifndef WINDOWS_ENABLED
FileAccess::set_unix_permissions(to_write, (info.external_fa >> 16) & 0x01FF);
#endif
@ -728,6 +728,7 @@ Error ExportTemplateManager::install_android_template_from_file(const String &p_
Ref<FileAccess> f = FileAccess::open(to_write, FileAccess::WRITE);
if (f.is_valid()) {
f->store_buffer(data.ptr(), data.size());
f.unref(); // close file.
#ifndef WINDOWS_ENABLED
FileAccess::set_unix_permissions(to_write, (info.external_fa >> 16) & 0x01FF);
#endif

View File

@ -1091,11 +1091,13 @@ void ScriptEditor::_file_dialog_action(String p_file) {
switch (file_dialog_option) {
case FILE_NEW_TEXTFILE: {
Error err;
{
Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
if (err) {
EditorNode::get_singleton()->show_warning(TTR("Error writing TextFile:") + "\n" + p_file, TTR("Error!"));
break;
}
}
if (EditorFileSystem::get_singleton()) {
if (textfile_extensions.has(p_file.get_extension())) {
@ -2209,6 +2211,7 @@ Error ScriptEditor::_save_text_file(Ref<TextFile> p_text_file, const String &p_p
String source = sqscr->get_text();
Error err;
{
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(err, err, "Cannot save text file '" + p_path + "'.");
@ -2217,6 +2220,7 @@ Error ScriptEditor::_save_text_file(Ref<TextFile> p_text_file, const String &p_p
if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
return ERR_CANT_CREATE;
}
}
if (ResourceSaver::get_timestamp_on_save()) {
p_text_file->set_last_modified_time(FileAccess::get_modified_time(p_path));

View File

@ -2353,6 +2353,7 @@ Error ResourceFormatSaverGDScript::save(const String &p_path, const RES &p_resou
String source = sqscr->get_source_code();
{
Error err;
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err);
@ -2362,6 +2363,7 @@ Error ResourceFormatSaverGDScript::save(const String &p_path, const RES &p_resou
if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
return ERR_CANT_CREATE;
}
}
if (ScriptServer::is_reload_scripts_on_save_enabled()) {
GDScriptLanguage::get_singleton()->reload_tool_script(p_resource, false);

View File

@ -3641,6 +3641,7 @@ Error ResourceFormatSaverCSharpScript::save(const String &p_path, const RES &p_r
}
#endif
{
Error err;
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save C# script file '" + p_path + "'.");
@ -3650,6 +3651,7 @@ Error ResourceFormatSaverCSharpScript::save(const String &p_path, const RES &p_r
if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
return ERR_CANT_CREATE;
}
}
#ifdef TOOLS_ENABLED
if (ScriptServer::is_reload_scripts_on_save_enabled()) {

View File

@ -77,22 +77,20 @@ static String make_text(const char *log_domain, const char *log_level, const cha
}
void GDMonoLog::mono_log_callback(const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *) {
Ref<FileAccess> f = GDMonoLog::get_singleton()->log_file;
if (GDMonoLog::get_singleton()->log_level_id >= get_log_level_id(log_level)) {
String text = make_text(log_domain, log_level, message);
text += "\n";
f->seek_end();
f->store_string(text);
GDMonoLog::get_singleton()->log_file->seek_end();
GDMonoLog::get_singleton()->log_file->store_string(text);
}
if (fatal) {
String text = make_text(log_domain, log_level, message);
ERR_PRINT("Mono: FATAL ERROR '" + text + "', ABORTING! Logfile: '" + GDMonoLog::get_singleton()->log_file_path + "'.");
// Make sure to flush before aborting
f->flush();
f->close();
GDMonoLog::get_singleton()->log_file->flush();
GDMonoLog::get_singleton()->log_file.unref();
abort();
}

View File

@ -152,7 +152,7 @@ void VideoStreamPlaybackTheora::clear() {
theora_eos = false;
vorbis_eos = false;
file = Ref<FileAccess>();
file.unref();
playing = false;
};

View File

@ -1570,6 +1570,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
}
/* write the file */
{
Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
if (f.is_null()) {
ERR_PRINT("Can't write '" + file + "'.");
@ -1577,6 +1578,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
return ERR_CANT_CREATE;
};
f->store_buffer(data.ptr(), data.size());
}
#if defined(OSX_ENABLED) || defined(X11_ENABLED)
if (is_execute) {
@ -1714,12 +1716,14 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
_export_additional_assets(dest_dir + binary_name, libraries, assets);
_add_assets_to_project(p_preset, project_file_data, assets);
String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj";
{
Ref<FileAccess> f = FileAccess::open(project_file_name, FileAccess::WRITE);
if (f.is_null()) {
ERR_PRINT("Can't write '" + project_file_name + "'.");
return ERR_CANT_CREATE;
};
f->store_buffer(project_file_data.ptr(), project_file_data.size());
}
#ifdef OSX_ENABLED
{

View File

@ -81,12 +81,14 @@ void JavaScriptToolsEditorPlugin::_download_zip(Variant p_v) {
const String base_path = resource_path.substr(0, resource_path.rfind("/")) + "/";
_zip_recursive(resource_path, base_path, zip);
zipClose(zip, nullptr);
{
Ref<FileAccess> f = FileAccess::open(output_path, FileAccess::READ);
ERR_FAIL_COND_MSG(f.is_null(), "Unable to create ZIP file.");
Vector<uint8_t> buf;
buf.resize(f->get_length());
f->get_buffer(buf.ptrw(), buf.size());
godot_js_os_download_buffer(buf.ptr(), buf.size(), output_name.utf8().get_data(), "application/zip");
}
// Remove the temporary file since it was sent to the user's native filesystem as a download.
DirAccess::remove_file_or_error(output_path);

View File

@ -511,9 +511,11 @@ Error OS_LinuxBSD::move_to_trash(const String &p_path) {
String trash_info = "[Trash Info]\nPath=" + path.uri_encode() + "\nDeletionDate=" + timestamp + "\n";
{
Error err;
{
Ref<FileAccess> file = FileAccess::open(trash_path + "/info/" + file_name + ".trashinfo", FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(err != OK, err, "Can't create trashinfo file: \"" + trash_path + "/info/" + file_name + ".trashinfo\"");
file->store_string(trash_info);
}
// Rename our resource before moving it to the trash can.
Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);

View File

@ -256,6 +256,7 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_
String path = EditorPaths::get_singleton()->get_cache_dir().plus_file("icon.png");
ResourceSaver::save(path, it);
{
Ref<FileAccess> f = FileAccess::open(path, FileAccess::READ);
if (f.is_null()) {
// Clean up generated file.
@ -271,6 +272,7 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_
len = BSWAP32(len);
memcpy(&data.write[ofs], icon_infos[i].name, 4);
encode_uint32(len, &data.write[ofs + 4]);
}
// Clean up generated file.
DirAccess::remove_file_or_error(path);

View File

@ -457,7 +457,7 @@ void AppxPackager::finish() {
Vector<uint8_t> end_record = make_end_of_central_record();
package->store_buffer(end_record.ptr(), end_record.size());
package = Ref<FileAccess>();
package.unref();
}
AppxPackager::AppxPackager() {}

View File

@ -346,6 +346,7 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
ERR_FAIL_V_MSG(data, err_string);
}
{
Ref<FileAccess> f = FileAccess::open(tmp_path, FileAccess::READ, &err);
if (err != OK) {
@ -358,6 +359,7 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
data.resize(f->get_length());
f->get_buffer(data.ptrw(), data.size());
}
DirAccess::remove_file_or_error(tmp_path);

View File

@ -197,7 +197,7 @@ void HTTPRequest::cancel_request() {
thread.wait_to_finish();
}
file = Ref<FileAccess>();
file.unref();
client->close();
body.clear();
got_response = false;

View File

@ -890,7 +890,7 @@ Error ResourceLoaderText::rename_dependencies(Ref<FileAccess> p_f, const String
fw->store_8(c);
c = f->get_8();
}
f = Ref<FileAccess>();
f.unref();
bool all_ok = fw->get_error() == OK;
@ -1098,14 +1098,14 @@ Error ResourceLoaderText::save_as_binary(Ref<FileAccess> p_f, const String &p_pa
wf->store_32(0); //zero sub resources, still parsing them
String temp_file = p_path + ".temp";
Vector<uint64_t> local_offsets;
Vector<uint64_t> local_pointers_pos;
{
Ref<FileAccess> wf2 = FileAccess::open(temp_file, FileAccess::WRITE);
if (wf2.is_null()) {
return ERR_CANT_OPEN;
}
Vector<uint64_t> local_offsets;
Vector<uint64_t> local_pointers_pos;
while (next_tag.name == "sub_resource" || next_tag.name == "resource") {
String type;
int id = -1;
@ -1235,6 +1235,7 @@ Error ResourceLoaderText::save_as_binary(Ref<FileAccess> p_f, const String &p_pa
wf2->store_32(prop_count);
wf2->seek_end();
}
}
uint64_t offset_from = wf->get_position();
wf->seek(sub_res_count_pos); //plus one because the saved one