From 587c3134fb05630c827ada678a92f5dc3a456920 Mon Sep 17 00:00:00 2001 From: GlitchedCode922 <126592994+GlitchedCode922@users.noreply.github.com> Date: Fri, 26 Sep 2025 18:07:17 +0300 Subject: [PATCH] Fix permission handling for backup on write files --- drivers/unix/file_access_unix.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index f4e44f83118..d818f41efed 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -148,7 +148,15 @@ Error FileAccessUnix::open_internal(const String &p_path, int p_mode_flags) { last_error = ERR_FILE_CANT_OPEN; return last_error; } - fchmod(fd, 0644); + + struct stat file_stat = {}; + int error = stat(save_path.utf8().get_data(), &file_stat); + if (!error) { + fchmod(fd, file_stat.st_mode & 0xFFF); // Mask to remove file type + } else { + fchmod(fd, 0644); // Fallback permissions + } + path = String::utf8(cs.ptr()); f = fdopen(fd, mode_string);