1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-31 00:39:46 +00:00

lib/oe/patch: handle encoding differences in patch files

With Python 3, the encoding of a file is significant; several recipes in
OE-Core have patches which are not fully utf-8 decodable e.g. man,
lrzsz, and gstreamer1.0-libav, leading to errors when using devtool's
modify, upgrade or extract subcommands on these recipes. To work around
this, try reading the patch file as utf-8 first and if that fails try
latin-1 before giving up.

(From OE-Core rev: 7f4d7a6f51569954e204f110827a8ce256bcdc68)

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Paul Eggleton
2016-07-07 11:57:09 +12:00
committed by Richard Purdie
parent f465039737
commit 029e3ebcb2
+56 -42
View File
@@ -117,43 +117,50 @@ class PatchSet(object):
return None return None
return os.sep.join(filesplit[striplevel:]) return os.sep.join(filesplit[striplevel:])
copiedmode = False for encoding in ['utf-8', 'latin-1']:
filelist = [] try:
with open(patchfile) as f: copiedmode = False
for line in f: filelist = []
if line.startswith('--- '): with open(patchfile) as f:
patchpth = patchedpath(line) for line in f:
if not patchpth: if line.startswith('--- '):
break patchpth = patchedpath(line)
if copiedmode: if not patchpth:
addedfile = patchpth break
else: if copiedmode:
removedfile = patchpth addedfile = patchpth
elif line.startswith('+++ '): else:
addedfile = patchedpath(line) removedfile = patchpth
if not addedfile: elif line.startswith('+++ '):
break addedfile = patchedpath(line)
elif line.startswith('*** '): if not addedfile:
copiedmode = True break
removedfile = patchedpath(line) elif line.startswith('*** '):
if not removedfile: copiedmode = True
break removedfile = patchedpath(line)
else: if not removedfile:
removedfile = None break
addedfile = None else:
removedfile = None
addedfile = None
if addedfile and removedfile: if addedfile and removedfile:
if removedfile == '/dev/null': if removedfile == '/dev/null':
mode = 'A' mode = 'A'
elif addedfile == '/dev/null': elif addedfile == '/dev/null':
mode = 'D' mode = 'D'
else: else:
mode = 'M' mode = 'M'
if srcdir: if srcdir:
fullpath = os.path.abspath(os.path.join(srcdir, addedfile)) fullpath = os.path.abspath(os.path.join(srcdir, addedfile))
else: else:
fullpath = addedfile fullpath = addedfile
filelist.append((fullpath, mode)) filelist.append((fullpath, mode))
except UnicodeDecodeError:
continue
break
else:
raise PatchError('Unable to decode %s' % patchfile)
return filelist return filelist
@@ -280,12 +287,19 @@ class GitApplyTree(PatchTree):
""" """
Extract just the header lines from the top of a patch file Extract just the header lines from the top of a patch file
""" """
lines = [] for encoding in ['utf-8', 'latin-1']:
with open(patchfile, 'r') as f: lines = []
for line in f.readlines(): try:
if line.startswith('Index: ') or line.startswith('diff -') or line.startswith('---'): with open(patchfile, 'r', encoding=encoding) as f:
break for line in f:
lines.append(line) if line.startswith('Index: ') or line.startswith('diff -') or line.startswith('---'):
break
lines.append(line)
except UnicodeDecodeError:
continue
break
else:
raise PatchError('Unable to find a character encoding to decode %s' % patchfile)
return lines return lines
@staticmethod @staticmethod