diff options
author | José Bollo <jose.bollo@iot.bzh> | 2019-10-04 13:41:00 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2019-10-04 13:43:10 +0200 |
commit | bf0edaecd3cbf088992ba4bae20d761cceeb1742 (patch) | |
tree | 6d9fbb8102f7215f62b5c5e872713974a0251bb3 | |
parent | f161cd8b8b83a29f42c275fe31a96825a8d27d86 (diff) |
anydb: Fix error in anydb_is_empty
Compute correctly if a database is empty or not.
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | src/anydb.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/anydb.c b/src/anydb.c index 9196e5c..88591a9 100644 --- a/src/anydb.c +++ b/src/anydb.c @@ -586,6 +586,13 @@ anydb_test( /******************************************************************************/ /******************************************************************************/ +/* structure for testing emptyness */ +struct empty_s +{ + bool empty; + time_t now; +}; + /* callback for computing if empty */ static anydb_action_t @@ -594,10 +601,12 @@ is_empty_cb( const anydb_key_t *key, anydb_value_t *value ) { - time_t *t = closure; - if (value->expire && value->expire <= *t) + struct empty_s *s = closure; + + if (value->expire && value->expire <= s->now) return Anydb_Action_Remove_And_Continue; - *t = 0; + + s->empty = false; return Anydb_Action_Stop; } @@ -606,11 +615,12 @@ bool anydb_is_empty( anydb_t *db ) { - time_t t; + struct empty_s s; - t = time(NULL); - db->itf.apply(db->clodb, is_empty_cb, &t); - return !t; + s.empty = true; + s.now = time(NULL); + db->itf.apply(db->clodb, is_empty_cb, &s); + return s.empty; } /******************************************************************************/ |