Skip to content

Commit

Permalink
Handles UTF-8 filenames in geologos archives
Browse files Browse the repository at this point in the history
  • Loading branch information
noirbizarre committed Jul 3, 2019
1 parent d739918 commit 845722b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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)

Expand Down
11 changes: 9 additions & 2 deletions udata/core/spatial/commands.py
Expand Up @@ -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='<filename>')
def load_logos(filename):
Expand All @@ -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):
Expand Down

0 comments on commit 845722b

Please sign in to comment.