瀏覽代碼

Merge pull request #1993 from enkore/issue/1992

fix xattrs on ObjectiveFS
enkore 8 年之前
父節點
當前提交
9d7ec9aa0a
共有 2 個文件被更改,包括 17 次插入6 次删除
  1. 9 6
      borg/xattr.py
  2. 8 0
      docs/changes.rst

+ 9 - 6
borg/xattr.py

@@ -10,7 +10,7 @@ from ctypes import CDLL, create_string_buffer, c_ssize_t, c_size_t, c_char_p, c_
 from ctypes.util import find_library
 from ctypes.util import find_library
 from distutils.version import LooseVersion
 from distutils.version import LooseVersion
 
 
-from .helpers import Buffer
+from .helpers import Buffer, Error
 
 
 
 
 try:
 try:
@@ -113,8 +113,11 @@ def split_lstring(buf):
     return result
     return result
 
 
 
 
-class BufferTooSmallError(Exception):
-    """the buffer given to an xattr function was too small for the result"""
+class BufferTooSmallError(OSError):
+    """insufficient buffer memory for completing a xattr operation."""
+
+    def __str__(self):
+        return self.__doc__
 
 
 
 
 def _check(rv, path=None, detect_buffer_too_small=False):
 def _check(rv, path=None, detect_buffer_too_small=False):
@@ -205,7 +208,7 @@ if sys.platform.startswith('linux'):  # pragma: linux only
 
 
         n, buf = _listxattr_inner(func, path)
         n, buf = _listxattr_inner(func, path)
         return [os.fsdecode(name) for name in split_string0(buf[:n])
         return [os.fsdecode(name) for name in split_string0(buf[:n])
-                if not name.startswith(b'system.posix_acl_')]
+                if name and not name.startswith(b'system.posix_acl_')]
 
 
     def getxattr(path, name, *, follow_symlinks=True):
     def getxattr(path, name, *, follow_symlinks=True):
         def func(path, name, buf, size):
         def func(path, name, buf, size):
@@ -261,7 +264,7 @@ elif sys.platform == 'darwin':  # pragma: darwin only
                     return libc.listxattr(path, buf, size, XATTR_NOFOLLOW)
                     return libc.listxattr(path, buf, size, XATTR_NOFOLLOW)
 
 
         n, buf = _listxattr_inner(func, path)
         n, buf = _listxattr_inner(func, path)
-        return [os.fsdecode(name) for name in split_string0(buf[:n])]
+        return [os.fsdecode(name) for name in split_string0(buf[:n]) if name]
 
 
     def getxattr(path, name, *, follow_symlinks=True):
     def getxattr(path, name, *, follow_symlinks=True):
         def func(path, name, buf, size):
         def func(path, name, buf, size):
@@ -320,7 +323,7 @@ elif sys.platform.startswith('freebsd'):  # pragma: freebsd only
                     return libc.extattr_list_link(path, ns, buf, size)
                     return libc.extattr_list_link(path, ns, buf, size)
 
 
         n, buf = _listxattr_inner(func, path)
         n, buf = _listxattr_inner(func, path)
-        return [os.fsdecode(name) for name in split_lstring(buf[:n])]
+        return [os.fsdecode(name) for name in split_lstring(buf[:n]) if name]
 
 
     def getxattr(path, name, *, follow_symlinks=True):
     def getxattr(path, name, *, follow_symlinks=True):
         def func(path, name, buf, size):
         def func(path, name, buf, size):

+ 8 - 0
docs/changes.rst

@@ -126,6 +126,14 @@ The best check that everything is ok is to run a dry-run extraction::
 Changelog
 Changelog
 =========
 =========
 
 
+Version 1.0.10rc1 (not released yet)
+------------------------------------
+
+Bug fixes:
+
+- Avoid triggering an ObjectiveFS bug in xattr retrieval, #1992
+- When running out of buffer memory when reading xattrs, only skip the current file, #1993
+
 Version 1.0.9 (2016-12-20)
 Version 1.0.9 (2016-12-20)
 --------------------------
 --------------------------