Browse Source

Merge pull request #4378 from milkey-mouse/fix-4348

Emit user-friendly error if repo key is exported to a directory
TW 6 years ago
parent
commit
86eca03d81
2 changed files with 16 additions and 4 deletions
  1. 8 4
      src/borg/archiver.py
  2. 8 0
      src/borg/testsuite/archiver.py

+ 8 - 4
src/borg/archiver.py

@@ -326,10 +326,14 @@ class Archiver:
             if not args.path:
             if not args.path:
                 self.print_error("output file to export key to expected")
                 self.print_error("output file to export key to expected")
                 return EXIT_ERROR
                 return EXIT_ERROR
-            if args.qr:
-                manager.export_qr(args.path)
-            else:
-                manager.export(args.path)
+            try:
+                if args.qr:
+                    manager.export_qr(args.path)
+                else:
+                    manager.export(args.path)
+            except IsADirectoryError:
+                self.print_error("'{}' must be a file, not a directory".format(args.path))
+                return EXIT_ERROR
         return EXIT_SUCCESS
         return EXIT_SUCCESS
 
 
     @with_repository(lock=False, exclusive=False, manifest=False, cache=False)
     @with_repository(lock=False, exclusive=False, manifest=False, cache=False)

+ 8 - 0
src/borg/testsuite/archiver.py

@@ -2654,6 +2654,14 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         assert export_contents.startswith('<!doctype html>')
         assert export_contents.startswith('<!doctype html>')
         assert export_contents.endswith('</html>')
         assert export_contents.endswith('</html>')
 
 
+    def test_key_export_directory(self):
+        export_directory = self.output_path + '/exported'
+        os.mkdir(export_directory)
+
+        self.cmd('init', self.repository_location, '--encryption', 'repokey')
+
+        self.cmd('key', 'export', self.repository_location, export_directory, exit_code=EXIT_ERROR)
+
     def test_key_import_errors(self):
     def test_key_import_errors(self):
         export_file = self.output_path + '/exported'
         export_file = self.output_path + '/exported'
         self.cmd('init', self.repository_location, '--encryption', 'keyfile')
         self.cmd('init', self.repository_location, '--encryption', 'keyfile')