From 1eb1222c67ef59f797108d97575afeff40f2fdc8 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 4 Jul 2014 20:42:58 +0200 Subject: [PATCH] store: Don't overwrite attribute values if the new timestamp is too old. Also, extended the unit tests to catch this error. --- src/core/store.c | 2 +- t/unit/core/store_test.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/store.c b/src/core/store.c index 323ed77..7de75b1 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -324,7 +324,7 @@ store_attr(sdb_llist_t *attributes, const char *key, const sdb_data_t *value, int status; status = store_obj(attributes, SDB_ATTRIBUTE, key, last_update, &attr); - if (status < 0) + if (status) return status; assert(attr); diff --git a/t/unit/core/store_test.c b/t/unit/core/store_test.c index 6715a5b..1eb387e 100644 --- a/t/unit/core/store_test.c +++ b/t/unit/core/store_test.c @@ -44,9 +44,14 @@ populate(void) datum.data.string = "v1"; sdb_store_attribute("h1", "k1", &datum, 1); datum.data.string = "v2"; - sdb_store_attribute("h1", "k2", &datum, 1); + sdb_store_attribute("h1", "k2", &datum, 2); datum.data.string = "v3"; - sdb_store_attribute("h1", "k3", &datum, 1); + sdb_store_attribute("h1", "k3", &datum, 2); + + /* make sure that older updates don't overwrite existing values */ + datum.data.string = "fail"; + sdb_store_attribute("h1", "k2", &datum, 1); + sdb_store_attribute("h1", "k3", &datum, 2); sdb_store_service("h2", "s1", 1); sdb_store_service("h2", "s2", 1); -- 2.30.2