From 64b7b5fdd4b9cf690d6c420e17fd8c65897a9219 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 10 Mar 2024 13:20:37 +0100 Subject: [PATCH] FreeBSD: check first if kind of ACL can be set on a file --- src/borg/platform/freebsd.pyx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/borg/platform/freebsd.pyx b/src/borg/platform/freebsd.pyx index ac522dfbe..c38f03588 100644 --- a/src/borg/platform/freebsd.pyx +++ b/src/borg/platform/freebsd.pyx @@ -48,6 +48,7 @@ cdef extern from "sys/acl.h": cdef extern from "unistd.h": long lpathconf(const char *path, int name) int _PC_ACL_NFS4 + int _PC_ACL_EXTENDED # On FreeBSD, borg currently only deals with the USER namespace as it is unclear @@ -213,6 +214,14 @@ def acl_set(path, item, numeric_ids=False, fd=None): """ if isinstance(path, str): path = os.fsencode(path) - _set_acl(path, ACL_TYPE_NFS4, item, 'acl_nfs4', numeric_ids, fd=fd) - _set_acl(path, ACL_TYPE_ACCESS, item, 'acl_access', numeric_ids, fd=fd) - _set_acl(path, ACL_TYPE_DEFAULT, item, 'acl_default', numeric_ids, fd=fd) + ret = lpathconf(path, _PC_ACL_NFS4) + if ret < 0: + raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path)) + if ret == 1: + _set_acl(path, ACL_TYPE_NFS4, item, 'acl_nfs4', numeric_ids, fd=fd) + ret = lpathconf(path, _PC_ACL_EXTENDED) + if ret < 0: + raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path)) + if ret == 1: + _set_acl(path, ACL_TYPE_ACCESS, item, 'acl_access', numeric_ids, fd=fd) + _set_acl(path, ACL_TYPE_DEFAULT, item, 'acl_default', numeric_ids, fd=fd)