]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/vfs.py
compat.hexstr: add and use
[bup.git] / lib / bup / vfs.py
index 3ab0e044f5623c5085736dfef6b60b192f368b0e..3c97d21c7943166f4094e7a2eb285b42f93e488b 100644 (file)
@@ -53,10 +53,10 @@ 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
 from time import localtime, strftime
-import exceptions, re, sys
+import re, sys
 
 from bup import git, metadata, vint
-from bup.compat import range
+from bup.compat import hexstr, range
 from bup.git import BUP_CHUNKED, cp, get_commit_items, parse_commit, tree_decode
 from bup.helpers import debug2, last
 from bup.metadata import Metadata
@@ -64,12 +64,17 @@ from bup.vint import read_bvec, write_bvec
 from bup.vint import read_vint, write_vint
 from bup.vint import read_vuint, write_vuint
 
+if sys.version_info[0] < 3:
+    from exceptions import IOError as py_IOError
+else:
+    py_IOError = IOError
+
 # We currently assume that it's always appropriate to just forward IOErrors
 # to a remote client.
 
-class IOError(exceptions.IOError):
+class IOError(py_IOError):
     def __init__(self, errno, message, terminus=None):
-        exceptions.IOError.__init__(self, errno, message)
+        py_IOError.__init__(self, errno, message)
         self.terminus = terminus
 
 def write_ioerror(port, ex):
@@ -480,7 +485,7 @@ def tree_data_and_bupm(repo, oid):
         data = ''.join(it)
         assert item_t == 'tree'
     elif item_t != 'tree':
-        raise Exception('%r is not a tree or commit' % oid.encode('hex'))
+        raise Exception('%s is not a tree or commit' % hexstr(oid))
     for _, mangled_name, sub_oid in tree_decode(data):
         if mangled_name == '.bupm':
             return data, sub_oid
@@ -507,12 +512,12 @@ def readlink(repo, item):
     target from the repository if necessary."""
     assert repo
     assert S_ISLNK(item_mode(item))
+    if isinstance(item, FakeLink):
+        return item.target
     if isinstance(item.meta, Metadata):
         target = item.meta.symlink_target
         if target:
             return target
-    elif isinstance(item, FakeLink):
-        return item.target
     return _readlink(repo, item.oid)
 
 def _compute_item_size(repo, item):
@@ -521,6 +526,8 @@ def _compute_item_size(repo, item):
         size = _normal_or_chunked_file_size(repo, item.oid)
         return size
     if S_ISLNK(mode):
+        if isinstance(item, FakeLink):
+            return len(item.target)
         return len(_readlink(repo, item.oid))
     return 0