From 9e35c56adb6f3f2f1d3e3258f3bce4f651bbd125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Mon, 1 Nov 2010 23:06:56 +0100 Subject: [PATCH] Fixed linux xattr issue --- darc/archive.py | 21 +++++++++++++++------ darc/test.py | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/darc/archive.py b/darc/archive.py index 67e322735..904408a2b 100644 --- a/darc/archive.py +++ b/darc/archive.py @@ -14,6 +14,7 @@ from .helpers import uid2user, user2uid, gid2group, group2gid, IntegrityError CHUNK_SIZE = 55001 have_lchmod = hasattr(os, 'lchmod') +linux = sys.platform == 'linux' class Archive(object): @@ -147,12 +148,12 @@ class Archive(object): 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 @@ class Archive(object): '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 diff --git a/darc/test.py b/darc/test.py index 861945a6d..d59d5a466 100644 --- a/darc/test.py +++ b/darc/test.py @@ -87,7 +87,7 @@ class Test(unittest.TestCase): 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')