++ hash_name = get_pool_memory(PM_MESSAGE);
++ make_unique_filename(&hash_name, jcr->JobId, "accurate");
++
++ if ((ret = db->open(db,
++ NULL, hash_name, NULL,
++ DB_BTREE, DB_CREATE, 0600)) != 0)
+ {
+- /* TODO: don't malloc/free results */
+- found = true;
+- elt->fname = fname;
+- memcpy(ret, elt, sizeof(CurFile));
+- realfree(elt);
+-// Dmsg1(dbglvl, "lookup <%s> ok\n", fname);
++ destroy();
++ Jmsg(jcr, M_ERROR, 1, _("Can't setup hash disk ERR=%i\n"), ret);
++ return false;
+ }
+- return found;
++
++ first_pass=0;
++
++ return true;
+ }
+
+-/* Create tokyo dbm hash file
+- * If something goes wrong, we cancel accurate mode.
+- */
+-static bool accurate_init(JCR *jcr, int nbfile)
++/* Just update the element->seen to know if we have seen it */
++bool AccurateBackendDB::mark_as_seen(JCR *jcr, char *key, CurFile *item)
+ {
+- jcr->file_list = tcadbnew();
+-//
+-// tchdbsetcache(jcr->file_list, 300000);
+-// tchdbtune(jcr->file_list,
+-// nbfile, /* nb bucket 0.5n to 4n */
+-// 6, /* size of element 2^x */
+-// 16,
+-// 0); /* options like compression */
+-//
+- jcr->hash_name = get_pool_memory(PM_MESSAGE);
+- POOLMEM *temp = get_pool_memory(PM_MESSAGE);
++ item->seen = 1;
++ return insert(jcr, key, item);
++}
+
+- if (nbfile > 500000) {
+- make_unique_filename(&jcr->hash_name, jcr->JobId, "accurate");
+- pm_strcat(jcr->hash_name, ".tcb");
+- Mmsg(temp, "%s#bnum=%i#mode=e#opts=l",
+- jcr->hash_name, nbfile*4);
+- Dmsg1(dbglvl, "Doing accurate hash on disk %s\n", jcr->hash_name);
+- } else {
+- Dmsg0(dbglvl, "Doing accurate hash on memory\n");
+- pm_strcpy(jcr->hash_name, "*");
+- pm_strcpy(temp, "*");
++/* insert/replace */
++bool AccurateBackendDB::insert(JCR *jcr, char *key, CurFile *item)
++{
++ int ret;
++ memset(&dbkey, 0, sizeof(DBT));
++ memset(&dbdata, 0, sizeof(DBT));
++ dbkey.data = key;
++ dbkey.size = strlen(key)+1;
++ dbdata.data = item;