mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-21 13:47:16 +00:00
parent
53f6738090
commit
18641ae687
2 changed files with 11 additions and 9 deletions
|
@ -21,10 +21,12 @@ def test(self):
|
|||
self.assert_equal(listxattr(self.symlink), [])
|
||||
setxattr(self.tmpfile.name, 'user.foo', b'bar')
|
||||
setxattr(self.tmpfile.fileno(), 'user.bar', b'foo')
|
||||
self.assert_equal(set(listxattr(self.tmpfile.name)), set(['user.foo', 'user.bar']))
|
||||
self.assert_equal(set(listxattr(self.tmpfile.fileno())), set(['user.foo', 'user.bar']))
|
||||
self.assert_equal(set(listxattr(self.symlink)), set(['user.foo', 'user.bar']))
|
||||
setxattr(self.tmpfile.name, 'user.empty', None)
|
||||
self.assert_equal(set(listxattr(self.tmpfile.name)), set(['user.foo', 'user.bar', 'user.empty']))
|
||||
self.assert_equal(set(listxattr(self.tmpfile.fileno())), set(['user.foo', 'user.bar', 'user.empty']))
|
||||
self.assert_equal(set(listxattr(self.symlink)), set(['user.foo', 'user.bar', 'user.empty']))
|
||||
self.assert_equal(listxattr(self.symlink, follow_symlinks=False), [])
|
||||
self.assert_equal(getxattr(self.tmpfile.name, 'user.foo'), b'bar')
|
||||
self.assert_equal(getxattr(self.tmpfile.fileno(), 'user.foo'), b'bar')
|
||||
self.assert_equal(getxattr(self.symlink, 'user.foo'), b'bar')
|
||||
self.assert_equal(getxattr(self.tmpfile.name, 'user.empty'), None)
|
||||
|
|
|
@ -89,7 +89,7 @@ def getxattr(path, name, *, follow_symlinks=True):
|
|||
|
||||
def setxattr(path, name, value, *, follow_symlinks=True):
|
||||
name = os.fsencode(name)
|
||||
value = os.fsencode(value)
|
||||
value = value and os.fsencode(value)
|
||||
if isinstance(path, str):
|
||||
path = os.fsencode(path)
|
||||
if isinstance(path, int):
|
||||
|
@ -98,7 +98,7 @@ def setxattr(path, name, value, *, follow_symlinks=True):
|
|||
func = libc.setxattr
|
||||
else:
|
||||
func = libc.lsetxattr
|
||||
_check(func(path, name, value, len(value), 0), path)
|
||||
_check(func(path, name, value, len(value) if value else 0, 0), path)
|
||||
|
||||
elif sys.platform == 'darwin':
|
||||
libc.listxattr.argtypes = (c_char_p, c_char_p, c_size_t, c_int)
|
||||
|
@ -155,7 +155,7 @@ def getxattr(path, name, *, follow_symlinks=True):
|
|||
|
||||
def setxattr(path, name, value, *, follow_symlinks=True):
|
||||
name = os.fsencode(name)
|
||||
value = os.fsencode(value)
|
||||
value = value and os.fsencode(value)
|
||||
func = libc.setxattr
|
||||
flags = 0
|
||||
if isinstance(path, str):
|
||||
|
@ -164,7 +164,7 @@ def setxattr(path, name, value, *, follow_symlinks=True):
|
|||
func = libc.fsetxattr
|
||||
elif not follow_symlinks:
|
||||
flags = XATTR_NOFOLLOW
|
||||
_check(func(path, name, value, len(value), 0, flags), path)
|
||||
_check(func(path, name, value, len(value) if value else 0, 0, flags), path)
|
||||
|
||||
elif sys.platform.startswith('freebsd'):
|
||||
EXTATTR_NAMESPACE_USER = 0x0001
|
||||
|
@ -236,7 +236,7 @@ def getxattr(path, name, *, follow_symlinks=True):
|
|||
|
||||
def setxattr(path, name, value, *, follow_symlinks=True):
|
||||
name = os.fsencode(name)
|
||||
value = os.fsencode(value)
|
||||
value = value and os.fsencode(value)
|
||||
if isinstance(path, str):
|
||||
path = os.fsencode(path)
|
||||
if isinstance(path, int):
|
||||
|
@ -245,7 +245,7 @@ def setxattr(path, name, value, *, follow_symlinks=True):
|
|||
func = libc.extattr_set_file
|
||||
else:
|
||||
func = libc.extattr_set_link
|
||||
_check(func(path, EXTATTR_NAMESPACE_USER, name, value, len(value)), path)
|
||||
_check(func(path, EXTATTR_NAMESPACE_USER, name, value, len(value) if value else 0), path)
|
||||
|
||||
else:
|
||||
raise Exception('Unsupported platform: %s' % sys.platform)
|
||||
|
|
Loading…
Reference in a new issue