summaryrefslogtreecommitdiffstats
path: root/src/context.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/context.c')
-rw-r--r--src/context.c78
1 files changed, 49 insertions, 29 deletions
diff --git a/src/context.c b/src/context.c
index 7052bad..1249669 100644
--- a/src/context.c
+++ b/src/context.c
@@ -37,21 +37,27 @@ int db_context_free(struct syrep_db_context* c) {
if (c->db_id_meta)
c->db_id_meta->close(c->db_id_meta, 0);
- if (c->db_md_name)
- c->db_md_name->close(c->db_md_name, 0);
+ if (c->db_md_nrecno)
+ c->db_md_nrecno->close(c->db_md_nrecno, 0);
- if (c->db_name_md)
- c->db_name_md->close(c->db_name_md, 0);
+ if (c->db_nrecno_md)
+ c->db_nrecno_md->close(c->db_nrecno_md, 0);
- if (c->db_md_lastname)
- c->db_md_lastname->close(c->db_md_lastname, 0);
+ if (c->db_md_lastnrecno)
+ c->db_md_lastnrecno->close(c->db_md_lastnrecno, 0);
- if (c->db_name_lastmd)
- c->db_name_lastmd->close(c->db_name_lastmd, 0);
+ if (c->db_nrecno_lastmd)
+ c->db_nrecno_lastmd->close(c->db_nrecno_lastmd, 0);
if (c->db_version_timestamp)
c->db_version_timestamp->close(c->db_version_timestamp, 0);
+ if (c->db_nhash_nrecno)
+ c->db_nhash_nrecno->close(c->db_nhash_nrecno, 0);
+
+ if (c->db_nrecno_name)
+ c->db_nrecno_name->close(c->db_nrecno_name, 0);
+
if (c->package)
package_remove(c->package);
@@ -65,7 +71,7 @@ int db_context_free(struct syrep_db_context* c) {
}
-static DB* open_db(const char*path, int dup) {
+static DB* open_db(const char*path, int dup, int recno) {
int ret;
DB* db;
@@ -79,7 +85,7 @@ static DB* open_db(const char*path, int dup) {
//db->set_pagesize(db, 4096*8);
- if ((ret = db->open(db, NULL, path, NULL, DB_BTREE, DB_CREATE, 0664))) {
+ if ((ret = db->open(db, NULL, path, NULL, recno ? DB_RECNO : DB_BTREE, DB_CREATE, 0664))) {
db->err(db, ret, "open(%s)", path);
db->close(db, 0);
return NULL;
@@ -144,29 +150,37 @@ struct syrep_db_context* db_context_open(const char *filename, int force) {
}
/* Creating database id_meta */
- if (!(c->db_id_meta = open_db(package_get_item(c->package, "id_meta", 1), 0)))
+ if (!(c->db_id_meta = open_db(package_get_item(c->package, "id_meta", 1), 0, 0)))
goto fail;
- /* Creating database md_name */
- if (!(c->db_md_name = open_db(package_get_item(c->package, "md_name", 1), 1)))
+ /* Creating database md_nrecno */
+ if (!(c->db_md_nrecno = open_db(package_get_item(c->package, "md_nrecno", 1), 1, 0)))
goto fail;
- /* Creating database name_md */
- if (!(c->db_name_md = open_db(package_get_item(c->package, "name_md", 1), 1)))
+ /* Creating database nrecno_md */
+ if (!(c->db_nrecno_md = open_db(package_get_item(c->package, "nrecno_md", 1), 1, 0)))
goto fail;
- /* Creating database name_lastmd */
- if (!(c->db_name_lastmd = open_db(package_get_item(c->package, "name_lastmd", 1), 0)))
+ /* Creating database nrecno_lastmd */
+ if (!(c->db_nrecno_lastmd = open_db(package_get_item(c->package, "nrecno_lastmd", 1), 0, 0)))
goto fail;
- /* Creating database md_lastname */
- if (!(c->db_md_lastname = open_db(package_get_item(c->package, "md_lastname", 1), 0)))
+ /* Creating database md_lastnrecno */
+ if (!(c->db_md_lastnrecno = open_db(package_get_item(c->package, "md_lastnrecno", 1), 0, 0)))
goto fail;
/* Creating database version_timestamp */
- if (!(c->db_version_timestamp = open_db(package_get_item(c->package, "version_timestamp", 1), 0)))
+ if (!(c->db_version_timestamp = open_db(package_get_item(c->package, "version_timestamp", 1), 0, 0)))
goto fail;
+ /* Creating database nhash_nrecno */
+ if (!(c->db_nhash_nrecno = open_db(package_get_item(c->package, "nhash_nrecno", 1), 1, 0)))
+ goto fail;
+
+ /* Creating database nrecno_name */
+ if (!(c->db_nrecno_name = open_db(package_get_item(c->package, "nrecno_name", 1), 0, 1)))
+ goto fail;
+
return c;
@@ -183,21 +197,27 @@ int db_context_save(struct syrep_db_context *c, const char *filename) {
if (c->db_id_meta)
c->db_id_meta->sync(c->db_id_meta, 0);
- if (c->db_md_name)
- c->db_md_name->sync(c->db_md_name, 0);
+ if (c->db_md_nrecno)
+ c->db_md_nrecno->sync(c->db_md_nrecno, 0);
- if (c->db_name_md)
- c->db_name_md->sync(c->db_name_md, 0);
+ if (c->db_nrecno_md)
+ c->db_nrecno_md->sync(c->db_nrecno_md, 0);
- if (c->db_md_lastname)
- c->db_md_lastname->sync(c->db_md_lastname, 0);
+ if (c->db_md_lastnrecno)
+ c->db_md_lastnrecno->sync(c->db_md_lastnrecno, 0);
- if (c->db_name_lastmd)
- c->db_name_lastmd->sync(c->db_name_lastmd, 0);
+ if (c->db_nrecno_lastmd)
+ c->db_nrecno_lastmd->sync(c->db_nrecno_lastmd, 0);
if (c->db_version_timestamp)
c->db_version_timestamp->sync(c->db_version_timestamp, 0);
-
+
+ if (c->db_nhash_nrecno)
+ c->db_nhash_nrecno->sync(c->db_nhash_nrecno, 0);
+
+ if (c->db_nrecno_name)
+ c->db_nrecno_name->sync(c->db_nrecno_name, 0);
+
if (!(f = fopen(package_get_item(c->package, "timestamp", 1), "w+")))
return -1;