1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 01:37:20 +00:00

Merge pull request #2900 from imsodin/fix-2899

Only compare contents when chunker params match (fixes #2899)
This commit is contained in:
TW 2017-08-06 01:20:24 +02:00 committed by GitHub
commit eee4542f3b
2 changed files with 21 additions and 18 deletions

View file

@ -1021,18 +1021,19 @@ def contents_changed(item1, item2):
def compare_content(path, item1, item2): def compare_content(path, item1, item2):
if contents_changed(item1, item2): if contents_changed(item1, item2):
if item1.get('deleted'): if item1.get('deleted'):
return ('added {:>13}'.format(format_file_size(sum_chunk_size(item2)))) return 'added {:>13}'.format(format_file_size(sum_chunk_size(item2)))
elif item2.get('deleted'): if item2.get('deleted'):
return ('removed {:>11}'.format(format_file_size(sum_chunk_size(item1)))) return 'removed {:>11}'.format(format_file_size(sum_chunk_size(item1)))
else: if not can_compare_chunk_ids:
chunk_ids1 = {c.id for c in item1.chunks} return 'modified'
chunk_ids2 = {c.id for c in item2.chunks} chunk_ids1 = {c.id for c in item1.chunks}
added_ids = chunk_ids2 - chunk_ids1 chunk_ids2 = {c.id for c in item2.chunks}
removed_ids = chunk_ids1 - chunk_ids2 added_ids = chunk_ids2 - chunk_ids1
added = sum_chunk_size(item2, added_ids) removed_ids = chunk_ids1 - chunk_ids2
removed = sum_chunk_size(item1, removed_ids) added = sum_chunk_size(item2, added_ids)
return ('{:>9} {:>9}'.format(format_file_size(added, precision=1, sign=True), removed = sum_chunk_size(item1, removed_ids)
format_file_size(-removed, precision=1, sign=True))) return '{:>9} {:>9}'.format(format_file_size(added, precision=1, sign=True),
format_file_size(-removed, precision=1, sign=True))
def compare_directory(item1, item2): def compare_directory(item1, item2):
if item2.get('deleted') and not item1.get('deleted'): if item2.get('deleted') and not item1.get('deleted'):

View file

@ -3276,9 +3276,10 @@ def test_basic_functionality(self):
self.cmd('create', self.repository_location + '::test1a', 'input') self.cmd('create', self.repository_location + '::test1a', 'input')
self.cmd('create', '--chunker-params', '16,18,17,4095', self.repository_location + '::test1b', 'input') self.cmd('create', '--chunker-params', '16,18,17,4095', self.repository_location + '::test1b', 'input')
def do_asserts(output, archive): def do_asserts(output, can_compare_ids):
# File contents changed (deleted and replaced with a new file) # File contents changed (deleted and replaced with a new file)
assert 'B input/file_replaced' in output change = 'B' if can_compare_ids else '{:<19}'.format('modified')
assert '{} input/file_replaced'.format(change) in output
# File unchanged # File unchanged
assert 'input/file_unchanged' not in output assert 'input/file_unchanged' not in output
@ -3307,9 +3308,10 @@ def do_asserts(output, archive):
# The inode has two links and the file contents changed. Borg # The inode has two links and the file contents changed. Borg
# should notice the changes in both links. However, the symlink # should notice the changes in both links. However, the symlink
# pointing to the file is not changed. # pointing to the file is not changed.
assert '0 B input/empty' in output change = '0 B' if can_compare_ids else '{:<19}'.format('modified')
assert '{} input/empty'.format(change) in output
if are_hardlinks_supported(): if are_hardlinks_supported():
assert '0 B input/hardlink_contents_changed' in output assert '{} input/hardlink_contents_changed'.format(change) in output
if are_symlinks_supported(): if are_symlinks_supported():
assert 'input/link_target_contents_changed' not in output assert 'input/link_target_contents_changed' not in output
@ -3336,9 +3338,9 @@ def do_asserts(output, archive):
if are_hardlinks_supported(): if are_hardlinks_supported():
assert 'input/hardlink_target_replaced' not in output assert 'input/hardlink_target_replaced' not in output
do_asserts(self.cmd('diff', self.repository_location + '::test0', 'test1a'), '1a') do_asserts(self.cmd('diff', self.repository_location + '::test0', 'test1a'), True)
# We expect exit_code=1 due to the chunker params warning # We expect exit_code=1 due to the chunker params warning
do_asserts(self.cmd('diff', self.repository_location + '::test0', 'test1b', exit_code=1), '1b') do_asserts(self.cmd('diff', self.repository_location + '::test0', 'test1b', exit_code=1), False)
def test_sort_option(self): def test_sort_option(self):
self.cmd('init', '--encryption=repokey', self.repository_location) self.cmd('init', '--encryption=repokey', self.repository_location)