Repository: borgbackup/borg

Issue:
borg key export confusing error msg
from IRC:
```
borg key export REPO PATH
```

if the second argument is a directory it will throw an error.

I understand it needs a file, but the error it throws may be confusing to other users. :)


Discussion:

Patch:
diff --git a/LICENSE b/LICENSE
index 698326d4..051e44c6 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (C) 2015-2019 The Borg Collective (see AUTHORS file)
+Copyright (C) 2015-2018 The Borg Collective (see AUTHORS file)
 Copyright (C) 2010-2014 Jonas Borgström <jonas@borgstrom.se>
 All rights reserved.
 
diff --git a/docs/conf.py b/docs/conf.py
index d80336e3..200e5423 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -42,7 +42,7 @@
 
 # General information about the project.
 project = 'Borg - Deduplicating Archiver'
-copyright = u'2010-2014 Jonas Borgström, 2015-2019 The Borg Collective (see AUTHORS file)'
+copyright = u'2010-2014 Jonas Borgström, 2015-2018 The Borg Collective (see AUTHORS file)'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
diff --git a/src/borg/archiver.py b/src/borg/archiver.py
index 207585e2..66e3760c 100644
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -325,10 +325,14 @@ def do_key_export(self, args, repository):
             if not args.path:
                 self.print_error("output file to export key to expected")
                 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
 
     @with_repository(lock=False, exclusive=False, manifest=False, cache=False)


Test patch:
diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py
index 88eee312..de5431d6 100644
--- a/src/borg/testsuite/archiver.py
+++ b/src/borg/testsuite/archiver.py
@@ -2639,6 +2639,14 @@ def test_key_export_qr(self):
         assert export_contents.startswith('<!doctype 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):
         export_file = self.output_path + '/exported'
         self.cmd('init', self.repository_location, '--encryption', 'keyfile')