Fix #138: Raise a warning instead of crashing when getting a broken path in file import
This commit is contained in:
parent
03eb2be2b8
commit
252aa31b11
|
@ -82,10 +82,31 @@ class Command(BaseCommand):
|
||||||
try:
|
try:
|
||||||
for import_path in options["path"]:
|
for import_path in options["path"]:
|
||||||
matching += glob.glob(import_path, **glob_kwargs)
|
matching += glob.glob(import_path, **glob_kwargs)
|
||||||
matching = sorted(list(set(matching)))
|
raw_matching = sorted(list(set(matching)))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
raise Exception("You need Python 3.5 to use the --recursive flag")
|
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"]:
|
if options["in_place"]:
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
"Checking imported paths against settings.MUSIC_DIRECTORY_PATH"
|
"Checking imported paths against settings.MUSIC_DIRECTORY_PATH"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Raise a warning instead of crashing when getting a broken path in file import (#138)
|
Loading…
Reference in New Issue