Merge pull request #4457 from ThomasWaldmann/freebsd-xattr-ns-1.1

make freebsd xattr platform code api compatible with linux, fixes #3952 (1.1-maint bp)
This commit is contained in:
TW 2019-03-21 01:48:49 +01:00 committed by GitHub
commit 8e78580c83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -44,13 +44,13 @@ class XattrTestCase(BaseTestCase):
def test_listxattr_buffer_growth(self):
# make it work even with ext4, which imposes rather low limits
buffer.resize(size=64, init=True)
# xattr raw key list will be size 9 * (10 + 1), which is > 64
keys = ['user.attr%d' % i for i in range(9)]
# xattr raw key list will be > 64
keys = ['user.attr%d' % i for i in range(20)]
for key in keys:
setxattr(self.tmpfile.name, key, b'x')
got_keys = listxattr(self.tmpfile.name)
self.assert_equal_se(got_keys, keys)
self.assert_equal(len(buffer), 128)
self.assert_true(len(buffer) > 64)
def test_getxattr_buffer_growth(self):
# make it work even with ext4, which imposes rather low limits

View file

@ -323,6 +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.restype = c_int
ns = EXTATTR_NAMESPACE_USER = 0x0001
prefix = 'user.'
def listxattr(path, *, follow_symlinks=True):
def func(path, buf, size):
@ -335,7 +336,7 @@ elif sys.platform.startswith('freebsd'): # pragma: freebsd only
return libc.extattr_list_link(path, ns, buf, size)
n, buf = _listxattr_inner(func, path)
return [os.fsdecode(name) for name in split_lstring(buf[:n]) if name]
return [prefix + os.fsdecode(name) for name in split_lstring(buf[:n]) if name]
def getxattr(path, name, *, follow_symlinks=True):
def func(path, name, buf, size):
@ -347,6 +348,10 @@ elif sys.platform.startswith('freebsd'): # pragma: freebsd only
else:
return libc.extattr_get_link(path, ns, name, buf, size)
# strip namespace if there, but ignore if not there.
# older borg / attic versions did not prefix the namespace to the names.
if name.startswith(prefix):
name = name[len(prefix):]
n, buf = _getxattr_inner(func, path, name)
return buf[:n] or None
@ -360,6 +365,10 @@ elif sys.platform.startswith('freebsd'): # pragma: freebsd only
else:
return libc.extattr_set_link(path, ns, name, value, size)
# strip namespace if there, but ignore if not there.
# older borg / attic versions did not prefix the namespace to the names.
if name.startswith(prefix):
name = name[len(prefix):]
_setxattr_inner(func, path, name, value)
else: # pragma: unknown platform only