From 6098005f5d01c322d99a9dd6842f8aa7b5a1d9bb Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 19 Jun 2023 23:07:57 -0700 Subject: [PATCH] Fix an error when "data" check time files are accessed without getting upgraded first (#711, #713). --- NEWS | 2 ++ borgmatic/borg/check.py | 2 +- tests/unit/borg/test_check.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 50391a8..8f3ffc2 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ * #697, #712: Extract borgmatic configuration from backup via "bootstrap" action—even when borgmatic has no configuration yet! * #669: Add sample systemd user service for running borgmatic as a non-root user. + * #711, #713: Fix an error when "data" check time files are accessed without getting upgraded + first. 1.7.14 * #484: Add a new verbosity level (-2) to disable output entirely (for console, syslog, log file, diff --git a/borgmatic/borg/check.py b/borgmatic/borg/check.py index 0c417ac..0e54a2c 100644 --- a/borgmatic/borg/check.py +++ b/borgmatic/borg/check.py @@ -342,7 +342,7 @@ def upgrade_check_times(location_config, borg_repository_id): temporary_path = f'{old_path}.temp' if not os.path.isfile(old_path) and not os.path.isfile(temporary_path): - return + continue logger.debug(f'Upgrading archives check time from {old_path} to {new_path}') diff --git a/tests/unit/borg/test_check.py b/tests/unit/borg/test_check.py index a1044ba..7920116 100644 --- a/tests/unit/borg/test_check.py +++ b/tests/unit/borg/test_check.py @@ -544,6 +544,34 @@ def test_upgrade_check_times_renames_old_check_paths_to_all(): module.upgrade_check_times(flexmock(), flexmock()) +def test_upgrade_check_times_renames_data_check_paths_when_archives_paths_are_already_upgraded(): + base_path = '~/.borgmatic/checks/1234' + flexmock(module).should_receive('make_check_time_path').with_args( + object, object, 'archives', 'all' + ).and_return(f'{base_path}/archives/all') + flexmock(module).should_receive('make_check_time_path').with_args( + object, object, 'data', 'all' + ).and_return(f'{base_path}/data/all') + flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/archives').and_return( + False + ) + flexmock(module.os.path).should_receive('isfile').with_args( + f'{base_path}/archives.temp' + ).and_return(False) + flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/data').and_return( + True + ) + flexmock(module.os).should_receive('rename').with_args( + f'{base_path}/data', f'{base_path}/data.temp' + ).once() + flexmock(module.os).should_receive('mkdir').with_args(f'{base_path}/data').once() + flexmock(module.os).should_receive('rename').with_args( + f'{base_path}/data.temp', f'{base_path}/data/all' + ).once() + + module.upgrade_check_times(flexmock(), flexmock()) + + def test_upgrade_check_times_skips_missing_check_paths(): flexmock(module).should_receive('make_check_time_path').and_return( '~/.borgmatic/checks/1234/archives/all'