Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/sdb/sdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 4 additions & 7 deletions src/sdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
27 changes: 24 additions & 3 deletions test/syncget.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading