diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-03-08 14:27:53 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-17 13:21:27 +0200 |
commit | 71a3fc4f3af6ddddd570c1a8f7cb11ad3805d558 (patch) | |
tree | 820174192d71dc1d9919b927d9d7a8fdee78e321 /ishtar_common/utils.py | |
parent | ac02eeb7de1f734352c7013694d8f8346758c26a (diff) | |
download | Ishtar-71a3fc4f3af6ddddd570c1a8f7cb11ad3805d558.tar.bz2 Ishtar-71a3fc4f3af6ddddd570c1a8f7cb11ad3805d558.zip |
Rename media: fix potential encoding issue
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 18 |
1 files changed, 8 insertions, 10 deletions
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 |