summaryrefslogtreecommitdiff
path: root/pyanidb/hash.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyanidb/hash.py')
-rw-r--r--pyanidb/hash.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/pyanidb/hash.py b/pyanidb/hash.py
index a748f9e..4aab45f 100644
--- a/pyanidb/hash.py
+++ b/pyanidb/hash.py
@@ -12,7 +12,7 @@ class File:
self.cached = False
if cache:
self.read_cache()
- if sum([not hasattr(self, a) for a in algorithms]):
+ if False in [hasattr(self, a) for a in algorithms]:
self.cached = False
h = multihash.hash_file(name, algorithms)
for a in algorithms:
@@ -20,6 +20,8 @@ class File:
self.write_cache()
def read_cache(self):
+ if not xattr:
+ return
cache = dict([(n[13:], xattr.getxattr(self.name, n)) for n in xattr.listxattr(self.name) if n.startswith('user.pyanidb.')])
if 'mtime' not in cache or str(int(self.mtime)) != cache.pop('mtime'):
return
@@ -28,6 +30,8 @@ class File:
self.cached = True
def write_cache(self):
+ if not xattr:
+ return
try:
self.clear_cache()
xattr.setxattr(self.name, 'user.pyanidb.mtime', str(int(self.mtime)))