mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-23 00:07:38 +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:
parent
c5e3f3b4d4
commit
dbe92b7ace
1 changed files with 11 additions and 3 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue