diff options
Diffstat (limited to 'drivers/unix/file_access_unix.cpp')
-rw-r--r-- | drivers/unix/file_access_unix.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 43d3f53904..12b11da10a 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -100,6 +100,11 @@ Error FileAccessUnix::open_internal(const String &p_path, int p_mode_flags) { if (is_backup_save_enabled() && (p_mode_flags == WRITE)) { save_path = path; + // Create a temporary file in the same directory as the target file. + path = path + "-XXXXXX"; + if (!mkstemp(path.utf8().ptrw())) { + return ERR_FILE_CANT_OPEN; + } path = path + ".tmp"; } @@ -143,7 +148,7 @@ void FileAccessUnix::_close() { } if (!save_path.is_empty()) { - int rename_error = rename((save_path + ".tmp").utf8().get_data(), save_path.utf8().get_data()); + int rename_error = rename(path.utf8().get_data(), save_path.utf8().get_data()); if (rename_error && close_fail_notify) { close_fail_notify(save_path); @@ -318,6 +323,10 @@ Error FileAccessUnix::_set_unix_permissions(const String &p_file, uint32_t p_per return FAILED; } +void FileAccessUnix::close() { + _close(); +} + CloseNotificationFunc FileAccessUnix::close_notification_func = nullptr; FileAccessUnix::~FileAccessUnix() { |