diff options
Diffstat (limited to 'rdiff-backup/rdiff_backup/Hardlink.py')
-rw-r--r-- | rdiff-backup/rdiff_backup/Hardlink.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/rdiff-backup/rdiff_backup/Hardlink.py b/rdiff-backup/rdiff_backup/Hardlink.py index 855c512..1dddbbb 100644 --- a/rdiff-backup/rdiff_backup/Hardlink.py +++ b/rdiff-backup/rdiff_backup/Hardlink.py @@ -31,15 +31,15 @@ source side should only transmit inode information. """ from __future__ import generators -import cPickle -import Globals, Time, rpath, log, robust, errno +import Globals, Time, log, robust, errno # The keys in this dictionary are (inode, devloc) pairs. The values -# are a pair (index, remaining_links, dest_key) where index is the -# rorp index of the first such linked file, remaining_links is the -# number of files hard linked to this one we may see, and key is +# are a pair (index, remaining_links, dest_key, sha1sum) where index +# is the rorp index of the first such linked file, remaining_links is +# the number of files hard linked to this one we may see, and key is # either (dest_inode, dest_devloc) or None, and represents the -# hardlink info of the existing file on the destination. +# hardlink info of the existing file on the destination. Finally +# sha1sum is the hash of the file if it exists, or None. _inode_index = None def initialize_dictionaries(): @@ -64,7 +64,9 @@ def add_rorp(rorp, dest_rorp = None): if not dest_rorp: dest_key = None elif dest_rorp.getnumlinks() == 1: dest_key = "NA" else: dest_key = get_inode_key(dest_rorp) - _inode_index[rp_inode_key] = (rorp.index, rorp.getnumlinks(), dest_key) + digest = rorp.has_sha1() and rorp.get_sha1() or None + _inode_index[rp_inode_key] = (rorp.index, rorp.getnumlinks(), + dest_key, digest) return rp_inode_key def del_rorp(rorp): @@ -73,12 +75,12 @@ def del_rorp(rorp): rp_inode_key = get_inode_key(rorp) val = _inode_index.get(rp_inode_key) if not val: return - index, remaining, dest_key = val + index, remaining, dest_key, digest = val if remaining == 1: del _inode_index[rp_inode_key] return 1 else: - _inode_index[rp_inode_key] = (index, remaining-1, dest_key) + _inode_index[rp_inode_key] = (index, remaining-1, dest_key, digest) return 0 def rorp_eq(src_rorp, dest_rorp): @@ -95,11 +97,11 @@ def rorp_eq(src_rorp, dest_rorp): if src_rorp.getnumlinks() < dest_rorp.getnumlinks(): return 0 src_key = get_inode_key(src_rorp) - index, remaining, dest_key = _inode_index[src_key] + index, remaining, dest_key, digest = _inode_index[src_key] if dest_key == "NA": # Allow this to be ok for first comparison, but not any # subsequent ones - _inode_index[src_key] = (index, remaining, None) + _inode_index[src_key] = (index, remaining, None, None) return 1 return dest_key == get_inode_key(dest_rorp) @@ -114,6 +116,10 @@ def get_link_index(rorp): """Return first index on target side rorp is already linked to""" return _inode_index[get_inode_key(rorp)][0] +def get_sha1(rorp): + """Return sha1 digest of what rorp is linked to""" + return _inode_index[get_inode_key(rorp)][3] + def link_rp(diff_rorp, dest_rpath, dest_root = None): """Make dest_rpath into a link using link flag in diff_rorp""" if not dest_root: dest_root = dest_rpath # use base of dest_rpath |