Skip to content
Snippets Groups Projects
Commit 79f9dae5 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Merge branch '138-surrogate-error-handling' into 'develop'

Resolve "Importer chokes on files with bad unicode characters"

Closes #138

See merge request funkwhale/funkwhale!309
parents 03eb2be2 252aa31b
No related branches found
No related tags found
No related merge requests found
......@@ -82,10 +82,31 @@ class Command(BaseCommand):
try:
for import_path in options["path"]:
matching += glob.glob(import_path, **glob_kwargs)
matching = sorted(list(set(matching)))
raw_matching = sorted(list(set(matching)))
except TypeError:
raise Exception("You need Python 3.5 to use the --recursive flag")
matching = []
for m in raw_matching:
# In some situations, the path is encoded incorrectly on the filesystem
# so we filter out faulty paths and display a warning to the user.
# see https://code.eliotberriot.com/funkwhale/funkwhale/issues/138
try:
m.encode("utf-8")
matching.append(m)
except UnicodeEncodeError:
try:
previous = matching[-1]
except IndexError:
previous = None
self.stderr.write(
self.style.WARNING(
"[warning] Ignoring undecodable path. Previous ok file was {}".format(
previous
)
)
)
if options["in_place"]:
self.stdout.write(
"Checking imported paths against settings.MUSIC_DIRECTORY_PATH"
......
Raise a warning instead of crashing when getting a broken path in file import (#138)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment