aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-08-31 15:28:46 +1200
committerPaul Eggleton <paul.eggleton@linux.intel.com>2016-09-06 21:58:58 +1200
commitd4044adfd000c8b67ed9b523bfbfc49ca97e8fa7 (patch)
tree645f54db95020060d39b3563c4ce2db66b4c6d2c
parent55bb6816aca39bfa25d4f7e2158a57a5f0ac1cca (diff)
downloadopenembedded-core-contrib-d4044adfd000c8b67ed9b523bfbfc49ca97e8fa7.tar.gz
lib/oe/patch: handle non-UTF8 encoding when reading patches
When extracting patches from a git repository with PATCHTOOL = "git" we cannot assume that all patches will be UTF-8 formatted, so as with other places in this module, try latin-1 if utf-8 fails. This fixes UnicodeDecodeError running devtool update-recipe or devtool finish on the openssl recipe. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
-rw-r--r--meta/lib/oe/patch.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index cad50157dd..05e0faa5b7 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -415,16 +415,24 @@ class GitApplyTree(PatchTree):
out = runcmd(["sh", "-c", " ".join(shellcmd)], tree)
if out:
for srcfile in out.split():
- patchlines = []
- outfile = None
- with open(srcfile, 'r') as f:
- for line in f:
- if line.startswith(GitApplyTree.patch_line_prefix):
- outfile = line.split()[-1].strip()
- continue
- if line.startswith(GitApplyTree.ignore_commit_prefix):
- continue
- patchlines.append(line)
+ for encoding in ['utf-8', 'latin-1']:
+ patchlines = []
+ outfile = None
+ try:
+ with open(srcfile, 'r', encoding=encoding) as f:
+ for line in f:
+ if line.startswith(GitApplyTree.patch_line_prefix):
+ outfile = line.split()[-1].strip()
+ continue
+ if line.startswith(GitApplyTree.ignore_commit_prefix):
+ continue
+ patchlines.append(line)
+ except UnicodeDecodeError:
+ continue
+ break
+ else:
+ raise PatchError('Unable to find a character encoding to decode %s' % srcfile)
+
if not outfile:
outfile = os.path.basename(srcfile)
with open(os.path.join(outdir, outfile), 'w') as of: