From 71a3fc4f3af6ddddd570c1a8f7cb11ad3805d558 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 8 Mar 2019 14:27:53 +0100 Subject: Rename media: fix potential encoding issue --- ishtar_common/utils.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 33d1f5bec..d0bfee02a 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -1194,7 +1194,11 @@ def simplify_name(full_path_name, check_existing=False): if match: new_name = name.replace(match.group(), '') full_new_name = os.sep.join([path, new_name + ext]) - if not check_existing or not os.path.isfile(full_new_name): + try: + is_file = os.path.isfile(full_new_name) + except UnicodeEncodeError: + is_file = os.path.isfile(full_new_name.encode('utf-8')) + if not check_existing or not is_file: # do not take the place of another file name = new_name[:] break @@ -1211,23 +1215,17 @@ def rename_and_simplify_media_name(full_path_name, rename=True): :return: new full path name (or old if not changed), modified """ try: - is_str = False exists = os.path.exists(full_path_name) is_file = os.path.isfile(full_path_name) except UnicodeEncodeError: - is_str = True - full_path_name = full_path_name.encode('utf-8') - exists = os.path.exists(full_path_name) - is_file = os.path.isfile(full_path_name) + full_path_name_unicode = full_path_name.encode('utf-8') + exists = os.path.exists(full_path_name_unicode) + is_file = os.path.isfile(full_path_name_unicode) if not exists or not is_file: return full_path_name, False path, current_name, name = simplify_name(full_path_name, check_existing=True) - if is_str: - full_path_name = full_path_name.decode('utf-8') - name = name.decode('utf-8') - path = path.decode('utf-8') if current_name == name: return full_path_name, False -- cgit v1.2.3