diff options
author | Yuri Sizov <11782833+YuriSizov@users.noreply.github.com> | 2023-03-16 12:05:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-16 12:05:48 +0100 |
commit | ea31842b72974dd663e908872213979f47e66f0d (patch) | |
tree | 67f7d750e39e518b47055cadce4193b4af92d9aa /drivers/unix/file_access_unix.cpp | |
parent | bdefdc866b7733741d310085d6617a6fa8881405 (diff) | |
parent | 345f5757e56e28a3a25465dcd84b8ddc674315b9 (diff) | |
download | redot-engine-ea31842b72974dd663e908872213979f47e66f0d.tar.gz |
Merge pull request #73156 from gw2cc/safe_save
Create a safe temporary file with is_backup_save_enabled
Diffstat (limited to 'drivers/unix/file_access_unix.cpp')
-rw-r--r-- | drivers/unix/file_access_unix.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index ee3cb876cf..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); |