update-alternatives: correctly escape PATHs when updating FILES_${PN}

The recently added support for updating FILES based on the file renames
that are happening here is using a regex replace, but failed to
properly escape the search pattern (the full path). This manifests itself
in FILES not being updated as soon as the full path contains any
character that has a special meaning, e.g. '+'.

In other words an original path (alt_target in the code) like
    /opt/poky/2.6+snapshot/sysroots/i686-pokysdk-linux/sbin/losetup
can't be matched, and hence we fail to update FILES with the new value,
causing packaging errors.

Fix by using re.escape() on the original path before passing into re.sub()

Fixes: 5c23fe378732 ("update-alternatives: try to update FILES_${PN} when
renaming a file"), or bcb3e7b7f8 in poky.git

[YOCTO #13058]

(From OE-Core rev: 126743162397e4145902b3f127f2dafd80a8a49b)

Signed-off-by: André Draszik <andre.draszik@jci.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
André Draszik
2019-02-05 02:32:29 +00:00
committed by Richard Purdie
parent 34ec0fce5f
commit d05823086d

View File

@@ -138,12 +138,12 @@ python apply_update_alternative_renames () {
if not update_alternatives_enabled(d):
return
from re import sub
import re
def update_files(alt_target, alt_target_rename, pkg, d):
f = d.getVar('FILES_' + pkg)
if f:
f = sub(r'(^|\s)%s(\s|$)' % alt_target, r'\1%s\2' % alt_target_rename, f)
f = re.sub(r'(^|\s)%s(\s|$)' % re.escape (alt_target), r'\1%s\2' % alt_target_rename, f)
d.setVar('FILES_' + pkg, f)
# Check for deprecated usage...