Commit e65bcdc9 authored by Harald Sitter's avatar Harald Sitter 🚔

[about-distro] OSRelease to collect "extra" keys

Summary:
previously we'd ignore unknown keys. in preparation of moving to a library
let's instead collect them so a user of the class may also access them.

- new extraKeys helper and extraValue getters
- extras are always processed as String
- test case fixture extended + now has comment variants (previously
  comments couldn't be tested since they were skipped as either comments
  or invalid/unknown lines. with the extras API we can actually verify
  that they do not incorrectly end up getting parsed

Test Plan: test still passes

Reviewers: apol

Reviewed By: apol

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D19976
parent 620be5cd
......@@ -49,6 +49,8 @@ private Q_SLOTS:
QCOMPARE(r.variant(), "Test Edition");
QCOMPARE(r.variantId(), "test");
QCOMPARE(r.logo(), "start-here-test");
QCOMPARE(r.extraKeys(), QStringList({"DEBIAN_BTS"}));
QCOMPARE(r.extraValue("DEBIAN_BTS"), "debbugs://bugs.debian.org/");
}
};
......
......@@ -13,6 +13,9 @@ SUPPORT_URL="https://url.support"
BUG_REPORT_URL="https://url.bugs"
PRIVACY_POLICY_URL="https://url.privacy"
BUILD_ID="105.5"
# comment
VARIANT="Test Edition"
VARIANT_ID=test
# indented comment
LOGO=start-here-test
DEBIAN_BTS="debbugs://bugs.debian.org/"
......@@ -140,8 +140,11 @@ public:
continue;
}
// os-release explicitly allows for vendor specific aditions. We have no
// interest in those right now.
// os-release explicitly allows for vendor specific additions, we'll
// collect them as strings and exposes them as "extras".
QString parsedValue;
setVar(&parsedValue, value);
extras.insert(key, parsedValue);
}
}
......@@ -163,6 +166,8 @@ public:
QString variant;
QString variantId;
QString logo;
QHash<QString, QString> extras;
};
OSRelease::OSRelease(const QString &filePath)
......@@ -265,6 +270,16 @@ QString OSRelease::logo() const
return d->logo;
}
QStringList OSRelease::extraKeys() const
{
return d->extras.keys();
}
QString OSRelease::extraValue(const QString &key) const
{
return d->extras.value(key);
}
QString OSRelease::defaultFilePath()
{
if (QFile::exists(QStringLiteral("/etc/os-release"))) {
......
......@@ -86,6 +86,14 @@ public:
/** @see https://www.freedesktop.org/software/systemd/man/os-release.html#LOGO= */
QString logo() const;
/**
* Extra keys are keys that are unknown or specified by a vendor.
*/
QStringList extraKeys() const;
/** Extra values are values assoicated with keys that are unknown. */
QString extraValue(const QString &key) const;
private:
static QString defaultFilePath();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment