mirror of
https://github.com/borgbackup/borg.git
synced 2026-04-28 01:28:46 -04:00
acls: only calls os.fsencode for str paths
This commit is contained in:
parent
34cd1b22ec
commit
5bf5f12be1
3 changed files with 28 additions and 19 deletions
|
|
@ -111,8 +111,10 @@ def _remove_non_numeric_identifier(acl):
|
|||
def acl_get(path, item, st, numeric_owner=False):
|
||||
cdef acl_t acl = NULL
|
||||
cdef char *text = NULL
|
||||
if isinstance(path, str):
|
||||
path = os.fsencode(path)
|
||||
try:
|
||||
acl = acl_get_link_np(<bytes>os.fsencode(path), ACL_TYPE_EXTENDED)
|
||||
acl = acl_get_link_np(path, ACL_TYPE_EXTENDED)
|
||||
if acl == NULL:
|
||||
return
|
||||
text = acl_to_text(acl, NULL)
|
||||
|
|
@ -138,7 +140,9 @@ def acl_set(path, item, numeric_owner=False):
|
|||
acl = acl_from_text(<bytes>_remove_numeric_id_if_possible(acl_text))
|
||||
if acl == NULL:
|
||||
return
|
||||
if acl_set_link_np(<bytes>os.fsencode(path), ACL_TYPE_EXTENDED, acl):
|
||||
if isinstance(path, str):
|
||||
path = os.fsencode(path)
|
||||
if acl_set_link_np(path, ACL_TYPE_EXTENDED, acl):
|
||||
return
|
||||
finally:
|
||||
acl_free(acl)
|
||||
|
|
|
|||
|
|
@ -107,16 +107,17 @@ def acl_get(path, item, st, numeric_owner=False):
|
|||
If `numeric_owner` is True the user/group field is not preserved only uid/gid
|
||||
"""
|
||||
cdef int flags = ACL_TEXT_APPEND_ID
|
||||
p = os.fsencode(path)
|
||||
ret = lpathconf(p, _PC_ACL_NFS4)
|
||||
if isinstance(path, str):
|
||||
path = os.fsencode(path)
|
||||
ret = lpathconf(path, _PC_ACL_NFS4)
|
||||
if ret < 0 and errno == EINVAL:
|
||||
return
|
||||
flags |= ACL_TEXT_NUMERIC_IDS if numeric_owner else 0
|
||||
if ret > 0:
|
||||
_get_acl(p, ACL_TYPE_NFS4, item, 'acl_nfs4', flags)
|
||||
_get_acl(path, ACL_TYPE_NFS4, item, 'acl_nfs4', flags)
|
||||
else:
|
||||
_get_acl(p, ACL_TYPE_ACCESS, item, 'acl_access', flags)
|
||||
_get_acl(p, ACL_TYPE_DEFAULT, item, 'acl_default', flags)
|
||||
_get_acl(path, ACL_TYPE_ACCESS, item, 'acl_access', flags)
|
||||
_get_acl(path, ACL_TYPE_DEFAULT, item, 'acl_default', flags)
|
||||
|
||||
|
||||
cdef _set_acl(p, type, item, attribute, numeric_owner=False):
|
||||
|
|
@ -153,7 +154,8 @@ def acl_set(path, item, numeric_owner=False):
|
|||
If `numeric_owner` is True the stored uid/gid is used instead
|
||||
of the user/group names
|
||||
"""
|
||||
p = os.fsencode(path)
|
||||
_set_acl(p, ACL_TYPE_NFS4, item, 'acl_nfs4', numeric_owner)
|
||||
_set_acl(p, ACL_TYPE_ACCESS, item, 'acl_access', numeric_owner)
|
||||
_set_acl(p, ACL_TYPE_DEFAULT, item, 'acl_default', numeric_owner)
|
||||
if isinstance(path, str):
|
||||
path = os.fsencode(path)
|
||||
_set_acl(path, ACL_TYPE_NFS4, item, 'acl_nfs4', numeric_owner)
|
||||
_set_acl(path, ACL_TYPE_ACCESS, item, 'acl_access', numeric_owner)
|
||||
_set_acl(path, ACL_TYPE_DEFAULT, item, 'acl_default', numeric_owner)
|
||||
|
|
|
|||
|
|
@ -227,20 +227,21 @@ def acl_get(path, item, st, numeric_owner=False):
|
|||
cdef char *default_text = NULL
|
||||
cdef char *access_text = NULL
|
||||
|
||||
p = <bytes>os.fsencode(path)
|
||||
if stat.S_ISLNK(st.st_mode) or acl_extended_file(p) <= 0:
|
||||
if isinstance(path, str):
|
||||
path = os.fsencode(path)
|
||||
if stat.S_ISLNK(st.st_mode) or acl_extended_file(path) <= 0:
|
||||
return
|
||||
if numeric_owner:
|
||||
converter = acl_numeric_ids
|
||||
else:
|
||||
converter = acl_append_numeric_ids
|
||||
try:
|
||||
access_acl = acl_get_file(p, ACL_TYPE_ACCESS)
|
||||
access_acl = acl_get_file(path, ACL_TYPE_ACCESS)
|
||||
if access_acl:
|
||||
access_text = acl_to_text(access_acl, NULL)
|
||||
if access_text:
|
||||
item['acl_access'] = converter(access_text)
|
||||
default_acl = acl_get_file(p, ACL_TYPE_DEFAULT)
|
||||
default_acl = acl_get_file(path, ACL_TYPE_DEFAULT)
|
||||
if default_acl:
|
||||
default_text = acl_to_text(default_acl, NULL)
|
||||
if default_text:
|
||||
|
|
@ -256,28 +257,30 @@ def acl_set(path, item, numeric_owner=False):
|
|||
cdef acl_t access_acl = NULL
|
||||
cdef acl_t default_acl = NULL
|
||||
|
||||
p = <bytes>os.fsencode(path)
|
||||
if isinstance(path, str):
|
||||
path = os.fsencode(path)
|
||||
if numeric_owner:
|
||||
converter = posix_acl_use_stored_uid_gid
|
||||
else:
|
||||
converter = acl_use_local_uid_gid
|
||||
access_text = item.get('acl_access')
|
||||
default_text = item.get('acl_default')
|
||||
if access_text:
|
||||
try:
|
||||
access_acl = acl_from_text(<bytes>converter(access_text))
|
||||
if access_acl:
|
||||
acl_set_file(p, ACL_TYPE_ACCESS, access_acl)
|
||||
acl_set_file(path, ACL_TYPE_ACCESS, access_acl)
|
||||
finally:
|
||||
acl_free(access_acl)
|
||||
default_text = item.get('acl_default')
|
||||
if default_text:
|
||||
try:
|
||||
default_acl = acl_from_text(<bytes>converter(default_text))
|
||||
if default_acl:
|
||||
acl_set_file(p, ACL_TYPE_DEFAULT, default_acl)
|
||||
acl_set_file(path, ACL_TYPE_DEFAULT, default_acl)
|
||||
finally:
|
||||
acl_free(default_acl)
|
||||
|
||||
|
||||
cdef _sync_file_range(fd, offset, length, flags):
|
||||
assert offset & PAGE_MASK == 0, "offset %d not page-aligned" % offset
|
||||
assert length & PAGE_MASK == 0, "length %d not page-aligned" % length
|
||||
|
|
|
|||
Loading…
Reference in a new issue