summaryrefslogtreecommitdiffstats
path: root/src/update.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/update.c')
-rw-r--r--src/update.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/update.c b/src/update.c
index 0c65d4c..06986f9 100644
--- a/src/update.c
+++ b/src/update.c
@@ -57,32 +57,38 @@ static int dbput(DB* db, const void *k, int klen, const void*d, int dlen, int f)
static int write_entry(struct syrep_db_context *c, const struct syrep_name *name, const struct syrep_md *md, const struct syrep_meta *meta) {
struct syrep_id id;
+ struct syrep_nrecno nrecno;
int f;
- assert(c && c->db_id_meta && c->db_md_name && c->db_name_md && c->db_md_lastname && c->db_name_lastmd && name && md && meta);
+ assert(c && c->db_id_meta && c->db_md_nrecno && c->db_nrecno_md && c->db_md_lastnrecno && c->db_nrecno_lastmd && name && md && meta);
+ if ((f = get_nrecno_by_name(c, name, &nrecno, 1)) < 0)
+ return -1;
+
+ assert(f);
+
/*** Update id_meta ***/
memset(&id, 0, sizeof(id));
- memcpy(&id.name, name, sizeof(struct syrep_name));
+ memcpy(&id.nrecno, &nrecno, sizeof(struct syrep_nrecno));
memcpy(&id.md, md, sizeof(struct syrep_md));
if (dbput(c->db_id_meta, &id, sizeof(struct syrep_id), meta, sizeof(struct syrep_meta), 0) < 0)
return -1;
- /*** Update md_name ***/
- if (dbput(c->db_md_name, md, sizeof(struct syrep_md), name, sizeof(struct syrep_name), DB_NODUPDATA) < 0)
+ /*** Update md_nrecno ***/
+ if (dbput(c->db_md_nrecno, md, sizeof(struct syrep_md), &nrecno, sizeof(struct syrep_nrecno), DB_NODUPDATA) < 0)
return -1;
- /*** Update name_md ***/
- if (dbput(c->db_name_md, name, sizeof(struct syrep_name), md, sizeof(struct syrep_md), DB_NODUPDATA) < 0)
+ /*** Update nrecno_md ***/
+ if (dbput(c->db_nrecno_md, &nrecno, sizeof(struct syrep_nrecno), md, sizeof(struct syrep_md), DB_NODUPDATA) < 0)
return -1;
- /*** Update md_lastname ***/
- if (dbput(c->db_md_lastname, md, sizeof(struct syrep_md), name, sizeof(struct syrep_name), 0) < 0)
+ /*** Update md_lastnrecno ***/
+ if (dbput(c->db_md_lastnrecno, md, sizeof(struct syrep_md), &nrecno, sizeof(struct syrep_nrecno), 0) < 0)
return -1;
- /*** Update name_lastmd ***/
- if ((f = dbput(c->db_name_lastmd, name, sizeof(struct syrep_name), md, sizeof(struct syrep_md), 0)) < 0)
+ /*** Update nrecno_lastmd ***/
+ if ((f = dbput(c->db_nrecno_lastmd, &nrecno, sizeof(struct syrep_nrecno), md, sizeof(struct syrep_md), 0)) < 0)
return -1;
//fprintf(stderr, "Insert: %s %i\n", name->path, f);
@@ -95,15 +101,22 @@ static int handle_file(struct syrep_db_context *c, uint32_t version, const char
int r;
struct syrep_meta meta;
struct syrep_name name;
+ struct syrep_nrecno nrecno;
memset(&name, 0, sizeof(name));
strncpy(name.path, path, PATH_MAX);
- memset(&meta, 0, sizeof(meta));
-
- if ((r = get_meta_by_name_md(c, &name, md, &meta)) < 0)
+ if ((r = get_nrecno_by_name(c, &name, &nrecno, 0)) < 0)
return -1;
+ if (r) {
+
+ memset(&meta, 0, sizeof(meta));
+
+ if ((r = get_meta_by_nrecno_md(c, &nrecno, md, &meta)) < 0)
+ return -1;
+ }
+
if (r) { /* File is alread known */
if (meta.last_seen != c->version) { /* File was deleted preiously */