diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2023-03-19 00:37:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-19 00:37:33 -0700 |
commit | 4d5f10fc3ad4e72c22391663c37d1f46510bb291 (patch) | |
tree | 49f92efbb3568d17d7630c255f9ce38358f1dd36 /drivers/unix/file_access_unix.cpp | |
parent | 7752b52aa35aa4ae2e0ac03fa1249a874018888d (diff) | |
parent | ca58a5d56f45709ff2860471de14130a6cfa9c13 (diff) | |
download | redot-engine-4d5f10fc3ad4e72c22391663c37d1f46510bb291.tar.gz |
Merge pull request #75074 from bruvzg/fix_unix_temp_files
Fix Unix temp file creations when using is_backup_save_enabled.
Diffstat (limited to 'drivers/unix/file_access_unix.cpp')
-rw-r--r-- | drivers/unix/file_access_unix.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 12b11da10a..3c2f36c7c0 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -102,14 +102,26 @@ Error FileAccessUnix::open_internal(const String &p_path, int p_mode_flags) { 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; + CharString cs = path.utf8(); + int fd = mkstemp(cs.ptrw()); + if (fd == -1) { + last_error = ERR_FILE_CANT_OPEN; + return last_error; } - path = path + ".tmp"; + path = String::utf8(cs.ptr()); + + f = fdopen(fd, mode_string); + if (f == nullptr) { + // Delete temp file and close descriptor if open failed. + ::unlink(cs.ptr()); + ::close(fd); + last_error = ERR_FILE_CANT_OPEN; + return last_error; + } + } else { + f = fopen(path.utf8().get_data(), mode_string); } - f = fopen(path.utf8().get_data(), mode_string); - if (f == nullptr) { switch (errno) { case ENOENT: { |