Browse Source

Merge pull request #3971 from ThomasWaldmann/more-xattr-stuff

xattrs: use follow_symlinks=False as default, more tests
TW 7 years ago
parent
commit
1f75b6b9b5

+ 1 - 1
src/borg/helpers/checks.py

@@ -28,7 +28,7 @@ def check_extension_modules():
         raise ExtensionModuleError
     if borg.crypto.low_level.API_VERSION != '1.1_02':
         raise ExtensionModuleError
-    if platform.API_VERSION != platform.OS_API_VERSION or platform.API_VERSION != '1.2_01':
+    if platform.API_VERSION != platform.OS_API_VERSION or platform.API_VERSION != '1.2_02':
         raise ExtensionModuleError
     if item.API_VERSION != '1.1_03':
         raise ExtensionModuleError

+ 4 - 4
src/borg/platform/base.py

@@ -17,14 +17,14 @@ platform API: that way platform APIs provided by the platform-specific support m
 are correctly composed into the base functionality.
 """
 
-API_VERSION = '1.2_01'
+API_VERSION = '1.2_02'
 
 fdatasync = getattr(os, 'fdatasync', os.fsync)
 
 from .xattr import ENOATTR
 
 
-def listxattr(path, *, follow_symlinks=True):
+def listxattr(path, *, follow_symlinks=False):
     """
     Return xattr names of a file (list of bytes objects).
 
@@ -35,7 +35,7 @@ def listxattr(path, *, follow_symlinks=True):
     return []
 
 
-def getxattr(path, name, *, follow_symlinks=True):
+def getxattr(path, name, *, follow_symlinks=False):
     """
     Read xattr and return its value (as bytes).
 
@@ -49,7 +49,7 @@ def getxattr(path, name, *, follow_symlinks=True):
     raise OSError(ENOATTR, os.strerror(ENOATTR), path)
 
 
-def setxattr(path, name, value, *, follow_symlinks=True):
+def setxattr(path, name, value, *, follow_symlinks=False):
     """
     Write xattr on *path*.
 

+ 4 - 4
src/borg/platform/darwin.pyx

@@ -6,7 +6,7 @@ from ..helpers import user2uid, group2gid
 from ..helpers import safe_decode, safe_encode
 from .xattr import _listxattr_inner, _getxattr_inner, _setxattr_inner, split_string0
 
-API_VERSION = '1.2_01'
+API_VERSION = '1.2_02'
 
 cdef extern from "sys/xattr.h":
     ssize_t c_listxattr "listxattr" (const char *path, char *list, size_t size, int flags)
@@ -37,7 +37,7 @@ cdef extern from "sys/acl.h":
     int ACL_TYPE_EXTENDED
 
 
-def listxattr(path, *, follow_symlinks=True):
+def listxattr(path, *, follow_symlinks=False):
     def func(path, buf, size):
         if isinstance(path, int):
             return c_flistxattr(path, <char *> buf, size, XATTR_NOFLAGS)
@@ -51,7 +51,7 @@ def listxattr(path, *, follow_symlinks=True):
     return [name for name in split_string0(buf[:n]) if name]
 
 
-def getxattr(path, name, *, follow_symlinks=True):
+def getxattr(path, name, *, follow_symlinks=False):
     def func(path, name, buf, size):
         if isinstance(path, int):
             return c_fgetxattr(path, name, <char *> buf, size, 0, XATTR_NOFLAGS)
@@ -65,7 +65,7 @@ def getxattr(path, name, *, follow_symlinks=True):
     return bytes(buf[:n])
 
 
-def setxattr(path, name, value, *, follow_symlinks=True):
+def setxattr(path, name, value, *, follow_symlinks=False):
     def func(path, name, value, size):
         if isinstance(path, int):
             return c_fsetxattr(path, name, <char *> value, size, 0, XATTR_NOFLAGS)

+ 4 - 4
src/borg/platform/freebsd.pyx

@@ -4,7 +4,7 @@ from ..helpers import posix_acl_use_stored_uid_gid
 from ..helpers import safe_encode, safe_decode
 from .xattr import _listxattr_inner, _getxattr_inner, _setxattr_inner, split_lstring
 
-API_VERSION = '1.2_01'
+API_VERSION = '1.2_02'
 
 cdef extern from "errno.h":
     int errno
@@ -50,7 +50,7 @@ cdef extern from "unistd.h":
     int _PC_ACL_NFS4
 
 
