From b2cffe00fe8fd992ac9b5475d9a8a7e1bbe0ba6f Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 18 Oct 2015 23:33:29 +0200 Subject: [PATCH] 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. --- borg/platform_linux.pyx | 4 ++-- borg/testsuite/platform.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/borg/platform_linux.pyx b/borg/platform_linux.pyx index 19041a71c..f825aa2a7 100644 --- a/borg/platform_linux.pyx +++ b/borg/platform_linux.pyx @@ -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): diff --git a/borg/testsuite/platform.py b/borg/testsuite/platform.py index df1e53542..bfb77efaa 100644 --- a/borg/testsuite/platform.py +++ b/borg/testsuite/platform.py @@ -86,8 +86,9 @@ class PlatformLinuxTestCase(BaseTestCase): 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)