mirror of
https://git.yoctoproject.org/poky
synced 2026-06-02 01:19:52 +00:00
lib/oe/lsb: sanitise the distro identifier
The distribution identifier is often used to create filenames, so it needs to be safe to use as a filename. Whilst most distributions have e.g. Fedora or Debian as their name, it is possible that the name contains special characters. To ensure this doesn't cause a problem strip out any non-alphanumerics from the distribution name before returning it. [ YOCTO #9443 ] (From OE-Core rev: 8a96a7207561e00eb92e4fb69e7340f20bfa2053) Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
9262d2ff39
commit
175263e584
@@ -62,6 +62,8 @@ def distro_identifier(adjust_hook=None):
|
|||||||
"""Return a distro identifier string based upon lsb_release -ri,
|
"""Return a distro identifier string based upon lsb_release -ri,
|
||||||
with optional adjustment via a hook"""
|
with optional adjustment via a hook"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
lsb_data = release_dict()
|
lsb_data = release_dict()
|
||||||
if lsb_data:
|
if lsb_data:
|
||||||
distro_id, release = lsb_data['Distributor ID'], lsb_data['Release']
|
distro_id, release = lsb_data['Distributor ID'], lsb_data['Release']
|
||||||
@@ -76,6 +78,9 @@ def distro_identifier(adjust_hook=None):
|
|||||||
distro_id, release = adjust_hook(distro_id, release)
|
distro_id, release = adjust_hook(distro_id, release)
|
||||||
if not distro_id:
|
if not distro_id:
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
|
# Filter out any non-alphanumerics
|
||||||
|
distro_id = re.sub(r'\W', '', distro_id)
|
||||||
|
|
||||||
if release:
|
if release:
|
||||||
id_str = '{0}-{1}'.format(distro_id, release)
|
id_str = '{0}-{1}'.format(distro_id, release)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user