瀏覽代碼

acls (linux): use surrogatescape error handling for acl_append_numeric_ids and acl_numeric_ids

surrogatescape will decode/encode invalid utf-8 sequences (if we do not get utf-8) in a round-tripping way.
Thomas Waldmann 9 年之前
父節點
當前提交
1f14d1de19
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      borg/platform_linux.pyx

+ 4 - 4
borg/platform_linux.pyx

@@ -46,7 +46,7 @@ cdef acl_append_numeric_ids(acl):
     """Extend the "POSIX 1003.1e draft standard 17" format with an additional uid/gid field
     """
     entries = []
-    for entry in _comment_re.sub('', acl.decode('ascii')).split('\n'):
+    for entry in _comment_re.sub('', acl.decode('utf-8', 'surrogateescape')).split('\n'):
         if entry:
             type, name, permission = entry.split(':')
             if name and type == 'user':
@@ -55,14 +55,14 @@ cdef acl_append_numeric_ids(acl):
                 entries.append(':'.join([type, name, permission, str(group2gid(name, name))]))
             else:
                 entries.append(entry)
-    return ('\n'.join(entries)).encode('ascii')
+    return '\n'.join(entries).encode('utf-8', 'surrogateescape')
 
 
 cdef acl_numeric_ids(acl):
     """Replace the "POSIX 1003.1e draft standard 17" user/group field with uid/gid
     """
     entries = []
-    for entry in _comment_re.sub('', acl.decode('ascii')).split('\n'):
+    for entry in _comment_re.sub('', acl.decode('utf-8', 'surrogateescape')).split('\n'):
         if entry:
             type, name, permission = entry.split(':')
             if name and type == 'user':
@@ -73,7 +73,7 @@ cdef acl_numeric_ids(acl):
                 entries.append(':'.join([type, gid, permission, gid]))
             else:
                 entries.append(entry)
-    return ('\n'.join(entries)).encode('ascii')
+    return '\n'.join(entries).encode('utf-8', 'surrogateescape')
 
 
 def acl_get(path, item, st, numeric_owner=False):