Skip to content

Commit 587c313

Browse files
Fix permission handling for backup on write files
1 parent 1f7630f commit 587c313

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/unix/file_access_unix.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ Error FileAccessUnix::open_internal(const String &p_path, int p_mode_flags) {
148148
last_error = ERR_FILE_CANT_OPEN;
149149
return last_error;
150150
}
151-
fchmod(fd, 0644);
151+
152+
struct stat file_stat = {};
153+
int error = stat(save_path.utf8().get_data(), &file_stat);
154+
if (!error) {
155+
fchmod(fd, file_stat.st_mode & 0xFFF); // Mask to remove file type
156+
} else {
157+
fchmod(fd, 0644); // Fallback permissions
158+
}
159+
152160
path = String::utf8(cs.ptr());
153161

154162
f = fdopen(fd, mode_string);

0 commit comments

Comments
 (0)