diff options
author | Vyacheslav Yurkov <uvv.mail@gmail.com> | 2020-04-30 16:03:40 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-05-03 15:41:40 +0100 |
commit | 4d98363d59cd422b6357148bc0862256ca2076cb (patch) | |
tree | 815b6a6439bad72f944771de11c1b72c707f4aff /meta/recipes-core/os-release | |
parent | 7d2814a2b0426fede93e34b1ff9b83348b3fc3a2 (diff) | |
download | poky-4d98363d59cd422b6357148bc0862256ca2076cb.tar.gz |
os-release: sanitize required fields
Currently only VERSION_ID field is sanitized, but os-release (5) has
more fields with the same requirement. Moreover, those fields come
unquoted in most distributions, because quotes are not needed for a
values without whitespaces.
(From OE-Core rev: f451c68667cca8a1883ceddb66dd2834b18252a8)
Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core/os-release')
-rw-r--r-- | meta/recipes-core/os-release/os-release.bb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/meta/recipes-core/os-release/os-release.bb b/meta/recipes-core/os-release/os-release.bb index d5793c6fed..a29d678125 100644 --- a/meta/recipes-core/os-release/os-release.bb +++ b/meta/recipes-core/os-release/os-release.bb | |||
@@ -13,6 +13,7 @@ do_configure[noexec] = "1" | |||
13 | # Other valid fields: BUILD_ID ID_LIKE ANSI_COLOR CPE_NAME | 13 | # Other valid fields: BUILD_ID ID_LIKE ANSI_COLOR CPE_NAME |
14 | # HOME_URL SUPPORT_URL BUG_REPORT_URL | 14 | # HOME_URL SUPPORT_URL BUG_REPORT_URL |
15 | OS_RELEASE_FIELDS = "ID ID_LIKE NAME VERSION VERSION_ID PRETTY_NAME" | 15 | OS_RELEASE_FIELDS = "ID ID_LIKE NAME VERSION VERSION_ID PRETTY_NAME" |
16 | OS_RELEASE_UNQUOTED_FIELDS = "ID VERSION_ID VARIANT_ID" | ||
16 | 17 | ||
17 | ID = "${DISTRO}" | 18 | ID = "${DISTRO}" |
18 | NAME = "${DISTRO_NAME}" | 19 | NAME = "${DISTRO_NAME}" |
@@ -22,8 +23,8 @@ PRETTY_NAME = "${DISTRO_NAME} ${VERSION}" | |||
22 | BUILD_ID ?= "${DATETIME}" | 23 | BUILD_ID ?= "${DATETIME}" |
23 | BUILD_ID[vardepsexclude] = "DATETIME" | 24 | BUILD_ID[vardepsexclude] = "DATETIME" |
24 | 25 | ||
25 | def sanitise_version(ver): | 26 | def sanitise_value(ver): |
26 | # VERSION_ID should be (from os-release(5)): | 27 | # unquoted fields like VERSION_ID should be (from os-release(5)): |
27 | # lower-case string (mostly numeric, no spaces or other characters | 28 | # lower-case string (mostly numeric, no spaces or other characters |
28 | # outside of 0-9, a-z, ".", "_" and "-") | 29 | # outside of 0-9, a-z, ".", "_" and "-") |
29 | ret = ver.replace('+', '-').replace(' ','_') | 30 | ret = ver.replace('+', '-').replace(' ','_') |
@@ -32,11 +33,14 @@ def sanitise_version(ver): | |||
32 | python do_compile () { | 33 | python do_compile () { |
33 | with open(d.expand('${B}/os-release'), 'w') as f: | 34 | with open(d.expand('${B}/os-release'), 'w') as f: |
34 | for field in d.getVar('OS_RELEASE_FIELDS').split(): | 35 | for field in d.getVar('OS_RELEASE_FIELDS').split(): |
36 | unquotedFields = d.getVar('OS_RELEASE_UNQUOTED_FIELDS').split() | ||
35 | value = d.getVar(field) | 37 | value = d.getVar(field) |
36 | if value and field == 'VERSION_ID': | ||
37 | value = sanitise_version(value) | ||
38 | if value: | 38 | if value: |
39 | f.write('{0}="{1}"\n'.format(field, value)) | 39 | if field in unquotedFields: |
40 | value = sanitise_value(value) | ||
41 | f.write('{0}={1}\n'.format(field, value)) | ||
42 | else: | ||
43 | f.write('{0}="{1}"\n'.format(field, value)) | ||
40 | } | 44 | } |
41 | do_compile[vardeps] += "${OS_RELEASE_FIELDS}" | 45 | do_compile[vardeps] += "${OS_RELEASE_FIELDS}" |
42 | 46 | ||