1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-23 16:26:29 +00:00

key export: fix exception handling

export_paperkey also must not get an already existing directory.
This commit is contained in:
Thomas Waldmann 2024-07-19 19:55:14 +02:00
parent 5eecdfa133
commit 4e6238e7d3
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -93,20 +93,19 @@ def do_key_export(self, args, repository):
"""Export the repository key for backup""" """Export the repository key for backup"""
manager = KeyManager(repository) manager = KeyManager(repository)
manager.load_keyblob() manager.load_keyblob()
if args.paper: try:
manager.export_paperkey(args.path) if args.path is not None and os.path.isdir(args.path):
else: # on Windows, Python raises PermissionError instead of IsADirectoryError
try: # (like on Unix) if the file to open is actually a directory.
if args.path is not None and os.path.isdir(args.path): raise IsADirectoryError
# on Windows, Python raises PermissionError instead of IsADirectoryError if args.paper:
# (like on Unix) if the file to open is actually a directory. manager.export_paperkey(args.path)
raise IsADirectoryError elif args.qr:
if args.qr: manager.export_qr(args.path)
manager.export_qr(args.path) else:
else: manager.export(args.path)
manager.export(args.path) except IsADirectoryError:
except IsADirectoryError: raise CommandError(f"'{args.path}' must be a file, not a directory")
raise CommandError(f"'{args.path}' must be a file, not a directory")
@with_repository(lock=False, exclusive=False, manifest=False, cache=False) @with_repository(lock=False, exclusive=False, manifest=False, cache=False)
def do_key_import(self, args, repository): def do_key_import(self, args, repository):