1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-25 07:23:28 +00:00

archiver: key_cmds: check if key path is a directory before opening

On Windows, Python raises PermissionError instead of IsADirectoryError (like on Unix) if the file to open is actually a directory.
See https://github.com/python/cpython/issues/87261
This commit is contained in:
Rayyan Ansari 2022-11-29 17:33:29 +00:00
parent fff2c21e65
commit 9e9b94615e
2 changed files with 12 additions and 0 deletions

View file

@ -101,6 +101,8 @@ def do_key_export(self, args, repository):
manager.export_paperkey(args.path) manager.export_paperkey(args.path)
else: else:
try: try:
if os.path.isdir(args.path):
raise IsADirectoryError
if args.qr: if args.qr:
manager.export_qr(args.path) manager.export_qr(args.path)
else: else:

View file

@ -163,6 +163,16 @@ def test_key_export_directory(self):
self.cmd(f"--repo={self.repository_location}", "key", "export", export_directory, exit_code=EXIT_ERROR) self.cmd(f"--repo={self.repository_location}", "key", "export", export_directory, exit_code=EXIT_ERROR)
def test_key_export_qr_directory(self):
export_directory = self.output_path + "/exported"
os.mkdir(export_directory)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(
f"--repo={self.repository_location}", "key", "export", "--qr-html", 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(f"--repo={self.repository_location}", "rcreate", KF_ENCRYPTION) self.cmd(f"--repo={self.repository_location}", "rcreate", KF_ENCRYPTION)