Skip to content

Commit

Permalink
Merge pull request #75074 from bruvzg/fix_unix_temp_files
Browse files Browse the repository at this point in the history
Fix Unix temp file creations when using is_backup_save_enabled.
  • Loading branch information
akien-mga authored Mar 19, 2023
2 parents 7752b52 + ca58a5d commit 4d5f10f
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions drivers/unix/file_access_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 4d5f10f

Please sign in to comment.