]> code.ossystems Code Review - openembedded-core.git/commitdiff
os-release: sanitise VERSION_ID field
authorJoshua Lock <joshua.g.lock@intel.com>
Wed, 24 Feb 2016 14:52:14 +0000 (14:52 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 28 Feb 2016 11:32:37 +0000 (11:32 +0000)
Per os-release(5) the VERSION_ID field should be:

  a lower-case string (mostly numeric, no spaces or other characters
  outside of 0-9, a-z, ".", "_" and "-")

Do some string manipulation to try and ensure the VERSION_ID field
we write is valid.

Signed-off-by: Joshua Lock <joshua.g.lock@intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/recipes-core/os-release/os-release.bb

index 58364ea249190e417042ac1f1801e47a0554b293..f519addd8d64041bd9d3d2c0ba4f768ff78c8876 100644 (file)
@@ -23,11 +23,20 @@ PRETTY_NAME = "${DISTRO_NAME} ${VERSION}"
 BUILD_ID ?= "${DATETIME}"
 BUILD_ID[vardepsexclude] = "DATETIME"
 
+def sanitise_version(ver):
+    # VERSION_ID should be (from os-release(5)):
+    #    lower-case string (mostly numeric, no spaces or other characters
+    #    outside of 0-9, a-z, ".", "_" and "-")
+    ret = ver.replace('+', '-').replace(' ','_')
+    return ret.lower()
+
 python do_compile () {
     import shutil
     with open(d.expand('${B}/os-release'), 'w') as f:
         for field in d.getVar('OS_RELEASE_FIELDS', True).split():
             value = d.getVar(field, True)
+            if value and field == 'VERSION_ID':
+                value = sanitise_version(value)
             if value:
                 f.write('{0}="{1}"\n'.format(field, value))
 }