-Add visible IO errors when closing a file fails due to it being locked (most likely on windows), closes #4760
This commit is contained in:
parent
f0abda999e
commit
7f02627290
|
@ -35,6 +35,8 @@
|
||||||
|
|
||||||
FileAccess::CreateFunc FileAccess::create_func[ACCESS_MAX]={0,0};
|
FileAccess::CreateFunc FileAccess::create_func[ACCESS_MAX]={0,0};
|
||||||
|
|
||||||
|
FileAccess::FileCloseFailNotify FileAccess::close_fail_notify=NULL;
|
||||||
|
|
||||||
|
|
||||||
bool FileAccess::backup_save=false;
|
bool FileAccess::backup_save=false;
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,8 @@ public:
|
||||||
ACCESS_MAX
|
ACCESS_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void (*FileCloseFailNotify)(const String&);
|
||||||
|
|
||||||
typedef FileAccess*(*CreateFunc)();
|
typedef FileAccess*(*CreateFunc)();
|
||||||
bool endian_swap;
|
bool endian_swap;
|
||||||
bool real_is_double;
|
bool real_is_double;
|
||||||
|
@ -56,7 +58,7 @@ protected:
|
||||||
virtual Error _open(const String& p_path, int p_mode_flags)=0; ///< open a file
|
virtual Error _open(const String& p_path, int p_mode_flags)=0; ///< open a file
|
||||||
virtual uint64_t _get_modified_time(const String& p_file)=0;
|
virtual uint64_t _get_modified_time(const String& p_file)=0;
|
||||||
|
|
||||||
|
static FileCloseFailNotify close_fail_notify;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static bool backup_save;
|
static bool backup_save;
|
||||||
|
@ -69,8 +71,12 @@ private:
|
||||||
return memnew( T );
|
return memnew( T );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static void set_file_close_fail_notify_callback(FileCloseFailNotify p_cbk) { close_fail_notify=p_cbk; }
|
||||||
|
|
||||||
virtual void _set_access_type(AccessType p_access);
|
virtual void _set_access_type(AccessType p_access);
|
||||||
|
|
||||||
enum ModeFlags {
|
enum ModeFlags {
|
||||||
|
|
|
@ -124,6 +124,11 @@ void FileAccessUnix::close() {
|
||||||
//unlink(save_path.utf8().get_data());
|
//unlink(save_path.utf8().get_data());
|
||||||
//print_line("renaming..");
|
//print_line("renaming..");
|
||||||
int rename_error = rename((save_path+".tmp").utf8().get_data(),save_path.utf8().get_data());
|
int rename_error = rename((save_path+".tmp").utf8().get_data(),save_path.utf8().get_data());
|
||||||
|
|
||||||
|
if (rename_error && close_fail_notify) {
|
||||||
|
close_fail_notify(save_path);
|
||||||
|
}
|
||||||
|
|
||||||
save_path="";
|
save_path="";
|
||||||
ERR_FAIL_COND( rename_error != 0);
|
ERR_FAIL_COND( rename_error != 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,6 +131,10 @@ void FileAccessWindows::close() {
|
||||||
//atomic replace for existing file
|
//atomic replace for existing file
|
||||||
rename_error = !ReplaceFileW(save_path.c_str(), (save_path+".tmp").c_str(), NULL, 2|4, NULL, NULL);
|
rename_error = !ReplaceFileW(save_path.c_str(), (save_path+".tmp").c_str(), NULL, 2|4, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
if (rename_error && close_fail_notify) {
|
||||||
|
close_fail_notify(save_path);
|
||||||
|
}
|
||||||
|
|
||||||
save_path="";
|
save_path="";
|
||||||
ERR_FAIL_COND( rename_error );
|
ERR_FAIL_COND( rename_error );
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,7 @@ void EditorNode::_notification(int p_what) {
|
||||||
if (p_what==NOTIFICATION_EXIT_TREE) {
|
if (p_what==NOTIFICATION_EXIT_TREE) {
|
||||||
|
|
||||||
editor_data.save_editor_external_data();
|
editor_data.save_editor_external_data();
|
||||||
|
FileAccess::set_file_close_fail_notify_callback(NULL);
|
||||||
log->deinit(); // do not get messages anymore
|
log->deinit(); // do not get messages anymore
|
||||||
}
|
}
|
||||||
if (p_what==NOTIFICATION_PROCESS) {
|
if (p_what==NOTIFICATION_PROCESS) {
|
||||||
|
@ -5138,6 +5138,10 @@ void EditorNode::_dropped_files(const Vector<String>& p_files,int p_screen) {
|
||||||
EditorImportExport::get_singleton()->get_import_plugin(i)->import_from_drop(p_files,cur_path);
|
EditorImportExport::get_singleton()->get_import_plugin(i)->import_from_drop(p_files,cur_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void EditorNode::_file_access_close_error_notify(const String& p_str) {
|
||||||
|
|
||||||
|
add_io_error("Unable to write to file '"+p_str+"', file in use, locked or lacking permissions.");
|
||||||
|
}
|
||||||
|
|
||||||
void EditorNode::_bind_methods() {
|
void EditorNode::_bind_methods() {
|
||||||
|
|
||||||
|
@ -5233,7 +5237,6 @@ EditorNode::EditorNode() {
|
||||||
SceneState::set_disable_placeholders(true);
|
SceneState::set_disable_placeholders(true);
|
||||||
editor_initialize_certificates(); //for asset sharing
|
editor_initialize_certificates(); //for asset sharing
|
||||||
|
|
||||||
|
|
||||||
InputDefault *id = Input::get_singleton()->cast_to<InputDefault>();
|
InputDefault *id = Input::get_singleton()->cast_to<InputDefault>();
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
|
@ -6575,6 +6578,7 @@ EditorNode::EditorNode() {
|
||||||
|
|
||||||
_load_docks();
|
_load_docks();
|
||||||
|
|
||||||
|
FileAccess::set_file_close_fail_notify_callback(_file_access_close_error_notify);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6582,6 +6586,7 @@ EditorNode::EditorNode() {
|
||||||
|
|
||||||
EditorNode::~EditorNode() {
|
EditorNode::~EditorNode() {
|
||||||
|
|
||||||
|
|
||||||
memdelete( EditorHelp::get_doc_data() );
|
memdelete( EditorHelp::get_doc_data() );
|
||||||
memdelete(editor_selection);
|
memdelete(editor_selection);
|
||||||
memdelete(editor_plugins_over);
|
memdelete(editor_plugins_over);
|
||||||
|
|
|
@ -574,6 +574,7 @@ private:
|
||||||
|
|
||||||
void _update_addon_config();
|
void _update_addon_config();
|
||||||
|
|
||||||
|
static void _file_access_close_error_notify(const String& p_str);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
|
Loading…
Reference in New Issue