diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-28 12:28:15 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-28 12:28:15 +0100 |
commit | 16b83018bb013bffc8364814385acf34281d5064 (patch) | |
tree | 64df71e63accb5e817acc25d6594d8041919ddb0 /ishtar_common/utils.py | |
parent | 69babd64fbe12417008d4ea8ba1f40560187f682 (diff) | |
download | Ishtar-16b83018bb013bffc8364814385acf34281d5064.tar.bz2 Ishtar-16b83018bb013bffc8364814385acf34281d5064.zip |
Clean media: fix potential encode errors
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 2156d4f95..e6bc38237 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -1031,7 +1031,14 @@ def rename_and_simplify_media_name(full_path_name, rename=True): :param rename: rename file if True (default: True) :return: new full path name (or old if not changed), modified """ - if not os.path.exists(full_path_name) or not os.path.isfile(full_path_name): + try: + exists = os.path.exists(full_path_name) + is_file = os.path.isfile(full_path_name) + except UnicodeEncodeError: + full_path_name = full_path_name.encode('utf-8') + exists = os.path.exists(full_path_name) + is_file = os.path.isfile(full_path_name) + if not exists or not is_file: return full_path_name, False path, current_name, name = simplify_name(full_path_name, @@ -1206,8 +1213,12 @@ def try_fix_file(filename, make_copy=True): path, current_name, simplified_ref_name = simplify_name( filename, check_existing=False) + try: + dirs = list(os.listdir(path)) + except UnicodeDecodeError: + dirs = list(os.listdir(path.encode('utf-8'))) # check existing files in the path - for file in sorted(list(os.listdir(path))): + for file in sorted(dirs): full_file = os.sep.join([path, file]) if not os.path.isfile(full_file): # must be a file continue |