From 95c60b0cbd21d9ebccf17ff1e6366ceb032fdb06 Mon Sep 17 00:00:00 2001 From: drew2a Date: Mon, 28 Mar 2022 15:00:09 +0200 Subject: [PATCH] Add UnicodeEncodeError to except block --- src/tribler/gui/utilities.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tribler/gui/utilities.py b/src/tribler/gui/utilities.py index 1f1ddf79fe3..8442ee137f0 100644 --- a/src/tribler/gui/utilities.py +++ b/src/tribler/gui/utilities.py @@ -266,14 +266,14 @@ def is_dir_writable(path): :return: True if writable, False otherwise """ - random_name = "tribler_temp_delete_me_" + str(uuid4()) + directory = Path(path) + random_file = directory / f'tribler_temp_delete_me_{uuid4()}' try: - if not os.path.exists(path): - os.makedirs(path) - open(os.path.join(path, random_name), 'w') - os.remove(os.path.join(path, random_name)) - except OSError as os_error: - return False, os_error + directory.mkdir(parents=True, exist_ok=True) + random_file.open('w') + random_file.unlink() + except (OSError, UnicodeEncodeError) as e: + return False, e else: return True, None