From 845722ba0f07410f56017c3745bd12361a9d23c9 Mon Sep 17 00:00:00 2001 From: Axel Haustant Date: Wed, 3 Jul 2019 12:58:20 +0200 Subject: [PATCH] Handles UTF-8 filenames in geologos archives --- CHANGELOG.md | 1 + udata/core/spatial/commands.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49845e4830..18a016d5bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Rename og:image target :warning: this will break your custom theme, please rename your logo image file to `logo-social.png` instead of `logo-600x600.png` [#2217](https://github.com/opendatateam/udata/pull/2217) - Don't automatically overwrite `last_update` field if manually set [#2020](https://github.com/opendatateam/udata/pull/2220) +- Handle UTF-8 filenames in `spatial load_logos` command [#2223](https://github.com/opendatateam/udata/pull/2223) ## 1.6.12 (2019-06-26) diff --git a/udata/core/spatial/commands.py b/udata/core/spatial/commands.py index e8e1e81524..32a0725f5e 100644 --- a/udata/core/spatial/commands.py +++ b/udata/core/spatial/commands.py @@ -121,6 +121,12 @@ def load(filename, drop=False): shutil.rmtree(tmp.path('translations')) # Not in use for now. +def safe_tarinfo(tarinfo): + '''make a tarinfo utf8-compatible''' + tarinfo.name = tarinfo.name.decode('utf8') + return tarinfo + + @grp.command() @click.argument('filename', metavar='') def load_logos(filename): @@ -135,8 +141,9 @@ def load_logos(filename): log.info('Extracting GeoLogos bundle') with contextlib.closing(lzma.LZMAFile(filename)) as xz: - with tarfile.open(fileobj=xz) as f: - f.extractall(tmp.root) + with tarfile.open(fileobj=xz, encoding='utf8') as tar: + decoded = (safe_tarinfo(t) for t in tar.getmembers()) + tar.extractall(tmp.root, members=decoded) log.info('Moving to the final location and cleaning up') if os.path.exists(logos.root):