Răsfoiți Sursa

Fix a traceback when the "repositories" option contains both strings and key/value pairs (#794).

Dan Helfman 1 an în urmă
părinte
comite
8b49a59aff
4 a modificat fișierele cu 14 adăugiri și 15 ștergeri
  1. 3 0
      NEWS
  2. 5 2
      borgmatic/config/normalize.py
  3. 1 1
      setup.py
  4. 5 12
      tests/unit/config/test_normalize.py

+ 3 - 0
NEWS

@@ -1,3 +1,6 @@
+1.8.6.dev0
+ * #794: Fix a traceback when the "repositories" option contains both strings and key/value pairs.
+
 1.8.5
  * #701: Add a "skip_actions" option to skip running particular actions, handy for append-only or
    checkless configurations. See the documentation for more information:

+ 5 - 2
borgmatic/config/normalize.py

@@ -192,7 +192,7 @@ def normalize(config_filename, config):
     # Upgrade remote repositories to ssh:// syntax, required in Borg 2.
     repositories = config.get('repositories')
     if repositories:
-        if isinstance(repositories[0], str):
+        if any(isinstance(repository, str) for repository in repositories):
             logs.append(
                 logging.makeLogRecord(
                     dict(
@@ -202,7 +202,10 @@ def normalize(config_filename, config):
                     )
                 )
             )
-            config['repositories'] = [{'path': repository} for repository in repositories]
+            config['repositories'] = [
+                {'path': repository} if isinstance(repository, str) else repository
+                for repository in repositories
+            ]
             repositories = config['repositories']
 
         config['repositories'] = []

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 
-VERSION = '1.8.5'
+VERSION = '1.8.6.dev0'
 
 
 setup(

+ 5 - 12
tests/unit/config/test_normalize.py

@@ -216,6 +216,11 @@ def test_normalize_sections_with_only_scalar_raises():
             {'repositories': [{'path': '/repo'}]},
             True,
         ),
+        (
+            {'repositories': [{'path': 'first'}, 'file:///repo']},
+            {'repositories': [{'path': 'first'}, {'path': '/repo'}]},
+            True,
+        ),
         (
             {'repositories': [{'path': 'foo@bar:/repo', 'label': 'foo'}]},
             {'repositories': [{'path': 'ssh://foo@bar/repo', 'label': 'foo'}]},
@@ -251,15 +256,3 @@ def test_normalize_applies_hard_coded_normalization_to_config(
         assert logs
     else:
         assert logs == []
-
-
-def test_normalize_raises_error_if_repository_data_is_not_consistent():
-    flexmock(module).should_receive('normalize_sections').and_return([])
-
-    with pytest.raises(TypeError):
-        module.normalize(
-            'test.yaml',
-            {
-                'repositories': [{'path': 'foo@bar:/repo', 'label': 'foo'}, 'file:///repo'],
-            },
-        )