summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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
commit4cf926ad278a752091f1680b6370f6361465326d (patch)
tree64df71e63accb5e817acc25d6594d8041919ddb0
parente2f32bddc51bc6c5cfff73df62760f252c37b711 (diff)
downloadIshtar-4cf926ad278a752091f1680b6370f6361465326d.tar.bz2
Ishtar-4cf926ad278a752091f1680b6370f6361465326d.zip
Clean media: fix potential encode errors
-rw-r--r--ishtar_common/utils.py15
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