Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse owner changes in borg diff results #553

Merged
merged 2 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/vorta/views/diff_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
21 changes: 21 additions & 0 deletions tests/test_archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down