You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-19 14:31:59 +00:00
Attempt renaming multiple times on safe file save, and make the behavior optional. Fixes #14339.
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
#ifdef WINDOWS_ENABLED
|
#ifdef WINDOWS_ENABLED
|
||||||
|
|
||||||
#include "file_access_windows.h"
|
#include "file_access_windows.h"
|
||||||
|
#include "os/os.h"
|
||||||
#include "shlwapi.h"
|
#include "shlwapi.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
@@ -115,7 +116,12 @@ void FileAccessWindows::close() {
|
|||||||
//_wunlink(save_path.c_str()); //unlink if exists
|
//_wunlink(save_path.c_str()); //unlink if exists
|
||||||
//int rename_error = _wrename((save_path+".tmp").c_str(),save_path.c_str());
|
//int rename_error = _wrename((save_path+".tmp").c_str(),save_path.c_str());
|
||||||
|
|
||||||
bool rename_error;
|
bool rename_error = true;
|
||||||
|
int attempts = 4;
|
||||||
|
while (rename_error && attempts) {
|
||||||
|
// This workaround of trying multiple times is added to deal with paranoid Windows
|
||||||
|
// antiviruses that love reading just written files even if they are not executable, thus
|
||||||
|
// locking the file and preventing renaming from happening.
|
||||||
|
|
||||||
#ifdef UWP_ENABLED
|
#ifdef UWP_ENABLED
|
||||||
// UWP has no PathFileExists, so we check attributes instead
|
// UWP has no PathFileExists, so we check attributes instead
|
||||||
@@ -135,6 +141,11 @@ void FileAccessWindows::close() {
|
|||||||
if (rename_error && close_fail_notify) {
|
if (rename_error && close_fail_notify) {
|
||||||
close_fail_notify(save_path);
|
close_fail_notify(save_path);
|
||||||
}
|
}
|
||||||
|
if (rename_error) {
|
||||||
|
attempts--;
|
||||||
|
OS::get_singleton()->delay_usec(1000000); //wait 100msec and try again
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
save_path = "";
|
save_path = "";
|
||||||
ERR_FAIL_COND(rename_error);
|
ERR_FAIL_COND(rename_error);
|
||||||
|
|||||||
@@ -4749,7 +4749,7 @@ EditorNode::EditorNode() {
|
|||||||
scene_distraction = false;
|
scene_distraction = false;
|
||||||
script_distraction = false;
|
script_distraction = false;
|
||||||
|
|
||||||
FileAccess::set_backup_save(true);
|
FileAccess::set_backup_save(EDITOR_DEF("filesystem/on_save/safe_save_on_backup_then_rename", true));
|
||||||
|
|
||||||
TranslationServer::get_singleton()->set_enabled(false);
|
TranslationServer::get_singleton()->set_enabled(false);
|
||||||
// load settings
|
// load settings
|
||||||
|
|||||||
Reference in New Issue
Block a user