diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 18622df8e..0a0112f76 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -363,9 +363,6 @@ class Archiver: if args.paper: manager.export_paperkey(args.path) else: - if not args.path: - self.print_error("output file to export key to expected") - return EXIT_ERROR try: if args.qr: manager.export_qr(args.path) diff --git a/src/borg/crypto/keymanager.py b/src/borg/crypto/keymanager.py index 146d9455d..675c57635 100644 --- a/src/borg/crypto/keymanager.py +++ b/src/borg/crypto/keymanager.py @@ -75,20 +75,29 @@ class KeyManager: return data def store_keyfile(self, target): - with open(target, 'w') as fd: + with dash_open(target, 'w') as fd: fd.write(self.get_keyfile_data()) def export(self, path): + if path is None: + path = '-' + self.store_keyfile(path) def export_qr(self, path): - with open(path, 'wb') as fd: + if path is None: + path = '-' + + with dash_open(path, 'wb') as fd: key_data = self.get_keyfile_data() html = pkgutil.get_data('borg', 'paperkey.html') html = html.replace(b'', key_data.encode() + b'') fd.write(html) def export_paperkey(self, path): + if path is None: + path = '-' + def grouped(s): ret = '' i = 0 @@ -118,11 +127,8 @@ class KeyManager: export += '{0:2d}: {1} - {2}\n'.format(idx, grouped(bin_to_hex(binline)), checksum) binary = binary[18:] - if path: - with open(path, 'w') as fd: - fd.write(export) - else: - print(export) + with dash_open(path, 'w') as fd: + fd.write(export) def import_keyfile(self, args): file_id = KeyfileKey.FILE_ID