From 4e6238e7d35f86ef46cdde5eb2351819e4e6d105 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 19 Jul 2024 19:55:14 +0200 Subject: [PATCH] key export: fix exception handling export_paperkey also must not get an already existing directory. --- src/borg/archiver/key_cmds.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/borg/archiver/key_cmds.py b/src/borg/archiver/key_cmds.py index 9dec5a5d2..1a7b4769a 100644 --- a/src/borg/archiver/key_cmds.py +++ b/src/borg/archiver/key_cmds.py @@ -93,20 +93,19 @@ class KeysMixIn: """Export the repository key for backup""" manager = KeyManager(repository) manager.load_keyblob() - if args.paper: - manager.export_paperkey(args.path) - else: - try: - if args.path is not None and os.path.isdir(args.path): - # on Windows, Python raises PermissionError instead of IsADirectoryError - # (like on Unix) if the file to open is actually a directory. - raise IsADirectoryError - if args.qr: - manager.export_qr(args.path) - else: - manager.export(args.path) - except IsADirectoryError: - raise CommandError(f"'{args.path}' must be a file, not a directory") + try: + if args.path is not None and os.path.isdir(args.path): + # on Windows, Python raises PermissionError instead of IsADirectoryError + # (like on Unix) if the file to open is actually a directory. + raise IsADirectoryError + if args.paper: + manager.export_paperkey(args.path) + elif args.qr: + manager.export_qr(args.path) + else: + manager.export(args.path) + except IsADirectoryError: + raise CommandError(f"'{args.path}' must be a file, not a directory") @with_repository(lock=False, exclusive=False, manifest=False, cache=False) def do_key_import(self, args, repository):