From 142dc04fd4ecf19a9e24131f80d82e54b0df5ce1 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Thu, 2 Sep 2021 14:19:37 +0200 Subject: [PATCH] app-misc/ca-certificates: ignore UnicodeEncodeError when opening file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that we started encoding strings to unicode by default, we should also take care of corner cases, where LC_CYPTE is set to a different value from the systemd default value in `/etc/locale.gen`. For example, under a build environment with `LC_CTYPE=C`, when the UTF-8 file name is `AC_Ra�z_Certic�mara_S.A..pem`, build fails like that. ``` Traceback (most recent call last): File "/var/tmp/portage/app-misc/ca-certificates-3.27.1-r2/files/certdata2pem.py", line 127, in f = open(fname, 'w') UnicodeEncodeError: 'ascii' codec can't encode character '\xed' in position 5: ordinal not in range(128) * ERROR: app-misc/ca-certificates-3.27.1-r2::coreos failed (compile phase): ``` To fix that, encode filename with system encoding when opening the file. --- ...cates-3.27.1-r2.ebuild => ca-certificates-3.27.1-r3.ebuild} | 0 .../app-misc/ca-certificates/files/certdata2pem.py | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) rename sdk_container/src/third_party/coreos-overlay/app-misc/ca-certificates/{ca-certificates-3.27.1-r2.ebuild => ca-certificates-3.27.1-r3.ebuild} (100%) diff --git a/sdk_container/src/third_party/coreos-overlay/app-misc/ca-certificates/ca-certificates-3.27.1-r2.ebuild b/sdk_container/src/third_party/coreos-overlay/app-misc/ca-certificates/ca-certificates-3.27.1-r3.ebuild similarity index 100% rename from sdk_container/src/third_party/coreos-overlay/app-misc/ca-certificates/ca-certificates-3.27.1-r2.ebuild rename to sdk_container/src/third_party/coreos-overlay/app-misc/ca-certificates/ca-certificates-3.27.1-r3.ebuild diff --git a/sdk_container/src/third_party/coreos-overlay/app-misc/ca-certificates/files/certdata2pem.py b/sdk_container/src/third_party/coreos-overlay/app-misc/ca-certificates/files/certdata2pem.py index bf73757639..d8e9d51996 100644 --- a/sdk_container/src/third_party/coreos-overlay/app-misc/ca-certificates/files/certdata2pem.py +++ b/sdk_container/src/third_party/coreos-overlay/app-misc/ca-certificates/files/certdata2pem.py @@ -124,7 +124,8 @@ for obj in objects: fname = fname.encode('latin1').decode('unicode_escape').encode('latin1').decode('utf8') except (UnicodeEncodeError, UnicodeDecodeError): pass - f = open(fname, 'w') + + f = open(fname.encode(encoding=sys.getfilesystemencoding(), errors="ignore"), 'w') f.write("-----BEGIN CERTIFICATE-----\n") # obj['CKA_VALUE'] is a string of octals like '\060\311…', # with a number not greater than octal 377 (which is 255,