소스 검색

Fix an error when "data" check time files are accessed without getting upgraded first (#711, #713).

Dan Helfman 1 년 전
부모
커밋
6098005f5d
3개의 변경된 파일31개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 0
      NEWS
  2. 1 1
      borgmatic/borg/check.py
  3. 28 0
      tests/unit/borg/test_check.py

+ 2 - 0
NEWS

@@ -3,6 +3,8 @@
  * #697, #712: Extract borgmatic configuration from backup via "bootstrap" action—even when
  * #697, #712: Extract borgmatic configuration from backup via "bootstrap" action—even when
    borgmatic has no configuration yet!
    borgmatic has no configuration yet!
  * #669: Add sample systemd user service for running borgmatic as a non-root user.
  * #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
 1.7.14
  * #484: Add a new verbosity level (-2) to disable output entirely (for console, syslog, log file,
  * #484: Add a new verbosity level (-2) to disable output entirely (for console, syslog, log file,

+ 1 - 1
borgmatic/borg/check.py

@@ -342,7 +342,7 @@ def upgrade_check_times(location_config, borg_repository_id):
         temporary_path = f'{old_path}.temp'
         temporary_path = f'{old_path}.temp'
 
 
         if not os.path.isfile(old_path) and not os.path.isfile(temporary_path):
         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}')
         logger.debug(f'Upgrading archives check time from {old_path} to {new_path}')
 
 

+ 28 - 0
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())
     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():
 def test_upgrade_check_times_skips_missing_check_paths():
     flexmock(module).should_receive('make_check_time_path').and_return(
     flexmock(module).should_receive('make_check_time_path').and_return(
         '~/.borgmatic/checks/1234/archives/all'
         '~/.borgmatic/checks/1234/archives/all'