1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-24 23:13:25 +00:00

transfer: all hardlinks have chunks, maybe chunks_healty, hlid

Item.hlid: same id, same hardlink (xxh64 digest)
Item.hardlink_master: not used for new archives any more
Item.source: not used for hardlink slaves any more
This commit is contained in:
Thomas Waldmann 2022-05-04 01:58:24 +02:00
parent 01f72d15b4
commit e4a97ea8cc
3 changed files with 18 additions and 2 deletions

View file

@ -347,6 +347,20 @@ def do_transfer(self, args, *,
def upgrade_item(item):
"""upgrade item as needed, get rid of legacy crap"""
if item.get('hardlink_master', True) and 'source' not in item and hardlinkable(item.mode):
item._dict['hlid'] = hlid = hashlib.sha256(item._dict['path'])
hardlink_masters[hlid] = (item._dict.get('chunks'), item._dict.get('chunks_healthy'))
elif 'source' in item and hardlinkable(item.mode):
item._dict['hlid'] = hlid = hashlib.sha256(item._dict['source'])
chunks, chunks_healthy = hardlink_masters.get(hlid, (None, None))
if chunks is not None:
item._dict['chunks'] = chunks
for chunk_id, _, _ in chunks:
cache.chunk_incref(chunk_id, archive.stats)
if chunks_healthy is not None:
item._dict['chunks_healthy'] = chunks
item._dict.pop('source') # not used for hardlinks any more, replaced by hlid
item._dict.pop('hardlink_master', None) # not used for hardlinks any more, replaced by hlid
item._dict.pop('acl', None) # remove remnants of bug in attic <= 0.13
item.get_size(memorize=True) # if not already present: compute+remember size for items with chunks
return item
@ -371,6 +385,7 @@ def upgrade_compressed_chunk(chunk):
else:
if not dry_run:
print(f"{name}: copying archive to destination repo...")
hardlink_masters = {}
other_archive = Archive(other_repository, other_key, other_manifest, name)
archive = Archive(repository, key, manifest, name, cache=cache, create=True) if not dry_run else None
for item in other_archive.iter_items():

View file

@ -1,5 +1,5 @@
# this set must be kept complete, otherwise the RobustUnpacker might malfunction:
ITEM_KEYS = frozenset(['path', 'source', 'rdev', 'chunks', 'chunks_healthy', 'hardlink_master',
ITEM_KEYS = frozenset(['path', 'source', 'rdev', 'chunks', 'chunks_healthy', 'hardlink_master', 'hlid',
'mode', 'user', 'group', 'uid', 'gid', 'mtime', 'atime', 'ctime', 'birthtime', 'size',
'xattrs', 'bsdflags', 'acl_nfs4', 'acl_access', 'acl_default', 'acl_extended',
'part'])

View file

@ -181,7 +181,8 @@ class Item(PropDict):
# compatibility note: this is a new feature, in old archives size will be missing.
size = PropDict._make_property('size', int)
hardlink_master = PropDict._make_property('hardlink_master', bool)
hlid = PropDict._make_property('hlid', bytes) # hard link id: same value means same hard link.
hardlink_master = PropDict._make_property('hardlink_master', bool) # legacy
chunks = PropDict._make_property('chunks', (list, type(None)), 'list or None')
chunks_healthy = PropDict._make_property('chunks_healthy', (list, type(None)), 'list or None')