diff --git a/include/sdb/sdb.h b/include/sdb/sdb.h index 1d0fc7f..750637a 100644 --- a/include/sdb/sdb.h +++ b/include/sdb/sdb.h @@ -178,7 +178,6 @@ SDB_API char *sdb_querys(Sdb* s, char *buf, size_t len, const char *cmd); SDB_API char *sdb_querysf(Sdb* s, char *buf, size_t buflen, const char *fmt, ...); SDB_API int sdb_query_file(Sdb *s, const char* file); SDB_API bool sdb_exists(Sdb*, const char *key); -SDB_API bool sdb_remove(Sdb*, const char *key, ut32 cas); SDB_API int sdb_unset(Sdb*, const char *key, ut32 cas); SDB_API int sdb_nunset(Sdb*, ut64 nkey, ut32 cas); SDB_API int sdb_unset_like(Sdb *s, const char *k); diff --git a/src/sdb.c b/src/sdb.c index 2a134e7..7e82656 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -306,12 +306,9 @@ SDB_API int sdb_unset(Sdb* s, const char *key, ut32 cas) { } SDB_API int sdb_nunset(Sdb* s, ut64 nkey, ut32 cas) { - return sdb_nset (s, nkey, "", cas); -} - -/* remove from memory */ -SDB_API bool sdb_remove(Sdb *s, const char *key, ut32 cas) { - return sdb_ht_delete (s->ht, key); + char buf[SDB_NUM_BUFSZ]; + const char *key = sdb_itoa (nkey, 16, buf, sizeof (buf)); + return sdb_unset (s, key, cas); } // alias for '-key=str'.. '+key=str' concats @@ -905,7 +902,7 @@ SDB_API bool sdb_sync(Sdb* s) { const char *kvv = sdbkv_value (kv); if (kvv && *kvv && !kv->expire) { if (sdb_disk_insert (s, sdbkv_key (kv), sdbkv_value (kv))) { - sdb_remove (s, sdbkv_key (kv), 0); + sdb_ht_delete (s->ht, sdbkv_key (kv)); } } } diff --git a/test/syncget.c b/test/syncget.c index 2cc180e..1781074 100644 --- a/test/syncget.c +++ b/test/syncget.c @@ -14,10 +14,31 @@ int main() { v = sdb_const_get (s, "foo", NULL); if (v && !strcmp ("bar", v)) { eprintf ("OK syncget\n"); + } else { + eprintf ("ERROR syncget: Keys not accessible after sync\n"); sdb_free (s); - return 0; + unlink (DBFILE); + return 1; } - eprintf ("ERROR syncget: Keys not accessible after sync\n"); + sdb_unset (s, "foo", 0); + v = sdb_const_get (s, "foo", NULL); + if (v) { + eprintf ("ERROR syncget: Unset key still accessible before sync\n"); + sdb_free (s); + unlink (DBFILE); + return 1; + } + sdb_sync (s); sdb_free (s); - return 1; + s = sdb_new (".", DBFILE, 0); + v = sdb_const_get (s, "foo", NULL); + if (v) { + eprintf ("ERROR syncget: Unset key still accessible after reopen\n"); + sdb_free (s); + unlink (DBFILE); + return 1; + } + sdb_free (s); + unlink (DBFILE); + return 0; }