mirror of
https://github.com/borgbase/vorta
synced 2025-02-20 13:26:54 +00:00
Parse owner changes in borg diff results (#553)
* Parse owner changes in borg diff results * Report owner-only changes as "modified" in diff
This commit is contained in:
parent
1f8f42e23f
commit
85eb725059
2 changed files with 30 additions and 6 deletions
|
@ -63,20 +63,23 @@ def parse_line(line):
|
|||
significand = size_change.group(1)
|
||||
unit = size_change.group(2)
|
||||
size = calc_size(significand, unit)
|
||||
full_path_index = size_change.end(0)
|
||||
rest_of_line = line[size_change.end(0):]
|
||||
else:
|
||||
size = 0
|
||||
rest_of_line = line
|
||||
|
||||
permission_change = re.search(r' *(\[.{24}\]) ', line)
|
||||
owner_change = re.search(r' *(\[[^:]+:[^\]]+ -> [^:]+:[^\]]+\]) ', rest_of_line)
|
||||
if owner_change:
|
||||
rest_of_line = rest_of_line[owner_change.end(0):]
|
||||
|
||||
permission_change = re.search(r' *(\[.{24}\]) ', rest_of_line)
|
||||
if permission_change:
|
||||
change_type = permission_change.group(1)
|
||||
full_path_index = permission_change.end(0)
|
||||
rest_of_line = rest_of_line[permission_change.end(0):]
|
||||
else:
|
||||
change_type = "modified"
|
||||
|
||||
if size_change and permission_change:
|
||||
full_path_index = max(size_change.end(0), permission_change.end(0))
|
||||
full_path = line[full_path_index:]
|
||||
full_path = rest_of_line.lstrip(' ')
|
||||
|
||||
dir, name = os.path.split(full_path)
|
||||
|
||||
|
|
|
@ -173,6 +173,27 @@ def test_archive_diff(qapp, qtbot, mocker, borg_json_output, monkeypatch):
|
|||
(0, 'changed', 'link', 'some/changed')),
|
||||
(' +77.8 kB -77.8 kB some/changed/file',
|
||||
(77800, 'modified', 'file', 'some/changed')),
|
||||
(' +77.8 kB -77.8 kB [-rw-rw-rw- -> -rw-r--r--] some/changed/file',
|
||||
(77800, '[-rw-rw-rw- -> -rw-r--r--]', 'file', 'some/changed')),
|
||||
('[-rw-rw-rw- -> -rw-r--r--] some/changed/file',
|
||||
(0, '[-rw-rw-rw- -> -rw-r--r--]', 'file', 'some/changed')),
|
||||
|
||||
('added directory some/changed/dir',
|
||||
(0, 'added', 'dir', 'some/changed')),
|
||||
('removed directory some/changed/dir',
|
||||
(0, 'removed', 'dir', 'some/changed')),
|
||||
|
||||
# Example from https://github.com/borgbase/vorta/issues/521
|
||||
('[user:user -> nfsnobody:nfsnobody] home/user/arrays/test.txt',
|
||||
(0, 'modified', 'test.txt', 'home/user/arrays')),
|
||||
|
||||
# Very short owner change, to check stripping whitespace from file path
|
||||
('[a:a -> b:b] home/user/arrays/test.txt',
|
||||
(0, 'modified', 'test.txt', 'home/user/arrays')),
|
||||
|
||||
# All file-related changes in one test
|
||||
(' +77.8 kB -77.8 kB [user:user -> nfsnobody:nfsnobody] [-rw-rw-rw- -> -rw-r--r--] home/user/arrays/test.txt',
|
||||
(77800, '[-rw-rw-rw- -> -rw-r--r--]', 'test.txt', 'home/user/arrays')),
|
||||
])
|
||||
def test_archive_diff_parser(line, expected):
|
||||
files_with_attributes, nested_file_list = vorta.views.diff_result.parse_diff_lines([line])
|
||||
|
|
Loading…
Reference in a new issue