From 977a1a15983065f4e759b9e4be1916a99955756d Mon Sep 17 00:00:00 2001 From: Yue-Lan Date: Mon, 12 Jun 2023 17:07:42 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=20#166960=20=E3=80=90=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=99=A8=E3=80=91=E5=9C=A8=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=BB=86=E5=8C=96=E7=95=8C=E9=9D=A2=E6=B7=BB=E5=8A=A0=E5=AE=8C?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E7=94=A8=E6=88=B7=E6=9D=83=E9=99=90=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E5=AF=B9=E8=AF=A5=E6=96=87=E6=A1=A3=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E4=BF=9D=E5=AD=98=E5=90=8E=EF=BC=8C=E7=BB=86?= =?UTF-8?q?=E5=8C=96=E6=9D=83=E9=99=90=E7=95=8C=E9=9D=A2=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=B7=BB=E5=8A=A0=E5=85=B6=E4=BB=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gio/glocalfileoutputstream.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c index 3ce987f..815372c 100644 --- a/gio/glocalfileoutputstream.c +++ b/gio/glocalfileoutputstream.c @@ -46,6 +46,7 @@ #include #include "gfiledescriptorbased.h" #include +#include #endif #include "glib-private.h" @@ -860,6 +861,21 @@ handle_overwrite_open (const char *filename, int errsv = 0; gboolean replace_destination_set = (flags & G_FILE_CREATE_REPLACE_DESTINATION); + #ifdef G_OS_UNIX + char acl_buf[1024]; + ssize_t acl_size = getxattr(filename, "system.posix_acl_access", acl_buf, sizeof(acl_buf)); + + gboolean has_acl_buf = FALSE; + if (acl_size == -1) { + g_debug("Error getting ACL with %s", filename); + } else if (acl_size == 0) { + g_debug("No ACL found with %s.\n", filename); + } else { + g_debug("%s ACL: %.*s\n", filename, (int)acl_size, acl_buf); + has_acl_buf = TRUE; + } +#endif + mode = mode_from_flags_or_info (flags, reference_info); /* We only need read access to the original file if we are creating a backup. @@ -1038,6 +1054,7 @@ handle_overwrite_open (const char *filename, dirname = g_path_get_dirname (filename); tmp_filename = g_build_filename (dirname, ".goutputstream-XXXXXX", NULL); + g_free (dirname); tmpfd = g_mkstemp_full (tmp_filename, (readable ? O_RDWR : O_WRONLY) | O_BINARY, mode); @@ -1045,7 +1062,13 @@ handle_overwrite_open (const char *filename, { g_free (tmp_filename); goto fallback_strategy; - } + } else { +#ifdef G_OS_UNIX + if (has_acl_buf) { + setxattr(tmp_filename, "system.posix_acl_access", acl_buf, acl_size, 0); + } +#endif + } /* try to keep permissions (unless replacing) */