From: Sebastian Harl Date: Fri, 4 Jul 2014 18:42:58 +0000 (+0200) Subject: store: Don't overwrite attribute values if the new timestamp is too old. X-Git-Tag: sysdb-0.3.0~86 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1eb1222c67ef59f797108d97575afeff40f2fdc8;p=sysdb.git store: Don't overwrite attribute values if the new timestamp is too old. Also, extended the unit tests to catch this error. --- 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);