فهرست منبع

Fix xattr issue when backing up sshfs filesystems (Closes #4).

Jonas Borgström 12 سال پیش
والد
کامیت
a84613f0b8
2فایلهای تغییر یافته به همراه11 افزوده شده و 16 حذف شده
  1. 1 0
      CHANGES
  2. 10 16
      attic/xattr.py

+ 1 - 0
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".

+ 10 - 16
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 @@ except ImportError:
                 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 @@ except ImportError:
                 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)