From a84613f0b8776415d21d2db5bd10cd8d3911113a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Sat, 17 Aug 2013 12:38:35 +0200 Subject: [PATCH] Fix xattr issue when backing up sshfs filesystems (Closes #4). --- CHANGES | 1 + attic/xattr.py | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index d9c513448..b602d712a 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ Version 0.8 (feature release, released on X) +- Fix xattr issue when backing up sshfs filesystems (#4) - Support access of read only repositories. - New syntax to enable repository encryption: attic init --encryption="none|passphrase|keyfile". diff --git a/attic/xattr.py b/attic/xattr.py index e3e2d9aeb..cdf6f4d12 100644 --- a/attic/xattr.py +++ b/attic/xattr.py @@ -18,13 +18,17 @@ def is_enabled(): def get_all(path, follow_symlinks=True): - return dict((name, getxattr(path, name, follow_symlinks=follow_symlinks)) - for name in listxattr(path, follow_symlinks=follow_symlinks)) - + try: + return dict((name, getxattr(path, name, follow_symlinks=follow_symlinks)) + for name in listxattr(path, follow_symlinks=follow_symlinks)) + except OSError as e: + if e.errno in (errno.ENOTSUP, errno.EPERM): + return {} try: # Currently only available on Python 3.3+ on Linux - from os import getxattr, setxattr, listxattr2 + from os import getxattr, setxattr, listxattr + except ImportError: from ctypes import CDLL, create_string_buffer, c_ssize_t, c_size_t, c_char_p, c_int, c_uint32, get_errno from ctypes.util import find_library @@ -124,12 +128,7 @@ def listxattr(path, *, follow_symlinks=True): func = libc.flistxattr elif not follow_symlinks: flags = XATTR_NOFOLLOW - try: - n = _check(func(path, None, 0, flags), path) - except OSError as e: - if e.errno == errno.EPERM: - return [] - raise + n = _check(func(path, None, 0, flags), path) if n == 0: return [] namebuf = create_string_buffer(n) @@ -201,12 +200,7 @@ def listxattr(path, *, follow_symlinks=True): func = libc.extattr_list_file else: func = libc.extattr_list_link - try: - n = _check(func(path, ns, None, 0), path) - except OSError as e: - if e.errno == errno.ENOTSUP: - return [] - raise + n = _check(func(path, ns, None, 0), path) if n == 0: return [] namebuf = create_string_buffer(n)