license class: try alt encoding when copying license file
PATCH v2 1/1 license class: try alt encoding when copying license file
From: Armin Kuster <[email protected]>
v2: fix typos
Try another encoding if utf-8 fails in file read.
line 20 of irdadump.c contains: University of Tromsø
fixes:
WARNING: irda-utils-0.9.18-r0 do_populate_lic: Could not copy license file /home/akuster/oss/maint/openembedded-core/build/tmp-glibc/work/aarch64-mvl-linux/irda-utils/0.9.18-r0/irda-utils-0.9.18/irdadump/irdadump.c to /home/akuster/oss/maint/openembedded-core/build/tmp-glibc/work/aarch64-mvl-linux/irda-utils/0.9.18-r0/license-destdir/irda-utils/irdadump.c: 'utf-8' codec can't decode byte 0xf8 in position 874: invalid start byte
--- meta/classes/license.bbclass | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
meta/classes/license.bbclass +12 -2
@@ -386,9 +386,19 @@ def copy_license_files(lic_files_paths, destdir): if begin_idx is None and end_idx is None: shutil.copyfile(src, dst) else: - with open(src, 'r') as src_f: + with open(src, "r", encoding="utf-8") as src_f: + try: + src_chunk = ''.join(src_f.readlines()[begin_idx:end_idx]) + except UnicodeDecodeError: + bb.debug(1, "Failed to copy license file %s using UTF-8 encoding" + " trying with iso8859-1" % src) + src_f.close() + with open(src, "r", encoding="iso8859-1") as src_f: + src_chunk = ''.join(src_f.readlines()[begin_idx:end_idx]) + + with open(dst, 'w') as dst_f: - dst_f.write(''.join(src_f.readlines()[begin_idx:end_idx])) + dst_f.write(src_chunk) except Exception as e: bb.warn("Could not copy license file %s to %s: %s" % (src, dst, e))
Signature · 1 line
2.7.4
Quoted 2 lines · Armin Kuster
Try another encoding if utf-8 fails in file read.
I sent a patch for this last week (just taking bytes instead of guessing encodings, which will still fail if the encoding isn't UTF-8 or 8859-1)
Ross
Quoted 7 lines · Ross
On 12 March 2017 at 15:27, Armin Kuster <[email protected] <mailto:[email protected]>> wrote:
Try another encoding if utf-8 fails in file read.
hl
I sent a patch for this last week (just taking bytes instead of guessing encodings, which will still fail if the encoding isn't UTF-8 or 8859-1)
Your patch works great in this case. I was working in a old tree.
- armin
Quoted 2 lines
Ross