From 44b4f9645d681ddb623efe8912c9b8dbe46b0a38 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 8 Jul 2018 14:37:04 +0200 Subject: [PATCH] xattrs: use follow_symlinks=False as default, more tests it's like we do it everywhere else because this is what we usually need. --- src/borg/helpers/checks.py | 2 +- src/borg/platform/base.py | 8 ++++---- src/borg/platform/darwin.pyx | 8 ++++---- src/borg/platform/freebsd.pyx | 8 ++++---- src/borg/platform/linux.pyx | 8 ++++---- src/borg/testsuite/xattr.py | 8 +++++--- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/borg/helpers/checks.py b/src/borg/helpers/checks.py index fa4d62e7c..de484f5f8 100644 --- a/src/borg/helpers/checks.py +++ b/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 diff --git a/src/borg/platform/base.py b/src/borg/platform/base.py index 3481a69b6..f9fa55c49 100644 --- a/src/borg/platform/base.py +++ b/src/borg/platform/base.py @@ -17,14 +17,14 @@ 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*. diff --git a/src/borg/platform/darwin.pyx b/src/borg/platform/darwin.pyx index ecd287ec7..342320eae 100644 --- a/src/borg/platform/darwin.pyx +++ b/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, 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, 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, value, size, 0, XATTR_NOFLAGS) diff --git a/src/borg/platform/freebsd.pyx b/src/borg/platform/freebsd.pyx index 92ee430a2..e52752fa3 100644 --- a/src/borg/platform/freebsd.pyx +++ b/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, 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, 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, value, size) diff --git a/src/borg/platform/linux.pyx b/src/borg/platform/linux.pyx index 4804afdeb..39c9ca310 100644 --- a/src/borg/platform/linux.pyx +++ b/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, 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, 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): diff --git a/src/borg/testsuite/xattr.py b/src/borg/testsuite/xattr.py index 9fe3e96b3..f9712be09 100644 --- a/src/borg/testsuite/xattr.py +++ b/src/borg/testsuite/xattr.py @@ -36,13 +36,15 @@ def test(self): 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):