summaryrefslogtreecommitdiff
path: root/fs/xattrs.py
diff options
context:
space:
mode:
authorrfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f>2009-07-17 02:28:08 +0000
committerrfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f>2009-07-17 02:28:08 +0000
commit8d1e513fa84944726cb56d3758b13c311ddd6025 (patch)
tree46fb6c426cfaf2bb6ca2b0408e70c29c745c8e4c /fs/xattrs.py
parent8697c1f5c8fa74d33aef19495bbe9705179c2668 (diff)
downloadpyfilesystem-git-8d1e513fa84944726cb56d3758b13c311ddd6025.tar.gz
more robustness (particularly cross-thread) for SimulateXAttr wrapper
Diffstat (limited to 'fs/xattrs.py')
-rw-r--r--fs/xattrs.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/fs/xattrs.py b/fs/xattrs.py
index 27a8abc..e17d048 100644
--- a/fs/xattrs.py
+++ b/fs/xattrs.py
@@ -31,6 +31,7 @@ except ImportError:
from fs.path import *
from fs.errors import *
from fs.wrapfs import WrapFS
+from fs.base import synchronize
def ensure_xattrs(fs):
@@ -42,9 +43,9 @@ def ensure_xattrs(fs):
"""
try:
# This attr doesn't have to exist, None should be returned by default
- fs.getxattr("/","testingx-xattr")
+ fs.getxattr("/","testing-xattr")
return fs
- except Exception:
+ except (AttributeError,UnsupportedError):
return SimulateXAttr(fs)
@@ -52,7 +53,7 @@ class SimulateXAttr(WrapFS):
"""FS wrapper class that simulates xattr support.
The following methods are supplied for manipulating extended attributes:
- * xattrs: list all extended attribute names for a path
+ * listxattrs: list all extended attribute names for a path
* getxattr: get an xattr of a path by name
* setxattr: set an xattr of a path by name
* delxattr: delete an xattr of a path by name
@@ -83,7 +84,10 @@ class SimulateXAttr(WrapFS):
"""Retrieve the xattr dictionary for the given path."""
attr_path = self._get_attr_path(path)
if self.wrapped_fs.exists(attr_path):
- return pickle.loads(self.wrapped_fs.getcontents(attr_path))
+ try:
+ return pickle.loads(self.wrapped_fs.getcontents(attr_path))
+ except EOFError:
+ return {}
else:
return {}
@@ -92,6 +96,7 @@ class SimulateXAttr(WrapFS):
attr_path = self._get_attr_path(path)
self.wrapped_fs.setcontents(attr_path, pickle.dumps(attrs))
+ @synchronize
def setxattr(self, path, key, value):
"""Set an extended attribute on the given path."""
if not self.exists(path):
@@ -100,6 +105,7 @@ class SimulateXAttr(WrapFS):
attrs[key] = str(value)
self._set_attr_dict(path, attrs)
+ @synchronize
def getxattr(self, path, key, default=None):
"""Retrieve an extended attribute for the given path."""
if not self.exists(path):
@@ -107,6 +113,7 @@ class SimulateXAttr(WrapFS):
attrs = self._get_attr_dict(path)
return attrs.get(key, default)
+ @synchronize
def delxattr(self, path, key):
if not self.exists(path):
raise ResourceNotFoundError(path)