[FIX] #166960 【文件管理器】在权限细化界面添加完其他用户权限后,对该文档进行编辑保存后,细化权限界面需要重新添加其他用户权限

This commit is contained in:
Yue-Lan 2023-06-12 17:07:42 +08:00
parent 88c51de3db
commit 977a1a1598
1 changed files with 24 additions and 1 deletions

View File

@ -46,6 +46,7 @@
#include <unistd.h>
#include "gfiledescriptorbased.h"
#include <sys/uio.h>
#include <sys/xattr.h>
#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,6 +1062,12 @@ 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) */