-def listxattr(path, *, follow_symlinks=True):
+def listxattr(path, *, follow_symlinks=False):
     def func(path, buf, size):
         if isinstance(path, int):
             return c_extattr_list_fd(path, EXTATTR_NAMESPACE_USER, <char *> buf, size)
@@ -64,7 +64,7 @@ def listxattr(path, *, follow_symlinks=True):
     return [name for name in split_lstring(buf[:n]) if name]
 
 
-def getxattr(path, name, *, follow_symlinks=True):
+def getxattr(path, name, *, follow_symlinks=False):
     def func(path, name, buf, size):
         if isinstance(path, int):
             return c_extattr_get_fd(path, EXTATTR_NAMESPACE_USER, name, <char *> buf, size)
@@ -78,7 +78,7 @@ def getxattr(path, name, *, follow_symlinks=True):
     return bytes(buf[:n])
 
 
-def setxattr(path, name, value, *, follow_symlinks=True):
+def setxattr(path, name, value, *, follow_symlinks=False):
     def func(path, name, value, size):
         if isinstance(path, int):
             return c_extattr_set_fd(path, EXTATTR_NAMESPACE_USER, name, <char *> value, size)

+ 4 - 4
src/borg/platform/linux.pyx

@@ -13,7 +13,7 @@ from .xattr import _listxattr_inner, _getxattr_inner, _setxattr_inner, split_str
 from libc cimport errno
 from libc.stdint cimport int64_t
 
-API_VERSION = '1.2_01'
+API_VERSION = '1.2_02'
 
 cdef extern from "attr/xattr.h":
     ssize_t c_listxattr "listxattr" (const char *path, char *list, size_t size)
@@ -79,7 +79,7 @@ cdef extern from "string.h":
 _comment_re = re.compile(' *#.*', re.M)
 
 
-def listxattr(path, *, follow_symlinks=True):
+def listxattr(path, *, follow_symlinks=False):
     def func(path, buf, size):
         if isinstance(path, int):
             return c_flistxattr(path, <char *> buf, size)
@@ -94,7 +94,7 @@ def listxattr(path, *, follow_symlinks=True):
             if name and not name.startswith(b'system.posix_acl_')]
 
 
-def getxattr(path, name, *, follow_symlinks=True):
+def getxattr(path, name, *, follow_symlinks=False):
     def func(path, name, buf, size):
         if isinstance(path, int):
             return c_fgetxattr(path, name, <char *> buf, size)
@@ -108,7 +108,7 @@ def getxattr(path, name, *, follow_symlinks=True):
     return bytes(buf[:n])
 
 
-def setxattr(path, name, value, *, follow_symlinks=True):
+def setxattr(path, name, value, *, follow_symlinks=False):
     def func(path, name, value, size):
         flags = 0
         if isinstance(path, int):

+ 5 - 3
src/borg/testsuite/xattr.py

@@ -36,13 +36,15 @@ class XattrTestCase(BaseTestCase):
         setxattr(tmp_fn, b'user.foo', b'bar')
         setxattr(tmp_fd, b'user.bar', b'foo')
         setxattr(tmp_fn, b'user.empty', b'')
+        setxattr(tmp_lfn, b'user.linkxattr', b'baz')
         self.assert_equal_se(listxattr(tmp_fn), [b'user.foo', b'user.bar', b'user.empty'])
         self.assert_equal_se(listxattr(tmp_fd), [b'user.foo', b'user.bar', b'user.empty'])
-        self.assert_equal_se(listxattr(tmp_lfn), [b'user.foo', b'user.bar', b'user.empty'])
-        self.assert_equal_se(listxattr(tmp_lfn, follow_symlinks=False), [])
+        self.assert_equal_se(listxattr(tmp_lfn, follow_symlinks=True), [b'user.foo', b'user.bar', b'user.empty'])
+        self.assert_equal_se(listxattr(tmp_lfn), [b'user.linkxattr'])
         self.assert_equal(getxattr(tmp_fn, b'user.foo'), b'bar')
         self.assert_equal(getxattr(tmp_fd, b'user.foo'), b'bar')
-        self.assert_equal(getxattr(tmp_lfn, b'user.foo'), b'bar')
+        self.assert_equal(getxattr(tmp_lfn, b'user.foo', follow_symlinks=True), b'bar')
+        self.assert_equal(getxattr(tmp_lfn, b'user.linkxattr'), b'baz')
         self.assert_equal(getxattr(tmp_fn, b'user.empty'), b'')
 
     def test_listxattr_buffer_growth(self):