Skip to content

Commit

Permalink
Merge pull request #1464 from ThomasWaldmann/fix-xattr-exception
Browse files Browse the repository at this point in the history
xattr: dynamically grow result buffer until it fits, fixes #1462
  • Loading branch information
ThomasWaldmann authored Aug 12, 2016
2 parents 6bf48bb + 3c7dddc commit 4e5b80b
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 147 deletions.
22 changes: 21 additions & 1 deletion borg/testsuite/xattr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import tempfile
import unittest

from ..xattr import is_enabled, getxattr, setxattr, listxattr
from ..xattr import is_enabled, getxattr, setxattr, listxattr, get_buffer
from . import BaseTestCase


Expand Down Expand Up @@ -38,3 +38,23 @@ def test(self):
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)

def test_listxattr_buffer_growth(self):
# make it work even with ext4, which imposes rather low limits
get_buffer(size=64, init=True)
# xattr raw key list will be size 9 * (10 + 1), which is > 64
keys = ['user.attr%d' % i for i in range(9)]
for key in keys:
setxattr(self.tmpfile.name, key, b'x')
got_keys = listxattr(self.tmpfile.name)
self.assert_equal_se(got_keys, keys)
self.assert_equal(len(get_buffer()), 128)

def test_getxattr_buffer_growth(self):
# make it work even with ext4, which imposes rather low limits
get_buffer(size=64, init=True)
value = b'x' * 126
setxattr(self.tmpfile.name, 'user.big', value)
got_value = getxattr(self.tmpfile.name, 'user.big')
self.assert_equal(value, got_value)
self.assert_equal(len(get_buffer()), 128)
Loading

0 comments on commit 4e5b80b

Please sign in to comment.