mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-23 22:51:35 +00:00
Fixed linux xattr issue
This commit is contained in:
parent
d70993fc83
commit
9e35c56adb
2 changed files with 16 additions and 7 deletions
|
@ -14,6 +14,7 @@
|
|||
CHUNK_SIZE = 55001
|
||||
|
||||
have_lchmod = hasattr(os, 'lchmod')
|
||||
linux = sys.platform == 'linux'
|
||||
|
||||
|
||||
class Archive(object):
|
||||
|
@ -147,12 +148,12 @@ def extract_item(self, item, dest=None):
|
|||
def restore_attrs(self, path, item, symlink=False):
|
||||
xattrs = item.get('xattrs')
|
||||
if xattrs:
|
||||
try:
|
||||
xa = xattr(path, XATTR_NOFOLLOW)
|
||||
for k, v in xattrs.items():
|
||||
xa = xattr(path, XATTR_NOFOLLOW)
|
||||
for k, v in xattrs.items():
|
||||
try:
|
||||
xa.set(k, v)
|
||||
except IOError:
|
||||
pass
|
||||
except KeyError:
|
||||
pass
|
||||
if have_lchmod:
|
||||
os.lchmod(path, item['mode'])
|
||||
elif not symlink:
|
||||
|
@ -196,7 +197,15 @@ def stat_attrs(self, st, path):
|
|||
'atime': st.st_atime, 'mtime': st.st_mtime,
|
||||
}
|
||||
try:
|
||||
item['xattrs'] = dict(xattr(path, XATTR_NOFOLLOW))
|
||||
xa = xattr(path, XATTR_NOFOLLOW)
|
||||
xattrs = {}
|
||||
for key in xa:
|
||||
# Only store the user namespace on Linux
|
||||
if linux and not key.startswith('user'):
|
||||
continue
|
||||
xattrs[key] = xa[key]
|
||||
if xattrs:
|
||||
item['xattrs'] = xattrs
|
||||
except IOError:
|
||||
pass
|
||||
return item
|
||||
|
|
|
@ -87,7 +87,7 @@ def test_basic_functionality(self):
|
|||
self.create_regual_file('file1', size=1024*80)
|
||||
self.create_regual_file('dir2/file2', size=1024*80)
|
||||
x = xattr(os.path.join(self.input_path, 'file1'))
|
||||
x.set('user:foo', 'bar')
|
||||
x.set('user.foo', 'bar')
|
||||
os.symlink('somewhere', os.path.join(self.input_path, 'link1'))
|
||||
os.mkfifo(os.path.join(self.input_path, 'fifo1'))
|
||||
self.darc('create', self.store_path + '::test', 'input')
|
||||
|
|
Loading…
Reference in a new issue