summaryrefslogtreecommitdiffstats
path: root/src/dbutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbutil.c')
-rw-r--r--src/dbutil.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/dbutil.c b/src/dbutil.c
index 535b665..d7aa319 100644
--- a/src/dbutil.c
+++ b/src/dbutil.c
@@ -198,10 +198,11 @@ int get_name_by_nrecno(struct syrep_db_context *c, const struct syrep_nrecno *nr
key.data = (void*) &nrecno->recno;
key.size = sizeof(nrecno->recno);
-
+
if ((ret = c->db_nrecno_name->get(c->db_nrecno_name, NULL, &key, &data, 0))) {
- if (ret == DB_NOTFOUND)
+ if (ret == DB_NOTFOUND) {
return 0;
+ }
c->db_nrecno_name->err(c->db_nrecno_name, ret, "nrecno_name::get");
return -1;
@@ -216,13 +217,15 @@ int get_name_by_nrecno(struct syrep_db_context *c, const struct syrep_nrecno *nr
}
static uint32_t csum_name(const struct syrep_name *name) {
- uint32_t a;
+ uint32_t a = 0;
assert(name);
- a = adler32(0, NULL, 0);
- a = adler32(a, name->path, strlen(name->path));
-
+ a = adler32(0, NULL, 0);
+ a = adler32(a, name->path, strlen(name->path));
+
+ /*fprintf(stderr, "csum: %s -> %u\n", name->path, a);*/
+
return a;
}
@@ -251,9 +254,12 @@ int get_nrecno_by_name(struct syrep_db_context *c, const struct syrep_name *rnam
for(;;) {
struct syrep_nrecno nrecno;
struct syrep_name name;
+
+/* struct syrep_nhash *foo1; */
+/* struct syrep_nrecno *foo2; */
int f;
-
- if (ret != 0) {
+
+ if (ret) {
if (ret == DB_NOTFOUND) {
r = 0;
@@ -264,6 +270,17 @@ int get_nrecno_by_name(struct syrep_db_context *c, const struct syrep_name *rnam
goto finish;
}
+
+ if (memcmp(key.data, &nhash, sizeof(struct syrep_nhash))) {
+ r = 0;
+ goto finish;
+ }
+
+/* foo1 = key.data; */
+/* foo2 = data.data; */
+
+/* fprintf(stderr, "cursor: %u ?= %u, %u\n", nhash.hash, foo1->hash, foo2->recno); */
+
memcpy(&nrecno, data.data, sizeof(nrecno));
if ((f = get_name_by_nrecno(c, &nrecno, &name)) < 0)
@@ -285,8 +302,9 @@ finish:
if (cursor)
cursor->c_close(cursor);
- if (!r && create)
+ if (!r && create) {
r = new_name(c, rname, rnrecno) < 0 ? -1 : 1;
+ }
return r;
}
@@ -309,7 +327,7 @@ int new_name(struct syrep_db_context *c, const struct syrep_name *name, struct s
return -1;
}
- nrecno.recno = *((db_recno_t*) data.data);
+ nrecno.recno = *((db_recno_t*) key.data);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
@@ -320,8 +338,8 @@ int new_name(struct syrep_db_context *c, const struct syrep_name *name, struct s
data.data = &nrecno;
data.size = sizeof(nrecno);
-
- if ((ret = c->db_nhash_nrecno->put(c->db_nhash_nrecno, NULL, &key, &data, 0))) {
+
+ if ((ret = c->db_nhash_nrecno->put(c->db_nhash_nrecno, NULL, &key, &data, DB_NODUPDATA))) {
c->db_nhash_nrecno->err(c->db_nhash_nrecno, ret, "nhash_nrecno::put");
return -1;
}