mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-14 16:11:43 +00:00
Merge pull request #4450 from ThomasWaldmann/freebsd-xattr-ns
freebsd xattr namespace fixes
This commit is contained in:
commit
915d84ecb2
7 changed files with 33 additions and 19 deletions
|
@ -35,5 +35,5 @@ def check_extension_modules():
|
|||
raise ExtensionModuleError
|
||||
if item.API_VERSION != '1.2_01':
|
||||
raise ExtensionModuleError
|
||||
if platform.API_VERSION != platform.OS_API_VERSION or platform.API_VERSION != '1.2_04':
|
||||
if platform.API_VERSION != platform.OS_API_VERSION or platform.API_VERSION != '1.2_05':
|
||||
raise ExtensionModuleError
|
||||
|
|
|
@ -17,7 +17,7 @@ platform API: that way platform APIs provided by the platform-specific support m
|
|||
are correctly composed into the base functionality.
|
||||
"""
|
||||
|
||||
API_VERSION = '1.2_04'
|
||||
API_VERSION = '1.2_05'
|
||||
|
||||
fdatasync = getattr(os, 'fdatasync', os.fsync)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from .posix import user2uid, group2gid
|
|||
from ..helpers import safe_decode, safe_encode
|
||||
from .xattr import _listxattr_inner, _getxattr_inner, _setxattr_inner, split_string0
|
||||
|
||||
API_VERSION = '1.2_04'
|
||||
API_VERSION = '1.2_05'
|
||||
|
||||
cdef extern from "sys/xattr.h":
|
||||
ssize_t c_listxattr "listxattr" (const char *path, char *list, size_t size, int flags)
|
||||
|
|
|
@ -4,7 +4,7 @@ from .posix import posix_acl_use_stored_uid_gid
|
|||
from ..helpers import safe_encode, safe_decode
|
||||
from .xattr import _listxattr_inner, _getxattr_inner, _setxattr_inner, split_lstring
|
||||
|
||||
API_VERSION = '1.2_04'
|
||||
API_VERSION = '1.2_05'
|
||||
|
||||
cdef extern from "errno.h":
|
||||
int errno
|
||||
|
@ -51,43 +51,57 @@ cdef extern from "unistd.h":
|
|||
|
||||
|
||||
def listxattr(path, *, follow_symlinks=False):
|
||||
ns, prefix = EXTATTR_NAMESPACE_USER, b'user.'
|
||||
|
||||
def func(path, buf, size):
|
||||
if isinstance(path, int):
|
||||
return c_extattr_list_fd(path, EXTATTR_NAMESPACE_USER, <char *> buf, size)
|
||||
return c_extattr_list_fd(path, ns, <char *> buf, size)
|
||||
else:
|
||||
if follow_symlinks:
|
||||
return c_extattr_list_file(path, EXTATTR_NAMESPACE_USER, <char *> buf, size)
|
||||
return c_extattr_list_file(path, ns, <char *> buf, size)
|
||||
else:
|
||||
return c_extattr_list_link(path, EXTATTR_NAMESPACE_USER, <char *> buf, size)
|
||||
return c_extattr_list_link(path, ns, <char *> buf, size)
|
||||
|
||||
n, buf = _listxattr_inner(func, path)
|
||||
return [name for name in split_lstring(buf[:n]) if name]
|
||||
return [prefix + name for name in split_lstring(buf[:n]) if name]
|
||||
|
||||
|
||||
def getxattr(path, name, *, follow_symlinks=False):
|
||||
ns, prefix = EXTATTR_NAMESPACE_USER, b'user.'
|
||||
|
||||
def func(path, name, buf, size):
|
||||
if isinstance(path, int):
|
||||
return c_extattr_get_fd(path, EXTATTR_NAMESPACE_USER, name, <char *> buf, size)
|
||||
return c_extattr_get_fd(path, ns, name, <char *> buf, size)
|
||||
else:
|
||||
if follow_symlinks:
|
||||
return c_extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, <char *> buf, size)
|
||||
return c_extattr_get_file(path, ns, name, <char *> buf, size)
|
||||
else:
|
||||
return c_extattr_get_link(path, EXTATTR_NAMESPACE_USER, name, <char *> buf, size)
|
||||
return c_extattr_get_link(path, ns, name, <char *> 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 bytes(buf[:n])
|
||||
|
||||
|
||||
def setxattr(path, name, value, *, follow_symlinks=False):
|
||||
ns, prefix = EXTATTR_NAMESPACE_USER, b'user.'
|
||||
|
||||
def func(path, name, value, size):
|
||||
if isinstance(path, int):
|
||||
return c_extattr_set_fd(path, EXTATTR_NAMESPACE_USER, name, <char *> value, size)
|
||||
return c_extattr_set_fd(path, ns, name, <char *> value, size)
|
||||
else:
|
||||
if follow_symlinks:
|
||||
return c_extattr_set_file(path, EXTATTR_NAMESPACE_USER, name, <char *> value, size)
|
||||
return c_extattr_set_file(path, ns, name, <char *> value, size)
|
||||
else:
|
||||
return c_extattr_set_link(path, EXTATTR_NAMESPACE_USER, name, <char *> value, size)
|
||||
return c_extattr_set_link(path, ns, name, <char *> 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)
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ from .xattr import _listxattr_inner, _getxattr_inner, _setxattr_inner, split_str
|
|||
from libc cimport errno
|
||||
from libc.stdint cimport int64_t
|
||||
|
||||
API_VERSION = '1.2_04'
|
||||
API_VERSION = '1.2_05'
|
||||
|
||||
cdef extern from "sys/xattr.h":
|
||||
ssize_t c_listxattr "listxattr" (const char *path, char *list, size_t size)
|
||||
|
|
|
@ -2240,7 +2240,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
|
|||
else:
|
||||
assert False, "expected OSError(ENOATTR), but no error was raised"
|
||||
except OSError as err:
|
||||
if sys.platform.startswith(('freebsd', )) and err.errno == errno.ENOTSUP:
|
||||
if sys.platform.startswith(('nothing_here_now', )) and err.errno == errno.ENOTSUP:
|
||||
# some systems have no xattr support on FUSE
|
||||
pass
|
||||
else:
|
||||
|
|
|
@ -56,13 +56,13 @@ class XattrTestCase(BaseTestCase):
|
|||
tmp_fn = os.fsencode(self.tmpfile.name)
|
||||
# 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 = [b'user.attr%d' % i for i in range(9)]
|
||||
# xattr raw key list will be > 64
|
||||
keys = [b'user.attr%d' % i for i in range(20)]
|
||||
for key in keys:
|
||||
setxattr(tmp_fn, key, b'x')
|
||||
got_keys = listxattr(tmp_fn)
|
||||
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):
|
||||
tmp_fn = os.fsencode(self.tmpfile.name)
|
||||
|
|
Loading…
Add table
Reference in a new issue