diff options
Diffstat (limited to 'src/borg/platform/darwin.pyx')
-rw-r--r-- | src/borg/platform/darwin.pyx | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/borg/platform/darwin.pyx b/src/borg/platform/darwin.pyx index 7fe3db3ec..b9617a7a8 100644 --- a/src/borg/platform/darwin.pyx +++ b/src/borg/platform/darwin.pyx @@ -1,6 +1,7 @@ import os from libc.stdint cimport uint32_t +from libc cimport errno from .posix import user2uid, group2gid from ..helpers import safe_decode, safe_encode @@ -115,20 +116,25 @@ def _remove_non_numeric_identifier(acl): def acl_get(path, item, st, numeric_ids=False, fd=None): cdef acl_t acl = NULL cdef char *text = NULL + if isinstance(path, str): + path = os.fsencode(path) try: if fd is not None: acl = acl_get_fd_np(fd, ACL_TYPE_EXTENDED) else: - if isinstance(path, str): - path = os.fsencode(path) acl = acl_get_link_np(path, ACL_TYPE_EXTENDED) - if acl is not NULL: - text = acl_to_text(acl, NULL) - if text is not NULL: - if numeric_ids: - item['acl_extended'] = _remove_non_numeric_identifier(text) - else: - item['acl_extended'] = text + if acl == NULL: + if errno.errno == errno.ENOENT: + # macOS weirdness: if a file has no ACLs, it sets errno to ENOENT. :-( + return + raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path)) + text = acl_to_text(acl, NULL) + if text == NULL: + raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path)) + if numeric_ids: + item['acl_extended'] = _remove_non_numeric_identifier(text) + else: + item['acl_extended'] = text finally: acl_free(text) acl_free(acl) @@ -139,16 +145,19 @@ def acl_set(path, item, numeric_ids=False, fd=None): acl_text = item.get('acl_extended') if acl_text is not None: try: + if isinstance(path, str): + path = os.fsencode(path) if numeric_ids: acl = acl_from_text(acl_text) else: acl = acl_from_text(<bytes>_remove_numeric_id_if_possible(acl_text)) - if acl is not NULL: - if fd is not None: - acl_set_fd_np(fd, acl, ACL_TYPE_EXTENDED) - else: - if isinstance(path, str): - path = os.fsencode(path) - acl_set_link_np(path, ACL_TYPE_EXTENDED, acl) + if acl == NULL: + raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path)) + if fd is not None: + if acl_set_fd_np(fd, acl, ACL_TYPE_EXTENDED) == -1: + raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path)) + else: + if acl_set_link_np(path, ACL_TYPE_EXTENDED, acl) == -1: + raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path)) finally: acl_free(acl) |