浏览代码

Fix "borgmatic borg key ..." to pass parameters to Borg in correct order (#515).

Dan Helfman 3 年之前
父节点
当前提交
0e6b425ac5
共有 3 个文件被更改,包括 18 次插入4 次删除
  1. 1 0
      NEWS
  2. 7 4
      borgmatic/borg/borg.py
  3. 10 0
      tests/unit/borg/test_borg.py

+ 1 - 0
NEWS

@@ -6,6 +6,7 @@
    once for each configured repository instead of once per configuration file. Additionally, the
    "repositories" interpolated variable has been changed to "repository", containing the path to the
    current repository for the hook.
+ * #515: Fix "borgmatic borg key ..." to pass parameters to Borg in correct order.
  * #516: Fix handling of TERM signal to exit borgmatic, not just forward the signal to Borg.
  * #517: Fix borgmatic exit code (so it's zero) when initial Borg calls fail but later retries
    succeed.

+ 7 - 4
borgmatic/borg/borg.py

@@ -21,17 +21,20 @@ def run_arbitrary_borg(
 
     try:
         options = options[1:] if options[0] == '--' else options
-        borg_command = options[0]
-        command_options = tuple(options[1:])
+
+        # Borg's "key" command has a sub-command ("export", etc.) that must follow it.
+        command_options_start_index = 2 if options[0] == 'key' else 1
+        borg_command = tuple(options[:command_options_start_index])
+        command_options = tuple(options[command_options_start_index:])
     except IndexError:
-        borg_command = None
+        borg_command = ()
         command_options = ()
 
     repository_archive = '::'.join((repository, archive)) if repository and archive else repository
 
     full_command = (
         (local_path,)
-        + ((borg_command,) if borg_command else ())
+        + borg_command
         + ((repository_archive,) if borg_command and repository_archive else ())
         + command_options
         + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())

+ 10 - 0
tests/unit/borg/test_borg.py

@@ -121,3 +121,13 @@ def test_run_arbitrary_borg_without_borg_specific_parameters_does_not_raise():
     module.run_arbitrary_borg(
         repository='repo', storage_config={}, options=[],
     )
+
+
+def test_run_arbitrary_borg_passes_key_sub_command_to_borg_before_repository():
+    flexmock(module).should_receive('execute_command').with_args(
+        ('borg', 'key', 'export', 'repo'), output_log_level=logging.WARNING, borg_local_path='borg',
+    )
+
+    module.run_arbitrary_borg(
+        repository='repo', storage_config={}, options=['key', 'export'],
+    )