Skip to content

Commit

Permalink
[config] don't match local and global unit config. MER#956
Browse files Browse the repository at this point in the history
If unit is registered as repository-local, do not remove it when there is no
corresponding global unit

Signed-off-by: Denis Zalevskiy <denis.zalevskiy@jolla.com>
  • Loading branch information
Denis Zalevskiy committed May 26, 2015
1 parent a5d096c commit 76a398e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/vault/config.hpp
Expand Up @@ -47,6 +47,7 @@ class Unit
QString script() const;
inline QVariantMap data() const { return m_data; }

bool isLocal() const { return is(m_data.value("local", QVariant(false))); }
private:
QVariantMap m_data;
};
Expand Down
8 changes: 6 additions & 2 deletions src/vault.cpp
Expand Up @@ -180,8 +180,12 @@ int Vault::execute(const QVariantMap &options)
if (!options.contains("data")) {
error::raise({{"action", action}, {"msg", "Needs data"}});
}
qDebug()<<parseKvPairs(options.value("data").toString());
vault.registerConfig(parseKvPairs(options.value("data").toString()));
auto data = parseKvPairs(str(options["data"]));
if (options.contains("unit"))
data["unit"] = options["unit"];
data["local"] = true;
debug::info("Register local unit:", data);
vault.registerConfig(data);
} else if (action == "unregister") {
if (!options.contains("unit")) {
error::raise({{"action", action}, {"msg", "Needs unit name"}});
Expand Down
21 changes: 13 additions & 8 deletions src/vault_config.cpp
Expand Up @@ -225,19 +225,24 @@ bool Vault::update(const QMap<QString, Unit> &src)
bool Vault::update(const QVariantMap &src)
{
bool updated = false;
QStringList units = m_config.units().keys();
auto before = m_config.units();
for (auto i = src.begin(); i != src.end(); ++i) {
if (set(i.value().toMap())) {
updated = true;
}
}
for (const QString &n: units) {
if (!src.contains(n)) {
if (!rm(n)) {
error::raise({{"msg", n + " is not removed??"}});
}
updated = true;
}
// remove local copy of the global unit if there is no global
// counterpart
for (auto it = before.cbegin(); it != before.cend(); ++it) {
auto name = it.key();
if (it.value().isLocal() || src.contains(name))
continue;

debug::info("Global unit", name, "is not registered, removing");
if (!rm(name))
error::raise({{"msg", name + " is not removed??"}});

updated = true;
}
return updated;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/vault.cpp
Expand Up @@ -174,7 +174,7 @@ void object::test<tid_config_update>()

units = vlt->config().units();
ensure("no unit1 in vault config", units.contains("unit1"));
ensure("unit2 should be removed from vault config", !units.contains("unit2"));
ensure("local unit2 should not be removed", units.contains("unit2"));
on_exit();
}

Expand Down

0 comments on commit 76a398e

Please sign in to comment.