encode filenames as bytes to handle all locale setups

This was failing on environments that did not have any LANG or LC_* locale
variables set.  This is a valid setup, and is common in headless setups, so
it needs to be handled.

This also adds a new pass of the test suite without the locale env vars set
so that this situation is also tests on gitlab-ci, not only gpjenkins.

The error this caused was:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 6-18: ordinal not in range(128)
This commit is contained in:
Hans-Christoph Steiner 2017-04-03 20:24:00 +02:00
parent 4d50ab9bad
commit e58ad330f4
4 changed files with 31 additions and 26 deletions

View file

@ -436,14 +436,14 @@ def make_v0(apps, apks, repodir, repodict, requestsdict):
and common.config['make_current_version_link'] \
and repodir == 'repo': # only create these
namefield = common.config['current_version_name_source']
sanitized_name = re.sub('''[ '"&%?+=/]''', '', app.get(namefield))
apklinkname = sanitized_name + '.apk'
current_version_path = os.path.join(repodir, current_version_file)
sanitized_name = re.sub(b'''[ '"&%?+=/]''', b'', app.get(namefield).encode('utf-8'))
apklinkname = sanitized_name + b'.apk'
current_version_path = os.path.join(repodir, current_version_file).encode('utf-8', 'surrogateescape')
if os.path.islink(apklinkname):
os.remove(apklinkname)
os.symlink(current_version_path, apklinkname)
# also symlink gpg signature, if it exists
for extension in ('.asc', '.sig'):
for extension in (b'.asc', b'.sig'):
sigfile_path = current_version_path + extension
if os.path.exists(sigfile_path):
siglinkname = apklinkname + extension