1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-23 08:16:54 +00:00

xattr.is_enabled: first listxattr before trying getxattr, see #4403

this is needed for the xattr dummy implementation (used e.g.
on openbsd):
- it returns [] for listxattr
- it fails with ENOATTR when trying getxattr for any name

also: reduce code duplication
This commit is contained in:
Thomas Waldmann 2019-02-26 20:35:46 +01:00
parent c5e3f3b4d4
commit dbe92b7ace

View file

@ -42,12 +42,20 @@
def is_enabled(path=None):
"""Determine if xattr is enabled on the filesystem
"""
with tempfile.NamedTemporaryFile(dir=path, prefix='borg-tmp') as fd:
with tempfile.NamedTemporaryFile(dir=path, prefix='borg-tmp') as f:
fd = f.fileno()
name, value = b'user.name', b'value'
try:
setxattr(fd.fileno(), b'user.name', b'value')
setxattr(fd, name, value)
except OSError:
return False
return getxattr(fd.fileno(), b'user.name') == b'value'
try:
names = listxattr(fd)
except OSError:
return False
if name not in names:
return False
return getxattr(fd, name) == value
def get_all(path, follow_symlinks=False):