freebsd xattr namespace: str vs. bytes fixup

This commit is contained in:
Thomas Waldmann 2019-03-21 03:20:12 +01:00
parent 3e2393a058
commit 88b4a00d1b
1 changed files with 7 additions and 5 deletions

View File

@ -323,7 +323,7 @@ elif sys.platform.startswith('freebsd'): # pragma: freebsd only
libc.extattr_set_file.argtypes = (c_char_p, c_int, c_char_p, c_char_p, c_size_t) libc.extattr_set_file.argtypes = (c_char_p, c_int, c_char_p, c_char_p, c_size_t)
libc.extattr_set_file.restype = c_int libc.extattr_set_file.restype = c_int
ns = EXTATTR_NAMESPACE_USER = 0x0001 ns = EXTATTR_NAMESPACE_USER = 0x0001
prefix = 'user.' prefix, prefix_b = 'user.', b'user.'
def listxattr(path, *, follow_symlinks=True): def listxattr(path, *, follow_symlinks=True):
def func(path, buf, size): def func(path, buf, size):
@ -350,8 +350,9 @@ elif sys.platform.startswith('freebsd'): # pragma: freebsd only
# strip namespace if there, but ignore if not there. # strip namespace if there, but ignore if not there.
# older borg / attic versions did not prefix the namespace to the names. # older borg / attic versions did not prefix the namespace to the names.
if name.startswith(prefix): _prefix = prefix if isinstance(name, str) else prefix_b
name = name[len(prefix):] if name.startswith(_prefix):
name = name[len(_prefix):]
n, buf = _getxattr_inner(func, path, name) n, buf = _getxattr_inner(func, path, name)
return buf[:n] or None return buf[:n] or None
@ -367,8 +368,9 @@ elif sys.platform.startswith('freebsd'): # pragma: freebsd only
# strip namespace if there, but ignore if not there. # strip namespace if there, but ignore if not there.
# older borg / attic versions did not prefix the namespace to the names. # older borg / attic versions did not prefix the namespace to the names.
if name.startswith(prefix): _prefix = prefix if isinstance(name, str) else prefix_b
name = name[len(prefix):] if name.startswith(_prefix):
name = name[len(_prefix):]
_setxattr_inner(func, path, name, value) _setxattr_inner(func, path, name, value)
else: # pragma: unknown platform only else: # pragma: unknown platform only