]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/vfs.py
vfs: import EINVAL for FileReader seek and include size in exception
[bup.git] / lib / bup / vfs.py
index 14598ffc33bdef32eaa1fbf36e96c52aca650536..124c3f0462a47f6a621e137ee6233ae15f5baead 100644 (file)
@@ -48,7 +48,7 @@ item.coid.
 
 from __future__ import absolute_import, print_function
 from collections import namedtuple
-from errno import ELOOP, ENOENT, ENOTDIR
+from errno import EINVAL, ELOOP, ENOENT, ENOTDIR
 from itertools import chain, dropwhile, groupby, tee
 from random import randrange
 from stat import S_IFDIR, S_IFLNK, S_IFREG, S_ISDIR, S_ISLNK, S_ISREG
@@ -162,10 +162,8 @@ class _FileReader(object):
         return self._size
         
     def seek(self, ofs):
-        if ofs < 0:
-            raise IOError(errno.EINVAL, 'Invalid argument')
-        if ofs > self._compute_size():
-            raise IOError(errno.EINVAL, 'Invalid argument')
+        if ofs < 0 or ofs > self._compute_size():
+            raise IOError(EINVAL, 'Invalid seek offset: %d' % ofs)
         self.ofs = ofs
 
     def tell(self):
@@ -253,20 +251,20 @@ def clear_cache():
 def is_valid_cache_key(x):
     """Return logically true if x looks like it could be a valid cache key
     (with respect to structure).  Current valid cache entries:
-      (repo-id, path, parent, want_meta, dref) -> resolution
+      res:... -> resolution
       commit_oid -> commit
       commit_oid + ':r' -> rev-list
          i.e. rev-list -> {'.', commit, '2012...', next_commit, ...}
     """
     # Suspect we may eventually add "(container_oid, name) -> ...", and others.
     x_t = type(x)
-    if x_t is tuple:
-        return len(x) == 5
     if x_t is bytes:
         if len(x) == 20:
             return True
         if len(x) == 22 and x.endswith(b':r'):
             return True
+        if x.startswith('res:'):
+            return True
 
 def cache_get(key):
     global _cache
@@ -759,7 +757,10 @@ def contents(repo, item, names=None, want_meta=True):
         yield x
 
 def _resolve_path(repo, path, parent=None, want_meta=True, deref=False):
-    cache_key = (repo.id(), tuple(path), parent, bool(want_meta), bool(deref))
+    cache_key = b'res:%d%d%d:%s\0%s' \
+                % (bool(want_meta), bool(deref), repo.id(),
+                   ('/'.join(x[0] for x in parent) if parent else ''),
+                   '/'.join(path))
     resolution = cache_get(cache_key)
     if resolution:
         return resolution