1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 01:37:20 +00:00

acls (linux): use surrogatescape error handling, fix test

surrogatescape will decode/encode invalid utf-8 sequences (if we do not get utf-8) in a round-tripping way.
This commit is contained in:
Thomas Waldmann 2015-10-18 23:33:29 +02:00
parent 55179fe64d
commit b2cffe00fe
2 changed files with 5 additions and 4 deletions

View file

@ -31,7 +31,7 @@ def acl_use_local_uid_gid(acl):
"""Replace the user/group field with the local uid/gid if possible
"""
entries = []
for entry in acl.decode('ascii').split('\n'):
for entry in acl.decode('utf-8', 'surrogateescape').split('\n'):
if entry:
fields = entry.split(':')
if fields[0] == 'user' and fields[1]:
@ -39,7 +39,7 @@ def acl_use_local_uid_gid(acl):
elif fields[0] == 'group' and fields[1]:
fields[1] = str(group2gid(fields[1], int(fields[3])))
entries.append(':'.join(fields[:3]))
return ('\n'.join(entries)).encode('ascii')
return '\n'.join(entries).encode('utf-8', 'surrogatescape')
cdef acl_append_numeric_ids(acl):

View file

@ -86,8 +86,9 @@ def test_non_ascii_acl(self):
acl = b'\n'.join([nothing_special, user_entry, group_entry])
self.set_acl(file.name, access=acl, numeric_owner=False)
acl_access = self.get_acl(file.name)[b'acl_access']
self.assert_in(user_entry, acl_access)
self.assert_in(group_entry, acl_access)
# set_acl did not find the local user/group here, so it fell back to the uid/gid:
self.assert_in(user_entry_numeric, acl_access)
self.assert_in(group_entry_numeric, acl_access)
acl_access_numeric = self.get_acl(file.name, numeric_owner=True)[b'acl_access']
self.assert_in(user_entry_numeric, acl_access_numeric)
self.assert_in(group_entry_numeric, acl_access_numeric)